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
29
30 /***
31 * A root {@link ContextPartition} that contains all other partitions, and
32 * routes all operations to the child partition that matches to its base suffixes.
33 * It also provides some extended operations such as accessing rootDSE and
34 * listing base suffixes.
35 *
36 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37 * @version $Rev: 226451 $, $Date: 2005-07-29 20:54:58 -0400 (Fri, 29 Jul 2005) $
38 */
39 public abstract class ContextPartitionNexus implements ContextPartition
40 {
41 /*** the default user principal or DN */
42 public final static String ADMIN_PRINCIPAL = "uid=admin,ou=system";
43 /*** the admin super user uid */
44 public final static String ADMIN_UID = "admin";
45 /*** the initial admin passwd set on startup */
46 public static final byte[] ADMIN_PW = "secret".getBytes();
47 /*** the base dn under which all users reside */
48 public final static String USERS_BASE_NAME = "ou=users,ou=system";
49 /*** the base dn under which all groups reside */
50 public final static String GROUPS_BASE_NAME = "ou=groups,ou=system";
51
52 /***
53 * System backend suffix constant. Should be kept down to a single Dn name
54 * component or the default constructor will have to parse it instead of
55 * building the name. Note that what ever the SUFFIX equals it should be
56 * both the normalized and the user provided form.
57 */
58 public static final String SYSTEM_PARTITION_SUFFIX = "ou=system" ;
59
60 /***
61 * Gets the DN for the admin user.
62 * @return the admin user DN
63 */
64 public static final Name getAdminName()
65 {
66 Name adminDn = null;
67
68 try
69 {
70 adminDn = new LdapName( ADMIN_PRINCIPAL );
71 }
72 catch ( NamingException e )
73 {
74 throw new InternalError();
75 }
76
77 return adminDn;
78 }
79
80 /***
81 * Gets the DN for the base entry under which all groups reside.
82 * A new Name instance is created and returned every time.
83 * @return the groups base DN
84 */
85 public static final Name getGroupsBaseName()
86 {
87 Name groupsBaseDn = null;
88
89 try
90 {
91 groupsBaseDn = new LdapName( GROUPS_BASE_NAME );
92 }
93 catch ( NamingException e )
94 {
95 throw new InternalError();
96 }
97
98 return groupsBaseDn;
99 }
100
101 /***
102 * Gets the DN for the base entry under which all non-admin users reside.
103 * A new Name instance is created and returned every time.
104 * @return the users base DN
105 */
106 public static final Name getUsersBaseName()
107 {
108 Name usersBaseDn = null;
109
110 try
111 {
112 usersBaseDn = new LdapName( USERS_BASE_NAME );
113 }
114 catch ( NamingException e )
115 {
116 throw new InternalError();
117 }
118
119 return usersBaseDn;
120 }
121
122 /***
123 * Gets the LdapContext associated with the calling thread.
124 *
125 * @return The LdapContext associated with the thread of execution or null
126 * if no context is associated with the calling thread.
127 */
128 public abstract LdapContext getLdapContext();
129
130 /***
131 * Get's the RootDSE entry for the DSA.
132 *
133 * @return the attributes of the RootDSE
134 */
135 public abstract Attributes getRootDSE() throws NamingException;
136
137 public abstract ContextPartition getSystemPartition();
138
139 /***
140 * Gets the most significant Dn that exists within the server for any Dn.
141 *
142 * @param name the normalized distinguished name to use for matching.
143 * @param normalized boolean if true cause the return of a normalized Dn,
144 * if false it returns the original user provided distinguished name for
145 * the matched portion of the Dn as it was provided on entry creation.
146 * @return a distinguished name representing the matching portion of dn,
147 * as originally provided by the user on creation of the matched entry or
148 * the empty string distinguished name if no match was found.
149 * @throws NamingException if there are any problems
150 */
151 public abstract Name getMatchedName( Name name, boolean normalized ) throws NamingException;
152
153 /***
154 * Gets the distinguished name of the suffix that would hold an entry with
155 * the supplied distinguished name parameter. If the DN argument does not
156 * fall under a partition suffix then the empty string Dn is returned.
157 *
158 * @param name the normalized distinguished name to use for finding a suffix.
159 * @param normalized if true causes the return of a normalized Dn, but
160 * if false it returns the original user provided distinguished name for
161 * the suffix Dn as it was provided on suffix entry creation.
162 * @return the suffix portion of dn, or the valid empty string Dn if no
163 * naming context was found for dn.
164 * @throws NamingException if there are any problems
165 */
166 public abstract Name getSuffix( Name name, boolean normalized ) throws NamingException;
167
168 /***
169 * Gets an iteration over the Name suffixes of the Backends managed by this
170 * BackendNexus.
171 *
172 * @param normalized if true the returned Iterator contains normalized Dn
173 * but, if false, it returns the original user provided distinguished names
174 * in the Iterator.
175 * @return Iteration over ContextPartition suffix names as Names.
176 * @throws NamingException if there are any problems
177 */
178 public abstract Iterator listSuffixes( boolean normalized ) throws NamingException;
179 }