001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2016 ForgeRock AS. 016 */ 017 018package org.opends.server.admin; 019 020import org.opends.server.authorization.dseecompat.Aci; 021import org.opends.server.authorization.dseecompat.AciException; 022import org.forgerock.opendj.ldap.DN; 023import org.forgerock.opendj.ldap.ByteString; 024import static org.forgerock.util.Reject.ifNull; 025 026import java.util.EnumSet; 027 028/** 029 * ACI property definition. 030 */ 031public class ACIPropertyDefinition extends PropertyDefinition<Aci> { 032 033 034 /** 035 * An interface for incrementally constructing ACI property 036 * definitions. 037 */ 038 public static class Builder extends 039 AbstractBuilder<Aci, ACIPropertyDefinition> { 040 041 /** Private constructor. */ 042 private Builder( 043 AbstractManagedObjectDefinition<?, ?> d, String propertyName) { 044 super(d, propertyName); 045 } 046 047 /** {@inheritDoc} */ 048 @Override 049 protected ACIPropertyDefinition buildInstance( 050 AbstractManagedObjectDefinition<?, ?> d, 051 String propertyName, EnumSet<PropertyOption> options, 052 AdministratorAction adminAction, 053 DefaultBehaviorProvider<Aci> defaultBehavior) { 054 return new ACIPropertyDefinition(d, propertyName, options, 055 adminAction, defaultBehavior); 056 } 057 } 058 059 060 /** 061 * Create a ACI property definition builder. 062 * 063 * @param d 064 * The managed object definition associated with this 065 * property definition. 066 * @param propertyName 067 * The property name. 068 * @return Returns the new ACI property definition builder. 069 */ 070 public static Builder createBuilder( 071 AbstractManagedObjectDefinition<?, ?> d, String propertyName) { 072 return new Builder(d, propertyName); 073 } 074 075 076 /** Private constructor. */ 077 private ACIPropertyDefinition( 078 AbstractManagedObjectDefinition<?, ?> d, String propertyName, 079 EnumSet<PropertyOption> options, 080 AdministratorAction adminAction, 081 DefaultBehaviorProvider<Aci> defaultBehavior) { 082 super(d, Aci.class, propertyName, options, adminAction, 083 defaultBehavior); 084 } 085 086 087 /** {@inheritDoc} */ 088 @Override 089 public void validateValue(Aci value) 090 throws PropertyException { 091 ifNull(value); 092 093 // No additional validation required. 094 } 095 096 /** {@inheritDoc} */ 097 @Override 098 public Aci decodeValue(String value) 099 throws PropertyException { 100 ifNull(value); 101 102 try { 103 return Aci.decode(ByteString.valueOfUtf8(value), DN.rootDN()); 104 } catch (AciException e) { 105 // TODO: it would be nice to throw the cause. 106 throw PropertyException.illegalPropertyValueException(this, value); 107 } 108 } 109 110 111 /** {@inheritDoc} */ 112 @Override 113 public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) { 114 return v.visitACI(this, p); 115 } 116 117 /** {@inheritDoc} */ 118 @Override 119 public <R, P> R accept(PropertyValueVisitor<R, P> v, Aci value, P p) { 120 return v.visitACI(this, value, p); 121 } 122 123 124 /** {@inheritDoc} */ 125 @Override 126 public int compare(Aci o1, Aci o2) { 127 return o1.toString().compareTo(o2.toString()); 128 } 129}