org.apache.directory.server.core.api.DirectoryService Java Examples

The following examples show how to use org.apache.directory.server.core.api.DirectoryService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleLDAPAuthenticationManagerTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void createPrincipal(final String sn,
                             final String cn,
                             final String uid,
                             final String userPassword,
                             final String kerberosPrincipalName) throws LdapException
{
    final DirectoryService directoryService = LDAP.getDirectoryService();
    final Entry entry = new DefaultEntry(directoryService.getSchemaManager());
    entry.setDn(String.format("uid=%s,%s", uid, USERS_DN));
    entry.add("objectClass", "top", "person", "inetOrgPerson", "krb5principal", "krb5kdcentry");
    entry.add("cn", cn);
    entry.add("sn", sn);
    entry.add("uid", uid);
    entry.add("userPassword", userPassword);
    entry.add("krb5PrincipalName", kerberosPrincipalName);
    entry.add("krb5KeyVersionNumber", "0");
    directoryService.getAdminSession().add(entry);
}
 
Example #2
Source File: TestLDAPAuthentication.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private void createPrincipal(String principal, String password)
    throws Exception {
  DirectoryService ds = getService();
  String baseDn = "ou=users,ou=system";
  String content = "dn: uid=" + principal + "," + baseDn + "\n" +
      "objectClass: top\n" +
      "objectClass: person\n" +
      "objectClass: inetOrgPerson\n" +
      "cn: " + principal + "\n" +
      "sn: " + principal + "\n" +
      "uid: " + principal + "\n" +
      "userPassword: " + password;

  for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
    ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(),
        ldifEntry.getEntry()));
  }
}
 
Example #3
Source File: LdapServer.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void importLdif(DirectoryService directoryService,
                        final SchemaManager schemaManager,
                        LdifReader ldifReader) throws Exception {
   try {
      for (LdifEntry ldifEntry : ldifReader) {
         checkPartition(ldifEntry);
         directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
      }
   } finally {
      try {
         ldifReader.close();
      } catch (IOException ioe) {
         // ignore
      }
   }
}
 
Example #4
Source File: ApacheDSRootDseServlet.java    From syncope with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an environment configuration for JNDI access.
 */
private Properties createEnv() {
    // Fetch directory service from servlet context
    ServletContext servletContext = this.getServletContext();
    DirectoryService directoryService = (DirectoryService) servletContext.getAttribute(DirectoryService.JNDI_KEY);

    Properties env = new Properties();
    env.put(DirectoryService.JNDI_KEY, directoryService);
    env.put(Context.PROVIDER_URL, "");
    env.put(Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());

    env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");

    return env;
}
 
Example #5
Source File: KerberosEmbeddedServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected DirectoryService createDirectoryService() throws Exception {
    DirectoryService directoryService = super.createDirectoryService();

    directoryService.addLast(new KeyDerivationInterceptor());
    return directoryService;
}
 
Example #6
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public void setDirectoryService( DirectoryService directoryService )
{
    super.setDirectoryService( directoryService );
    Iterator<String> itr = directoryService.getLdapCodecService().registeredControls();
    while ( itr.hasNext() )
    {
        supportedControls.add( itr.next() );
    }
}
 
Example #7
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init( DirectoryService directoryService ) throws LdapException
{
    super.init( directoryService );
    nexus = directoryService.getPartitionNexus();
    Value<?> attr = nexus.getRootDse( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
    subschemSubentryDn = directoryService.getDnFactory().create( attr.getString() );
}
 
Example #8
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the Schema Service
 *
 * @param directoryService the directory service core
 * @throws Exception if there are problems during initialization
 */
public void init( DirectoryService directoryService ) throws LdapException
{
    if ( IS_DEBUG )
    {
        LOG.debug( "Initializing SchemaInterceptor..." );
    }

    super.init( directoryService );

    nexus = directoryService.getPartitionNexus();
    topFilter = new TopFilter();
    filters.add( topFilter );

    schemaBaseDn = directoryService.getDnFactory().create( SchemaConstants.OU_SCHEMA );

    // stuff for dealing with subentries (garbage for now)
    Value<?> subschemaSubentry = nexus.getRootDse( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
    subschemaSubentryDn = directoryService.getDnFactory().create( subschemaSubentry.getString() );
    subschemaSubentryDn.apply( schemaManager );
    subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();

    schemaModificationAttributesDn = directoryService.getDnFactory().create(
        SchemaConstants.SCHEMA_MODIFICATIONS_DN );
    schemaModificationAttributesDn.apply( schemaManager );

    computeSuperiors();

    // Initialize the schema manager
    SchemaLoader loader = directoryService.getSchemaManager().getLoader();
    schemaSubEntryManager = new SchemaSubentryManager( schemaManager, loader, directoryService.getDnFactory() );

    if ( IS_DEBUG )
    {
        LOG.debug( "SchemaInterceptor Initialized !" );
    }
}
 
Example #9
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
public void setDirectoryService( DirectoryService directoryService )
{
    super.setDirectoryService( directoryService );
    Iterator<String> itr = directoryService.getLdapCodecService().registeredControls();
    while ( itr.hasNext() )
    {
        supportedControls.add( itr.next() );
    }
}
 
Example #10
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init( DirectoryService directoryService ) throws LdapException
{
    super.init( directoryService );
    nexus = directoryService.getPartitionNexus();
    Value<?> attr = nexus.getRootDseValue( SUBSCHEMA_SUBENTRY_AT );
    subschemSubentryDn = dnFactory.create( attr.getString() );
}
 
Example #11
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the Schema Service
 *
 * @param directoryService the directory service core
 * @throws Exception if there are problems during initialization
 */
public void init( DirectoryService directoryService ) throws LdapException
{
    if ( IS_DEBUG )
    {
        LOG.debug( "Initializing SchemaInterceptor..." );
    }

    super.init( directoryService );

    nexus = directoryService.getPartitionNexus();
    topFilter = new TopFilter();
    filters.add( topFilter );

    schemaBaseDn = dnFactory.create( SchemaConstants.OU_SCHEMA );

    // stuff for dealing with subentries (garbage for now)
    Value<?> subschemaSubentry = nexus.getRootDseValue( SUBSCHEMA_SUBENTRY_AT );
    subschemaSubentryDn = dnFactory.create( subschemaSubentry.getString() );
    subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();

    schemaModificationAttributesDn = dnFactory.create(
        SchemaConstants.SCHEMA_MODIFICATIONS_DN );

    computeSuperiors();

    // Initialize the schema manager
    SchemaLoader loader = directoryService.getSchemaManager().getLoader();
    schemaSubEntryManager = new SchemaSubentryManager( schemaManager, loader, dnFactory );

    if ( IS_DEBUG )
    {
        LOG.debug( "SchemaInterceptor Initialized !" );
    }
}
 
Example #12
Source File: TestLDAPAuthentication.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void createGroup(String groupName, String memberDn) throws Exception {
  DirectoryService ds = getService();
  String baseDn = "ou=groups,ou=system";
  String content = "dn: cn=" + groupName + "," + baseDn + "\n" +
      "objectClass: top\n" +
      "objectClass: groupofnames\n" +
      "cn: " + groupName + "\n" +
      "description: " + groupName + "\n" +
      "member: " + memberDn;

  for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
    ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(),
        ldifEntry.getEntry()));
  }
}
 
Example #13
Source File: LdapTestSuite.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void createPartition(final DirectoryServiceFactory dsf, final SchemaManager schemaManager, final String id,
        final String suffix, final DirectoryService directoryService, final File workingDir) throws Exception {
    PartitionFactory pf = dsf.getPartitionFactory();
    Partition p = pf.createPartition(schemaManager, id, suffix, 1000, workingDir);
    pf.addIndex(p, "uid", 10);
    pf.addIndex(p, "departmentNumber", 10);
    pf.addIndex(p, "member", 10);
    pf.addIndex(p, "memberOf", 10);
    p.initialize();
    directoryService.addPartition(p);
}
 
Example #14
Source File: LdapDirectoryServerConnectionTest.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmbeddedLdapServerInitialization() throws IndexNotFoundException {
    LdapServer ldapServer = embeddedLdapServer.getLdapServer();
    assertNotNull(ldapServer);

    DirectoryService directoryService = embeddedLdapServer.getDirectoryService();
    assertNotNull(directoryService);
    assertNotNull(directoryService.getSchemaPartition());
    assertNotNull(directoryService.getSystemPartition());
    assertNotNull(directoryService.getSchemaManager());
    assertNotNull(directoryService.getDnFactory());

    assertNotNull(directoryService.isDenormalizeOpAttrsEnabled());

    ChangeLog changeLog = directoryService.getChangeLog();

    assertNotNull(changeLog);
    assertFalse(changeLog.isEnabled());

    assertNotNull(directoryService.isStarted());
    assertNotNull(ldapServer.isStarted());

    List userList = new ArrayList(embeddedLdapServer.getUserIndexMap().keySet());
    java.util.Collections.sort(userList);
    List checkList = Arrays.asList("uid");
    assertEquals(userList, checkList);
}
 
Example #15
Source File: DirectoryServiceBuilder.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static void shutdownDirectoryService(DirectoryService service) throws Exception {
    if (service != null) {
        LOG.debug("Shuting down DS for {}", service.getInstanceId());
        service.shutdown();
        FileUtils.deleteDirectory(service.getInstanceLayout().getInstanceDirectory());
    }
}
 
Example #16
Source File: DirectoryServiceBuilder.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static long getCurrentRevision(DirectoryService dirService) throws Exception {
    if ((dirService != null) && (dirService.getChangeLog().isEnabled())) {
        long revision = dirService.getChangeLog().getCurrentRevision();
        LOG.debug("Create revision {}", revision);
        return revision;
    }
    return 0;
}
 
Example #17
Source File: DirectoryServiceBuilder.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static void revert(DirectoryService dirService, long revision) throws Exception {
    ChangeLog cl = dirService.getChangeLog();
    if (cl.isEnabled() && (revision < cl.getCurrentRevision())) {
        LOG.debug("Revert revision {}", revision);
        dirService.revert(revision);
    }
}
 
Example #18
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the registries, normalizers.
 */
@Override
public void init( DirectoryService directoryService ) throws LdapException
{
    LOG.debug( "Initialiazing the NormalizationInterceptor" );

    super.init( directoryService );

    NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( schemaManager );
    normVisitor = new FilterNormalizingVisitor( ncn, schemaManager );
}
 
Example #19
Source File: Runner.java    From aws-iam-ldap-bridge with Apache License 2.0 5 votes vote down vote up
public Partition getPartition(DirectoryService directory, String id) throws LdapException {
    Set<? extends Partition> partitions = directory.getPartitions();
    for (Partition part : partitions) {
        if (part.getId().equalsIgnoreCase(id)) return part;
    }
    throw new LdapException("No partition with the ID " + id);
}
 
Example #20
Source File: LDAPIAMPoller.java    From aws-iam-ldap-bridge with Apache License 2.0 5 votes vote down vote up
public LDAPIAMPoller(DirectoryService directoryService) throws LdapException {
    this.directory = directoryService;

    credentials = new DefaultAWSCredentialsProviderChain();
    try {
        credentials.getCredentials(); // throws
    } catch (AmazonClientException ex) {
        LOG.error("AWS credentials error", ex);
        throw new LdapException("Unable to initialze AWS poller - cannot retrieve valid credentials");
    }
    utils = new ApacheDSUtils(directory);
    runner = new Runner(directory);
    LOG.info("IAMPoller created");
}
 
Example #21
Source File: LDAPEmbeddedServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static void importLdifContent(DirectoryService directoryService, String ldifContent) throws Exception {
    LdifReader ldifReader = new LdifReader(IOUtils.toInputStream(ldifContent));

    try {
        for (LdifEntry ldifEntry : ldifReader) {
            try {
                directoryService.getAdminSession().add(new DefaultEntry(directoryService.getSchemaManager(), ldifEntry.getEntry()));
            } catch (LdapEntryAlreadyExistsException ignore) {
                log.info("Entry " + ldifEntry.getDn() + " already exists. Ignoring.");
            }
        }
    } finally {
        ldifReader.close();
    }
}
 
Example #22
Source File: SpliceTestKDCPlatform.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public void startLdapServer(MiniKdc miniKdc) throws Exception {
    ldapServer = new LdapServer();
    Field f = MiniKdc.class.getDeclaredField("ds");
    f.setAccessible(true);
    DirectoryService ds = (DirectoryService) f.get(miniKdc);
    ldapServer.setDirectoryService(ds);
    TcpTransport tcpTransport = new TcpTransport(4016);
    ldapServer.setTransports(tcpTransport);
    LOG.info(ds.getAdminSession().getAuthenticatedPrincipal().getDn());
    ldapServer.start();
}
 
Example #23
Source File: DirectoryServiceBuilder.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public DirectoryService getDirectoryService() {
    return directoryService;
}
 
Example #24
Source File: InMemoryDirectoryServiceFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private WrapperDirectoryService(DirectoryService wrapped, CacheManager cacheManager) {
    this.wrapped = wrapped;
    this.cacheManager = cacheManager;
}
 
Example #25
Source File: InMemoryDirectoryServiceFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DirectoryService getDirectoryService() throws Exception {
    return cacheManager != null ? new WrapperDirectoryService(directoryService, cacheManager) : directoryService;
}
 
Example #26
Source File: InMemoryDirectoryServiceFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private WrapperDirectoryService(DirectoryService wrapped, CacheManager cacheManager) {
    this.wrapped = wrapped;
    this.cacheManager = cacheManager;
}
 
Example #27
Source File: InMemoryDirectoryServiceFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private WrapperDirectoryService(DirectoryService wrapped, CacheManager cacheManager) {
    this.wrapped = wrapped;
    this.cacheManager = cacheManager;
}
 
Example #28
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public DefaultOperationManager( DirectoryService directoryService )
{
    this.directoryService = directoryService;
}
 
Example #29
Source File: EmbeddedLdapServer.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public DirectoryService getDirectoryService() {
    return _directoryService;
}
 
Example #30
Source File: InMemoryDirectoryServiceFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DirectoryService getDirectoryService() throws Exception {
    return cacheManager != null ? new WrapperDirectoryService(directoryService, cacheManager) : directoryService;
}