001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.schema;
028    
029    
030    
031    import org.opends.server.admin.std.server.AttributeSyntaxCfg;
032    import org.opends.server.api.ApproximateMatchingRule;
033    import org.opends.server.api.AttributeSyntax;
034    import org.opends.server.api.EqualityMatchingRule;
035    import org.opends.server.api.OrderingMatchingRule;
036    import org.opends.server.api.SubstringMatchingRule;
037    import org.opends.server.config.ConfigException;
038    import org.opends.server.core.DirectoryServer;
039    import org.opends.server.types.ByteString;
040    
041    
042    import org.opends.server.types.DN;
043    import org.opends.server.types.DebugLogLevel;
044    
045    import static org.opends.server.loggers.ErrorLogger.*;
046    import static org.opends.server.loggers.debug.DebugLogger.*;
047    import org.opends.server.loggers.debug.DebugTracer;
048    import static org.opends.messages.SchemaMessages.*;
049    import org.opends.messages.MessageBuilder;
050    import static org.opends.server.schema.SchemaConstants.*;
051    import org.opends.server.authorization.dseecompat.Aci;
052    import org.opends.server.authorization.dseecompat.AciException;
053    
054    
055    /**
056     * This class implements the access control information (aci) attribute syntax.
057     */
058    public class AciSyntax
059           extends AttributeSyntax<AttributeSyntaxCfg>
060    {
061      /**
062       * The tracer object for the debug logger.
063       */
064      private static final DebugTracer TRACER = getTracer();
065    
066    
067    
068    
069      // The default approximate matching rule for this syntax.
070      private ApproximateMatchingRule defaultApproximateMatchingRule;
071    
072      // The default equality matching rule for this syntax.
073      private EqualityMatchingRule defaultEqualityMatchingRule;
074    
075      // The default ordering matching rule for this syntax.
076      private OrderingMatchingRule defaultOrderingMatchingRule;
077    
078      // The default substring matching rule for this syntax.
079      private SubstringMatchingRule defaultSubstringMatchingRule;
080    
081    
082    
083      /**
084       * Creates a new instance of this syntax.  Note that the only thing that
085       * should be done here is to invoke the default constructor for the
086       * superclass.  All initialization should be performed in the
087       * <CODE>initializeSyntax</CODE> method.
088       */
089      public AciSyntax()
090      {
091        super();
092      }
093    
094    
095    
096      /**
097       * {@inheritDoc}
098       */
099      public void initializeSyntax(AttributeSyntaxCfg configuration)
100             throws ConfigException
101      {
102        // We don't need an approximate matching rule.
103        defaultApproximateMatchingRule = null;
104    
105        defaultEqualityMatchingRule =
106             DirectoryServer.getEqualityMatchingRule(EMR_CASE_IGNORE_IA5_OID);
107        if (defaultEqualityMatchingRule == null)
108        {
109          logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
110              EMR_CASE_IGNORE_IA5_OID, SYNTAX_ACI_NAME));
111        }
112    
113        // We don't need an ordering matching rule.
114        defaultOrderingMatchingRule = null;
115    
116        defaultSubstringMatchingRule =
117             DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_IA5_OID);
118        if (defaultSubstringMatchingRule == null)
119        {
120          logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
121              SMR_CASE_IGNORE_IA5_OID, SYNTAX_ACI_NAME));
122        }
123      }
124    
125    
126    
127      /**
128       * Retrieves the common name for this attribute syntax.
129       *
130       * @return  The common name for this attribute syntax.
131       */
132      public String getSyntaxName()
133      {
134        return SYNTAX_ACI_NAME;
135      }
136    
137    
138    
139      /**
140       * Retrieves the OID for this attribute syntax.
141       *
142       * @return  The OID for this attribute syntax.
143       */
144      public String getOID()
145      {
146        return SYNTAX_ACI_OID;
147      }
148    
149    
150    
151      /**
152       * Retrieves a description for this attribute syntax.
153       *
154       * @return  A description for this attribute syntax.
155       */
156      public String getDescription()
157      {
158        return SYNTAX_ACI_DESCRIPTION;
159      }
160    
161    
162    
163      /**
164       * Retrieves the default equality matching rule that will be used for
165       * attributes with this syntax.
166       *
167       * @return  The default equality matching rule that will be used for
168       *          attributes with this syntax, or <CODE>null</CODE> if equality
169       *          matches will not be allowed for this type by default.
170       */
171      public EqualityMatchingRule getEqualityMatchingRule()
172      {
173        return defaultEqualityMatchingRule;
174      }
175    
176    
177    
178      /**
179       * Retrieves the default ordering matching rule that will be used for
180       * attributes with this syntax.
181       *
182       * @return  The default ordering matching rule that will be used for
183       *          attributes with this syntax, or <CODE>null</CODE> if ordering
184       *          matches will not be allowed for this type by default.
185       */
186      public OrderingMatchingRule getOrderingMatchingRule()
187      {
188        return defaultOrderingMatchingRule;
189      }
190    
191    
192    
193      /**
194       * Retrieves the default substring matching rule that will be used for
195       * attributes with this syntax.
196       *
197       * @return  The default substring matching rule that will be used for
198       *          attributes with this syntax, or <CODE>null</CODE> if substring
199       *          matches will not be allowed for this type by default.
200       */
201      public SubstringMatchingRule getSubstringMatchingRule()
202      {
203        return defaultSubstringMatchingRule;
204      }
205    
206    
207    
208      /**
209       * Retrieves the default approximate matching rule that will be used for
210       * attributes with this syntax.
211       *
212       * @return  The default approximate matching rule that will be used for
213       *          attributes with this syntax, or <CODE>null</CODE> if approximate
214       *          matches will not be allowed for this type by default.
215       */
216      public ApproximateMatchingRule getApproximateMatchingRule()
217      {
218        return defaultApproximateMatchingRule;
219      }
220    
221    
222    
223      /**
224       * Indicates whether the provided value is acceptable for use in an attribute
225       * with this syntax.  If it is not, then the reason may be appended to the
226       * provided buffer.
227       *
228       * @param  value          The value for which to make the determination.
229       * @param  invalidReason  The buffer to which the invalid reason should be
230       *                        appended.
231       *
232       * @return  <CODE>true</CODE> if the provided value is acceptable for use with
233       *          this syntax, or <CODE>false</CODE> if not.
234       */
235      public boolean valueIsAcceptable(ByteString value,
236                                       MessageBuilder invalidReason)
237      {
238        try
239        {
240          Aci.decode(value, DN.nullDN());
241        }
242        catch (AciException e)
243        {
244          if (debugEnabled())
245          {
246            TRACER.debugCaught(DebugLogLevel.ERROR, e);
247          }
248    
249          logError(e.getMessageObject());
250          invalidReason.append(e.getMessageObject());
251          return false;
252        }
253        return true;
254      }
255    }
256