1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server;
18
19 import org.apache.ldap.common.message.LockableAttributesImpl;
20 import org.apache.ldap.common.name.LdapName;
21 import org.apache.ldap.common.schema.AttributeType;
22 import org.apache.ldap.common.util.DateUtils;
23 import org.apache.ldap.common.util.NamespaceTools;
24 import org.apache.ldap.server.db.Database;
25 import org.apache.ldap.server.db.SearchEngine;
26
27 import javax.naming.InvalidNameException;
28 import javax.naming.Name;
29 import javax.naming.NamingException;
30 import javax.naming.directory.Attributes;
31
32
33 /***
34 * A very special ContextPartition used to store system information such as
35 * users, the system catalog and other administrative information. This
36 * partition is fixed at the ou=system context.
37 *
38 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39 * @version $Rev: 159259 $
40 */
41 public final class SystemPartition extends AbstractContextPartition
42 {
43 /*** the default user principal or DN */
44 public final static String ADMIN_PRINCIPAL = "uid=admin,ou=system";
45 /*** the admin super user uid */
46 public final static String ADMIN_UID = "admin";
47 /*** the initial admin passwd set on startup */
48 public static final byte[] ADMIN_PW = "secret".getBytes();
49 /*** the base dn under which all users reside */
50 public final static String USERS_BASE_DN = "ou=users,ou=system";
51 /*** the base dn under which all groups reside */
52 public final static String GROUPS_BASE_DN = "ou=groups,ou=system";
53
54 /***
55 * System backend suffix constant. Should be kept down to a single Dn name
56 * component or the default constructor will have to parse it instead of
57 * building the name. Note that what ever the SUFFIX equals it should be
58 * both the normalized and the user provided form.
59 */
60 public static final String SUFFIX = "ou=system" ;
61
62 /*** The suffix as a name. */
63 private final Name suffix ;
64
65
66
67
68
69
70
71 /***
72 * Gets the DN for the base entry under which all non-admin users reside.
73 * A new Name instance is created and returned every time.
74 *
75 * @see #USERS_BASE_DN
76 * @return the users base DN
77 */
78 public static final Name getUsersBaseDn()
79 {
80 Name usersBaseDn = null;
81
82 try
83 {
84 usersBaseDn = new LdapName( USERS_BASE_DN );
85 }
86 catch ( NamingException e )
87 {
88 e.printStackTrace();
89
90 }
91
92 return usersBaseDn;
93 }
94
95
96 /***
97 * Gets the DN for the base entry under which all groups reside.
98 * A new Name instance is created and returned every time.
99 *
100 * @see #GROUPS_BASE_DN
101 * @return the groups base DN
102 */
103 public static final Name getGroupsBaseDn()
104 {
105 Name groupsBaseDn = null;
106
107 try
108 {
109 groupsBaseDn = new LdapName( GROUPS_BASE_DN );
110 }
111 catch ( NamingException e )
112 {
113 e.printStackTrace();
114
115 }
116
117 return groupsBaseDn;
118 }
119
120
121 /***
122 * Gets the DN for the admin user.
123 *
124 * @see #ADMIN_PRINCIPAL
125 * @return the admin user DN
126 */
127 public static final Name getAdminDn()
128 {
129 Name adminDn = null;
130
131 try
132 {
133 adminDn = new LdapName( ADMIN_PRINCIPAL );
134 }
135 catch ( NamingException e )
136 {
137 e.printStackTrace();
138
139 }
140
141 return adminDn;
142 }
143
144
145
146
147
148
149
150 /***
151 * Creates the system partition which is used to store various peices of
152 * information critical for server operation. Things like the system
153 * catalog and other operational information like system users are
154 * maintained within the context of this partition. Unlike other
155 * ContextBackends which must have their suffix specified this one does
156 * not since it will stay fixed at the following namingContext: ou=system.
157 *
158 * @param db the database used for this partition
159 * @param searchEngine the search engine to conduct searches with
160 * @param indexAttributes the attributeTypes of indicies to build which must
161 * also contain all system index attribute types - if not the system will
162 * not operate correctly.
163 */
164 public SystemPartition( Database db, SearchEngine searchEngine,
165 AttributeType[] indexAttributes )
166 throws NamingException
167 {
168 super( db, searchEngine, indexAttributes );
169 suffix = new LdapName() ;
170
171 try
172 {
173 suffix.add( SUFFIX ) ;
174 }
175 catch ( InvalidNameException e )
176 {
177
178 }
179
180
181 Attributes attributes = db.getSuffixEntry() ;
182 if ( null == attributes )
183 {
184 attributes = new LockableAttributesImpl() ;
185 attributes.put( "objectClass", "top" ) ;
186 attributes.put( "objectClass", "organizationalUnit" ) ;
187 attributes.put( "creatorsName", ADMIN_PRINCIPAL ) ;
188 attributes.put( "createTimestamp", DateUtils.getGeneralizedTime() ) ;
189 attributes.put( NamespaceTools.getRdnAttribute( SUFFIX ),
190 NamespaceTools.getRdnValue( SUFFIX ) ) ;
191
192 getDb().add( SUFFIX, suffix, attributes ) ;
193 }
194 }
195
196
197
198
199
200
201
202 /***
203 * @see org.apache.ldap.server.ContextPartition#getSuffix(boolean)
204 */
205 public final Name getSuffix( boolean normalized )
206 {
207
208
209
210
211 return ( Name ) suffix.clone() ;
212 }
213
214
215 /***
216 * @see org.apache.ldap.server.BackingStore#isSuffix(javax.naming.Name)
217 */
218 public final boolean isSuffix( Name dn )
219 {
220 return SUFFIX.equals( dn.toString() ) ;
221 }
222 }