1 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 41 public final class SystemPartition extends AbstractContextPartition 42 { 43 44 public final static String ADMIN_PRINCIPAL = "uid=admin,ou=system"; 45 46 public final static String ADMIN_UID = "admin"; 47 48 public static final byte[] ADMIN_PW = "secret".getBytes(); 49 50 public final static String USERS_BASE_DN = "ou=users,ou=system"; 51 52 public final static String GROUPS_BASE_DN = "ou=groups,ou=system"; 53 54 60 public static final String SUFFIX = "ou=system" ; 61 62 63 private final Name suffix ; 64 65 66 70 71 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 } 91 92 return usersBaseDn; 93 } 94 95 96 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 } 116 117 return groupsBaseDn; 118 } 119 120 121 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 } 140 141 return adminDn; 142 } 143 144 145 149 150 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 } 179 180 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 201 202 205 public final Name getSuffix( boolean normalized ) 206 { 207 211 return ( Name ) suffix.clone() ; 212 } 213 214 215 218 public final boolean isSuffix( Name dn ) 219 { 220 return SUFFIX.equals( dn.toString() ) ; 221 } 222 } 223 | Popular Tags |