View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.core.partition;
21  
22  
23  import java.util.HashMap;
24  import java.util.Iterator;
25  import java.util.Map;
26  import java.util.Set;
27  
28  import javax.naming.InvalidNameException;
29  import javax.naming.ldap.LdapContext;
30  
31  import org.apache.directory.server.constants.ServerDNConstants;
32  import org.apache.directory.server.core.entry.ClonedServerEntry;
33  import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext;
34  import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
35  import org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext;
36  import org.apache.directory.server.core.interceptor.context.GetRootDSEOperationContext;
37  import org.apache.directory.server.core.interceptor.context.GetSuffixOperationContext;
38  import org.apache.directory.server.core.interceptor.context.ListSuffixOperationContext;
39  import org.apache.directory.server.core.interceptor.context.RemoveContextPartitionOperationContext;
40  import org.apache.directory.shared.ldap.constants.SchemaConstants;
41  import org.apache.directory.shared.ldap.name.LdapDN;
42  import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
43  import org.apache.directory.shared.ldap.schema.OidNormalizer;
44  import org.apache.directory.shared.ldap.util.StringTools;
45  
46  
47  /**
48   * A root {@link Partition} that contains all other partitions, and
49   * routes all operations to the child partition that matches to its base suffixes.
50   * It also provides some extended operations such as accessing rootDSE and
51   * listing base suffixes.
52   *
53   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
54   * @version $Rev: 664295 $, $Date: 2008-06-07 09:48:16 +0200 (Sa, 07 Jun 2008) $
55   */
56  public abstract class PartitionNexus implements Partition
57  {
58      /** the admin super user uid */
59      public static final String ADMIN_UID = "admin";
60      
61      /** the initial admin passwd set on startup */
62      public static final String ADMIN_PASSWORD_STRING = "secret";
63      public static final byte[] ADMIN_PASSWORD_BYTES = StringTools.getBytesUtf8( ADMIN_PASSWORD_STRING );
64      
65     
66      /**
67       * Gets the DN for the admin user.
68       * 
69       * @return the admin user DN
70       */
71      public static final LdapDN getAdminName()
72      {
73          LdapDN adminDn = null;
74  
75          try
76          {
77              adminDn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN );
78          }
79          catch ( Exception e )
80          {
81              throw new InternalError();
82          }
83          
84          try
85          {
86              Map<String, OidNormalizer> oidsMap = new HashMap<String, OidNormalizer>();
87              
88              oidsMap.put( SchemaConstants.UID_AT, new OidNormalizer( SchemaConstants.UID_AT_OID, new NoOpNormalizer() ) );
89              oidsMap.put( SchemaConstants.USER_ID_AT, new OidNormalizer( SchemaConstants.UID_AT_OID, new NoOpNormalizer() ) );
90              oidsMap.put( SchemaConstants.UID_AT_OID, new OidNormalizer( SchemaConstants.UID_AT_OID, new NoOpNormalizer() ) );
91              
92              oidsMap.put( SchemaConstants.OU_AT, new OidNormalizer( SchemaConstants.OU_AT_OID, new NoOpNormalizer()  ) );
93              oidsMap.put( SchemaConstants.ORGANIZATIONAL_UNIT_NAME_AT, new OidNormalizer( SchemaConstants.OU_AT_OID, new NoOpNormalizer()  ) );
94              oidsMap.put( SchemaConstants.OU_AT_OID, new OidNormalizer( SchemaConstants.OU_AT_OID, new NoOpNormalizer()  ) );
95  
96              adminDn.normalize( oidsMap );
97          }
98          catch ( InvalidNameException ine )
99          {
100             // Nothing we can do ...
101         }
102         catch ( Exception ne )
103         {
104             // Nothing we can do ...
105         }
106 
107         return adminDn;
108     }
109 
110 
111     /**
112      * Gets the DN for the base entry under which all groups reside.
113      * A new Name instance is created and returned every time.
114      * @return the groups base DN
115      */
116     public static final LdapDN getGroupsBaseName()
117     {
118         LdapDN groupsBaseDn = null;
119 
120         try
121         {
122             groupsBaseDn = new LdapDN( ServerDNConstants.GROUPS_SYSTEM_DN );
123         }
124         catch ( Exception e )
125         {
126             throw new InternalError();
127         }
128 
129         return groupsBaseDn;
130     }
131 
132 
133     /**
134      * Gets the DN for the base entry under which all non-admin users reside.
135      * A new Name instance is created and returned every time.
136      * @return the users base DN
137      */
138     public static final LdapDN getUsersBaseName()
139     {
140         LdapDN usersBaseDn = null;
141 
142         try
143         {
144             usersBaseDn = new LdapDN( ServerDNConstants.USERS_SYSTEM_DN );
145         }
146         catch ( Exception e )
147         {
148             throw new InternalError();
149         }
150 
151         return usersBaseDn;
152     }
153 
154 
155     /**
156      * Gets the LdapContext associated with the calling thread.
157      * 
158      * @return The LdapContext associated with the thread of execution or null
159      * if no context is associated with the calling thread.
160      */
161     public abstract LdapContext getLdapContext();
162 
163 
164     /**
165      * Get's the RootDSE entry for the DSA.
166      *
167      * @return the attributes of the RootDSE
168      */
169     public abstract ClonedServerEntry getRootDSE( GetRootDSEOperationContext opContext ) throws Exception;
170 
171 
172     /**
173      * Performs a comparison check to see if an attribute of an entry has
174      * a specified value.
175      *
176      * @param compareContext the context used to compare
177      * @return true if the entry contains an attribute with the value, false otherwise
178      * @throws Exception if there is a problem accessing the entry and its values
179      * @throws Exception 
180      */
181     public abstract boolean compare( CompareOperationContext compareContext ) throws Exception;
182 
183 
184     public abstract void addContextPartition( AddContextPartitionOperationContext opContext ) throws Exception;
185 
186 
187     public abstract void removeContextPartition( RemoveContextPartitionOperationContext opContext ) throws Exception;
188 
189 
190     public abstract Partition getSystemPartition();
191 
192 
193     /**
194      * Get's the partition corresponding to a distinguished name.  This 
195      * name need not be the name of the partition suffix.  When used in 
196      * conjunction with get suffix this can properly find the partition 
197      * associated with the DN.  Make sure to use the normalized DN.
198      * 
199      * @param dn the normalized distinguished name to get a partition for
200      * @return the partition containing the entry represented by the dn
201      * @throws Exception if there is no partition for the dn
202      */
203     public abstract Partition getPartition( LdapDN dn ) throws Exception;
204 
205 
206     /**
207      * Gets the most significant Dn that exists within the server for any Dn.
208      *
209      * @param getMatchedNameContext the context containing the  distinguished name 
210      * to use for matching.
211      * @return a distinguished name representing the matching portion of dn,
212      * as originally provided by the user on creation of the matched entry or 
213      * the empty string distinguished name if no match was found.
214      * @throws Exception if there are any problems
215      */
216     public abstract LdapDN getMatchedName ( GetMatchedNameOperationContext getMatchedNameContext ) throws Exception;
217 
218 
219     /**
220      * Gets the distinguished name of the suffix that would hold an entry with
221      * the supplied distinguished name parameter.  If the DN argument does not
222      * fall under a partition suffix then the empty string Dn is returned.
223      *
224      * @param suffixContext the Context containing normalized distinguished
225      * name to use for finding a suffix.
226      * @return the suffix portion of dn, or the valid empty string Dn if no
227      * naming context was found for dn.
228      * @throws Exception if there are any problems
229      */
230     public abstract LdapDN getSuffix ( GetSuffixOperationContext suffixContext ) throws Exception;
231 
232 
233     /**
234      * Gets an iteration over the Name suffixes of the partitions managed by this
235      * {@link PartitionNexus}.
236      *
237      * @return Iteration over ContextPartition suffix names as Names.
238      * @throws Exception if there are any problems
239      */
240     public abstract Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception;
241 
242 
243     /**
244      * Adds a set of supportedExtension (OID Strings) to the RootDSE.
245      * 
246      * @param extensionOids a set of OID strings to add to the supportedExtension 
247      * attribute in the RootDSE
248      */
249     public abstract void registerSupportedExtensions( Set<String> extensionOids ) throws Exception;
250 
251 
252     public abstract void registerSupportedSaslMechanisms( Set<String> strings ) throws Exception;
253 }