View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.ldap.server.partition;
18  
19  
20  import java.util.Iterator;
21  
22  import javax.naming.Name;
23  import javax.naming.NamingException;
24  import javax.naming.directory.Attributes;
25  import javax.naming.ldap.LdapContext;
26  
27  import org.apache.ldap.common.name.LdapName;
28  import org.apache.ldap.server.configuration.DirectoryPartitionConfiguration;
29  
30  
31  /***
32   * A root {@link DirectoryPartition} that contains all other partitions, and
33   * routes all operations to the child partition that matches to its base suffixes.
34   * It also provides some extended operations such as accessing rootDSE and
35   * listing base suffixes.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   * @version $Rev: 328323 $, $Date: 2005-10-25 06:08:31 -0400 (Tue, 25 Oct 2005) $
39   */
40  public abstract class DirectoryPartitionNexus implements DirectoryPartition
41  {
42      /*** the default user principal or DN */
43      public final static String ADMIN_PRINCIPAL = "uid=admin,ou=system";
44      /*** the admin super user uid */
45      public final static String ADMIN_UID = "admin";
46      /*** the initial admin passwd set on startup */
47      public static final String ADMIN_PASSWORD = "secret";
48      /*** the base dn under which all users reside */
49      public final static String USERS_BASE_NAME = "ou=users,ou=system";
50      /*** the base dn under which all groups reside */
51      public final static String GROUPS_BASE_NAME = "ou=groups,ou=system";
52  
53      /***
54       * System backend suffix constant.  Should be kept down to a single Dn name 
55       * component or the default constructor will have to parse it instead of 
56       * building the name.  Note that what ever the SUFFIX equals it should be 
57       * both the normalized and the user provided form.
58       */
59      public static final String SYSTEM_PARTITION_SUFFIX = "ou=system" ;
60  
61      /***
62       * Gets the DN for the admin user.
63       * @return the admin user DN
64       */
65      public static final Name getAdminName()
66      {
67          Name adminDn = null;
68      
69          try
70          {
71              adminDn = new LdapName( ADMIN_PRINCIPAL );
72          }
73          catch ( NamingException e )
74          {
75              throw new InternalError();
76          }
77      
78          return adminDn;
79      }
80  
81      /***
82       * Gets the DN for the base entry under which all groups reside.
83       * A new Name instance is created and returned every time.
84       * @return the groups base DN
85       */
86      public static final Name getGroupsBaseName()
87      {
88          Name groupsBaseDn = null;
89      
90          try
91          {
92              groupsBaseDn = new LdapName( GROUPS_BASE_NAME );
93          }
94          catch ( NamingException e )
95          {
96              throw new InternalError();
97          }
98      
99          return groupsBaseDn;
100     }
101 
102     /***
103      * Gets the DN for the base entry under which all non-admin users reside.
104      * A new Name instance is created and returned every time.
105      * @return the users base DN
106      */
107     public static final Name getUsersBaseName()
108     {
109         Name usersBaseDn = null;
110     
111         try
112         {
113             usersBaseDn = new LdapName( USERS_BASE_NAME );
114         }
115         catch ( NamingException e )
116         {
117             throw new InternalError();
118         }
119     
120         return usersBaseDn;
121     }
122 
123     /***
124      * Gets the LdapContext associated with the calling thread.
125      * 
126      * @return The LdapContext associated with the thread of execution or null
127      * if no context is associated with the calling thread.
128      */
129     public abstract LdapContext getLdapContext();
130 
131     /***
132      * Get's the RootDSE entry for the DSA.
133      *
134      * @return the attributes of the RootDSE
135      */
136     public abstract Attributes getRootDSE() throws NamingException;
137 
138     /***
139      * Performs a comparison check to see if an attribute of an entry has
140      * a specified value.
141      *
142      * @param name the normalized name of the entry
143      * @param oid the attribute being compared
144      * @param value the value the attribute is compared to
145      * @return true if the entry contains an attribute with the value, false otherwise
146      * @throws NamingException if there is a problem accessing the entry and its values
147      */
148     public abstract boolean compare( Name name, String oid, Object value ) throws NamingException;
149 
150     public abstract void addContextPartition( DirectoryPartitionConfiguration config ) throws NamingException;
151     
152     public abstract void removeContextPartition( Name suffix ) throws NamingException;
153 
154     public abstract DirectoryPartition getSystemPartition();
155 
156     /***
157      * Gets the most significant Dn that exists within the server for any Dn.
158      *
159      * @param name the normalized distinguished name to use for matching.
160      * @param normalized boolean if true cause the return of a normalized Dn,
161      * if false it returns the original user provided distinguished name for 
162      * the matched portion of the Dn as it was provided on entry creation.
163      * @return a distinguished name representing the matching portion of dn,
164      * as originally provided by the user on creation of the matched entry or 
165      * the empty string distinguished name if no match was found.
166      * @throws NamingException if there are any problems
167      */
168     public abstract Name getMatchedName( Name name, boolean normalized ) throws NamingException;
169 
170     /***
171      * Gets the distinguished name of the suffix that would hold an entry with
172      * the supplied distinguished name parameter.  If the DN argument does not
173      * fall under a partition suffix then the empty string Dn is returned.
174      *
175      * @param name the normalized distinguished name to use for finding a suffix.
176      * @param normalized if true causes the return of a normalized Dn, but
177      * if false it returns the original user provided distinguished name for 
178      * the suffix Dn as it was provided on suffix entry creation.
179      * @return the suffix portion of dn, or the valid empty string Dn if no
180      * naming context was found for dn.
181      * @throws NamingException if there are any problems
182      */
183     public abstract Name getSuffix( Name name, boolean normalized ) throws NamingException;
184 
185     /***
186      * Gets an iteration over the Name suffixes of the Backends managed by this
187      * {@link DirectoryPartitionNexus}.
188      *
189      * @param normalized if true the returned Iterator contains normalized Dn
190      * but, if false, it returns the original user provided distinguished names
191      * in the Iterator.
192      * @return Iteration over ContextPartition suffix names as Names.
193      * @throws NamingException if there are any problems
194      */
195     public abstract Iterator listSuffixes( boolean normalized ) throws NamingException;
196 }