1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.ContextPartitionConfiguration;
29
30
31 /***
32 * A root {@link ContextPartition} 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: 264732 $, $Date: 2005-08-30 04:04:51 -0400 (Tue, 30 Aug 2005) $
39 */
40 public abstract class ContextPartitionNexus implements ContextPartition
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 byte[] ADMIN_PW = "secret".getBytes();
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 public abstract void addContextPartition( ContextPartitionConfiguration config ) throws NamingException;
139
140 public abstract void removeContextPartition( Name suffix ) throws NamingException;
141
142 public abstract ContextPartition getSystemPartition();
143
144 /***
145 * Gets the most significant Dn that exists within the server for any Dn.
146 *
147 * @param name the normalized distinguished name to use for matching.
148 * @param normalized boolean if true cause the return of a normalized Dn,
149 * if false it returns the original user provided distinguished name for
150 * the matched portion of the Dn as it was provided on entry creation.
151 * @return a distinguished name representing the matching portion of dn,
152 * as originally provided by the user on creation of the matched entry or
153 * the empty string distinguished name if no match was found.
154 * @throws NamingException if there are any problems
155 */
156 public abstract Name getMatchedName( Name name, boolean normalized ) throws NamingException;
157
158 /***
159 * Gets the distinguished name of the suffix that would hold an entry with
160 * the supplied distinguished name parameter. If the DN argument does not
161 * fall under a partition suffix then the empty string Dn is returned.
162 *
163 * @param name the normalized distinguished name to use for finding a suffix.
164 * @param normalized if true causes the return of a normalized Dn, but
165 * if false it returns the original user provided distinguished name for
166 * the suffix Dn as it was provided on suffix entry creation.
167 * @return the suffix portion of dn, or the valid empty string Dn if no
168 * naming context was found for dn.
169 * @throws NamingException if there are any problems
170 */
171 public abstract Name getSuffix( Name name, boolean normalized ) throws NamingException;
172
173 /***
174 * Gets an iteration over the Name suffixes of the Backends managed by this
175 * {@link ContextPartitionNexus}.
176 *
177 * @param normalized if true the returned Iterator contains normalized Dn
178 * but, if false, it returns the original user provided distinguished names
179 * in the Iterator.
180 * @return Iteration over ContextPartition suffix names as Names.
181 * @throws NamingException if there are any problems
182 */
183 public abstract Iterator listSuffixes( boolean normalized ) throws NamingException;
184 }