public void setDirectoryService( DirectoryService directoryService ) { this.directoryService = directoryService; this.schemaManager = directoryService.getSchemaManager(); this.session = directoryService.getAdminSession(); }
@Override public void addPartition(Partition partition) throws Exception { wrapped.addPartition(partition); }
/** * Inits the system partition. * * @throws Exception the exception */ private void initSystemPartition() throws Exception { // change the working directory to something that is unique // on the system and somewhere either under target directory // or somewhere in a temp area of the machine. // Inject the System Partition Partition systemPartition = partitionFactory.createPartition( directoryService.getSchemaManager(), directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File( directoryService.getInstanceLayout().getPartitionsDirectory(), "system" ) ); systemPartition.setSchemaManager( directoryService.getSchemaManager() ); partitionFactory.addIndex( systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100 ); directoryService.setSystemPartition( systemPartition ); }
/** * This method does nothing by default. * * @param directoryService The DirectoryService instance * @throws LdapException If the initialization failed */ public void init( DirectoryService directoryService ) throws LdapException { // Initialize the fields that will be used by all the interceptors this.directoryService = directoryService; schemaManager = directoryService.getSchemaManager(); dnFactory = directoryService.getDnFactory(); finalInterceptor.init( directoryService ); }
public static CoreSession getCoreSession( String principalDn, DirectoryService service, String dn ) throws LdapException { if ( principalDn == null ) { principalDn = ""; } Dn userDn = new Dn( service.getSchemaManager(), principalDn ); LdapPrincipal principal = new LdapPrincipal( service.getSchemaManager(), userDn, AuthenticationLevel.SIMPLE ); CoreSession session = service.getSession( principal ); return session; }
private void initDirectoryService() throws Exception { ds = new DefaultDirectoryService(); ds.setInstanceLayout(new InstanceLayout(workDir)); ds.setCacheService(cacheService); InstanceLayout instanceLayout = ds.getInstanceLayout(); File schemaPartitionDirectory = new File( instanceLayout.getPartitionsDirectory(), "schema"); SchemaManager schemaManager = new DefaultSchemaManager(loader); schemaManager.loadAllEnabled(); ds.setSchemaManager(schemaManager); ds.setSchemaPartition(schemaPartition); JdbmPartition systemPartition = new JdbmPartition(ds.getSchemaManager()); systemPartition.setId("system"); systemPartition.setPartitionPath(new File( ds.getInstanceLayout().getPartitionsDirectory(), systemPartition.getId()).toURI()); systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN)); systemPartition.setSchemaManager(ds.getSchemaManager()); ds.setSystemPartition(systemPartition); ds.getChangeLog().setEnabled(false); ds.setDenormalizeOpAttrsEnabled(true); ds.addLast(new KeyDerivationInterceptor()); JdbmPartition partition = new JdbmPartition(ds.getSchemaManager());
if ((directoryService != null) && directoryService.isStarted()) { return; directoryService.setInstanceId(name); directoryService.setInstanceLayout(instanceLayout); ehCacheConfig.addDefaultCache(defaultCache); CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig)); directoryService.setCacheService(cacheService); directoryService.setSchemaManager(schemaManager); InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager); directoryService.setSchemaPartition(schemaPartition); List<Throwable> errors = schemaManager.getErrors(); if (errors.size() != 0) { Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system")); systemPartition.setSchemaManager(directoryService.getSchemaManager()); partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100); directoryService.setSystemPartition(systemPartition); directoryService.startup();
directoryService.setShutdownHookEnabled(false); directoryService.setInstanceLayout(new InstanceLayout(cwd)); cacheService.initialize(directoryService.getInstanceLayout()); directoryService.setSchemaManager(schemaManager); directoryService.setDnFactory(new DefaultDnFactory(directoryService.getSchemaManager(), cacheService.getCache("dnCache"))); AvlPartition schLdifPart = new AvlPartition(directoryService.getSchemaManager(), directoryService.getDnFactory()); schLdifPart.setId("schema"); schLdifPart.setSuffixDn(directoryService.getDnFactory().create(ServerDNConstants.CN_SCHEMA_DN)); SchemaPartition schPart = new SchemaPartition(directoryService.getSchemaManager()); schPart.setWrappedPartition(schLdifPart); directoryService.setSchemaPartition(schPart); AvlPartition sysPart = new AvlPartition(directoryService.getSchemaManager(), directoryService.getDnFactory()); sysPart.setId(SystemSchemaConstants.SCHEMA_NAME); sysPart.setSuffixDn(directoryService.getDnFactory().create(ServerDNConstants.SYSTEM_DN)); directoryService.setSystemPartition(sysPart); AvlPartition examplePart = new AvlPartition(directoryService.getSchemaManager(), directoryService.getDnFactory()); examplePart.setId("example"); examplePart.setSuffixDn(directoryService.getDnFactory().create(EXAMPLE_DN)); examplePart.setCacheService(cacheService); directoryService.addPartition(examplePart); directoryService.startup(); setupExamplePartition(); startLdapServer();
private ApacheDS startDirectoryService(String workDirStr) throws Exception { DefaultDirectoryServiceFactory factory = new DefaultDirectoryServiceFactory(); factory.init(realm); directoryService = factory.getDirectoryService(); directoryService.getChangeLog().setEnabled(false); directoryService.setShutdownHookEnabled(false); directoryService.setAllowAnonymousAccess(true); File workDir = new File(workDirStr); if (workDir.exists()) { FileUtils.deleteDirectory(workDir); } InstanceLayout instanceLayout = new InstanceLayout(workDir); directoryService.setInstanceLayout(instanceLayout); AvlPartition partition = new AvlPartition(directoryService.getSchemaManager()); partition.setId("Test"); partition.setSuffixDn(new Dn(directoryService.getSchemaManager(), baseDn)); partition.addIndexedAttributes( new AvlIndex<>("ou"), new AvlIndex<>("uid"), new AvlIndex<>("dc"), new AvlIndex<>("objectClass")); partition.initialize(); directoryService.addPartition(partition); directoryService.addLast(new KeyDerivationInterceptor()); directoryService.shutdown(); directoryService.startup(); return this; }
this.service.setInstanceId(INSTANCE_NAME); this.service.setInstanceLayout(new InstanceLayout(this.dataDirectory.toFile())); cacheService.initialize(this.service.getInstanceLayout()); this.service.setCacheService(cacheService); final File systemPartitionPath = new File(this.service.getInstanceLayout().getPartitionsDirectory(), "system"); Partition systemPartition = createPartition(this.service.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, systemPartitionPath); this.service.setSystemPartition(systemPartition); this.service.startup(); final CoreSession session = this.service.getAdminSession();
directoryService.setShutdownHookEnabled( false ); } catch ( Exception e ) { throw new RuntimeException( e ); service.getSchemaManager(), service.getDnFactory(), "users", rootDn, 500, service.getInstanceLayout().getInstanceDirectory() ); service.addPartition( partition ); CoreSession session = service.getAdminSession(); LdifFileLoader lfl = new LdifFileLoader( session, usersLdif, null ); lfl.execute();
public SimpleLdapDirectoryServer( String rootDn, File usersLdif, Transport... transports ) throws Exception { if( !usersLdif.exists() ) { throw new FileNotFoundException( usersLdif.getAbsolutePath() ); } factory = new SimpleDirectoryServiceFactory(); factory.init( UUID.randomUUID().toString() ); service = factory.getDirectoryService(); Partition partition = factory.getPartitionFactory().createPartition( service.getSchemaManager(), "users", rootDn, 500, service.getInstanceLayout().getInstanceDirectory() ); service.addPartition( partition ); CoreSession session = service.getAdminSession(); LdifFileLoader lfl = new LdifFileLoader( session, usersLdif, null ); lfl.execute(); server = new LdapServer(); server.setTransports( transports ); server.setDirectoryService( service ); }
directoryService.setDnFactory( dnFactory ); directoryService.setSchemaPartition( schemaPartition ); directoryService.addPartition( configPartition ); directoryService.setInstanceLayout( instanceLayout ); directoryService.setCacheService( cacheService ); directoryService.startup(); AttributeType ocAt = directoryService.getAtProvider().getObjectClass(); MANDATORY_ENTRY_ATOP_MAP.put( ocAt.getName(), new AttributeTypeOptions( ocAt ) ); AttributeType uuidAt = directoryService.getAtProvider().getEntryUUID(); MANDATORY_ENTRY_ATOP_MAP.put( uuidAt.getName(), new AttributeTypeOptions( uuidAt ) ); AttributeType csnAt = directoryService.getAtProvider().getEntryCSN(); MANDATORY_ENTRY_ATOP_MAP.put( csnAt.getName(), new AttributeTypeOptions( csnAt ) ); AttributeType creatorAt = directoryService.getAtProvider().getCreatorsName(); MANDATORY_ENTRY_ATOP_MAP.put( creatorAt.getName(), new AttributeTypeOptions( creatorAt ) ); AttributeType createdTimeAt = directoryService.getAtProvider().getCreateTimestamp(); MANDATORY_ENTRY_ATOP_MAP.put( createdTimeAt.getName(), new AttributeTypeOptions( createdTimeAt ) );
private void checkPartition(LdifEntry ldifEntry) throws Exception { Dn dn = ldifEntry.getDn(); Dn parent = dn.getParent(); try { directoryService.getAdminSession().exists(parent); } catch (Exception e) { System.out.println("Creating new partition for DN=" + dn + "\n"); AvlPartition partition = new AvlPartition(directoryService.getSchemaManager()); partition.setId(dn.getName()); partition.setSuffixDn(dn); directoryService.addPartition(partition); } }
directoryService.setSchemaPartition( schemaPartition ); directoryService.addPartition( configPartition ); directoryService.setInstanceLayout( instanceLayout ); directoryService.setCacheService(cacheService); directoryService.startup();
public void loadLDIF(String fileName) { File ldifFile = new File(fileName); LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(), ldifFile, null, getClass().getClassLoader()); loader.execute(); } }
/** * Builds the directory server instance. * * @param name the instance name */ private void build( String name ) throws Exception { directoryService.setInstanceId( name ); buildInstanceDirectory( name ); CacheService cacheService = new CacheService(); cacheService.initialize( directoryService.getInstanceLayout(), name ); directoryService.setCacheService( cacheService ); // Init the service now initSchema(); initSystemPartition(); directoryService.startup(); }
public SubentryUtils( DirectoryService directoryService ) { this.directoryService = directoryService; this.schemaManager = directoryService.getSchemaManager(); }
/** * Creates a {@link JdbmPartition} with the given id and DN. * * @param id Id to create partition with. * @param dn Distinguished Name to use to create partition. * @return Created partition. */ private JdbmPartition createPartition(String id, Dn dn) throws LdapInvalidDnException { JdbmPartition partition = new JdbmPartition(service.getSchemaManager(), service.getDnFactory()); partition.setId(id); partition.setPartitionPath( new File(service.getInstanceLayout().getPartitionsDirectory(), id).toURI()); partition.setSuffixDn(dn); partition.setSchemaManager(service.getSchemaManager()); return partition; }
public void stop( boolean clean ) throws Exception { server.stop(); service.shutdown(); if( clean ) { FileUtils.deleteDirectory( service.getInstanceLayout().getInstanceDirectory() ); } }