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    
043    import static org.opends.server.loggers.ErrorLogger.*;
044    import static org.opends.messages.SchemaMessages.*;
045    import org.opends.messages.MessageBuilder;
046    import static org.opends.server.schema.SchemaConstants.*;
047    
048    
049    /**
050     * This class implements the certificate attribute syntax.  This should be
051     * restricted to holding only X.509 certificates, but we will accept any set of
052     * bytes.  It will be treated much like the octet string attribute syntax.
053     */
054    public class CertificateSyntax
055           extends AttributeSyntax<AttributeSyntaxCfg>
056    {
057      // The default equality matching rule for this syntax.
058      private EqualityMatchingRule defaultEqualityMatchingRule;
059    
060      // The default ordering matching rule for this syntax.
061      private OrderingMatchingRule defaultOrderingMatchingRule;
062    
063      // The default substring matching rule for this syntax.
064      private SubstringMatchingRule defaultSubstringMatchingRule;
065    
066    
067    
068      /**
069       * Creates a new instance of this syntax.  Note that the only thing that
070       * should be done here is to invoke the default constructor for the
071       * superclass.  All initialization should be performed in the
072       * <CODE>initializeSyntax</CODE> method.
073       */
074      public CertificateSyntax()
075      {
076        super();
077      }
078    
079    
080    
081      /**
082       * {@inheritDoc}
083       */
084      public void initializeSyntax(AttributeSyntaxCfg configuration)
085             throws ConfigException
086      {
087        defaultEqualityMatchingRule =
088             DirectoryServer.getEqualityMatchingRule(EMR_OCTET_STRING_OID);
089        if (defaultEqualityMatchingRule == null)
090        {
091          logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
092              EMR_OCTET_STRING_OID, SYNTAX_CERTIFICATE_NAME));
093        }
094    
095        defaultOrderingMatchingRule =
096             DirectoryServer.getOrderingMatchingRule(OMR_OCTET_STRING_OID);
097        if (defaultOrderingMatchingRule == null)
098        {
099          logError(ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get(
100              OMR_OCTET_STRING_OID, SYNTAX_CERTIFICATE_NAME));
101        }
102    
103        defaultSubstringMatchingRule =
104             DirectoryServer.getSubstringMatchingRule(SMR_OCTET_STRING_OID);
105        if (defaultSubstringMatchingRule == null)
106        {
107          logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
108              SMR_OCTET_STRING_OID, SYNTAX_CERTIFICATE_NAME));
109        }
110      }
111    
112    
113    
114      /**
115       * Retrieves the common name for this attribute syntax.
116       *
117       * @return  The common name for this attribute syntax.
118       */
119      public String getSyntaxName()
120      {
121        return SYNTAX_CERTIFICATE_NAME;
122      }
123    
124    
125    
126      /**
127       * Retrieves the OID for this attribute syntax.
128       *
129       * @return  The OID for this attribute syntax.
130       */
131      public String getOID()
132      {
133        return SYNTAX_CERTIFICATE_OID;
134      }
135    
136    
137    
138      /**
139       * Retrieves a description for this attribute syntax.
140       *
141       * @return  A description for this attribute syntax.
142       */
143      public String getDescription()
144      {
145        return SYNTAX_CERTIFICATE_DESCRIPTION;
146      }
147    
148    
149    
150      /**
151       * Retrieves the default equality matching rule that will be used for
152       * attributes with this syntax.
153       *
154       * @return  The default equality matching rule that will be used for
155       *          attributes with this syntax, or <CODE>null</CODE> if equality
156       *          matches will not be allowed for this type by default.
157       */
158      public EqualityMatchingRule getEqualityMatchingRule()
159      {
160        return defaultEqualityMatchingRule;
161      }
162    
163    
164    
165      /**
166       * Retrieves the default ordering matching rule that will be used for
167       * attributes with this syntax.
168       *
169       * @return  The default ordering matching rule that will be used for
170       *          attributes with this syntax, or <CODE>null</CODE> if ordering
171       *          matches will not be allowed for this type by default.
172       */
173      public OrderingMatchingRule getOrderingMatchingRule()
174      {
175        return defaultOrderingMatchingRule;
176      }
177    
178    
179    
180      /**
181       * Retrieves the default substring matching rule that will be used for
182       * attributes with this syntax.
183       *
184       * @return  The default substring matching rule that will be used for
185       *          attributes with this syntax, or <CODE>null</CODE> if substring
186       *          matches will not be allowed for this type by default.
187       */
188      public SubstringMatchingRule getSubstringMatchingRule()
189      {
190        return defaultSubstringMatchingRule;
191      }
192    
193    
194    
195      /**
196       * Retrieves the default approximate matching rule that will be used for
197       * attributes with this syntax.
198       *
199       * @return  The default approximate matching rule that will be used for
200       *          attributes with this syntax, or <CODE>null</CODE> if approximate
201       *          matches will not be allowed for this type by default.
202       */
203      public ApproximateMatchingRule getApproximateMatchingRule()
204      {
205        // There is no approximate matching rule by default.
206        return null;
207      }
208    
209    
210    
211      /**
212       * Indicates whether the provided value is acceptable for use in an attribute
213       * with this syntax.  If it is not, then the reason may be appended to the
214       * provided buffer.
215       *
216       * @param  value          The value for which to make the determination.
217       * @param  invalidReason  The buffer to which the invalid reason should be
218       *                        appended.
219       *
220       * @return  <CODE>true</CODE> if the provided value is acceptable for use with
221       *          this syntax, or <CODE>false</CODE> if not.
222       */
223      public boolean valueIsAcceptable(ByteString value,
224                                       MessageBuilder invalidReason)
225      {
226        // All values will be acceptable for the certificate syntax.
227        return true;
228      }
229    }
230