Examples of DirectoryService


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

                LdapPrincipal ldapPrincipal = ( LdapPrincipal ) ldapSession
                    .getSaslProperty( SaslConstants.SASL_AUTHENT_USER );

                if ( ldapPrincipal != null )
                {
                    DirectoryService ds = ldapSession.getLdapServer().getDirectoryService();
                    String saslMechanism = bindRequest.getSaslMechanism();
                    byte[] password = null;

                    if ( ldapPrincipal.getUserPasswords() != null )
                    {
                        password = ldapPrincipal.getUserPasswords()[0];
                    }

                    CoreSession userSession = ds.getSession( ldapPrincipal.getDn(),
                        password, saslMechanism, null );

                    // Set the user session into the ldap session
                    ldapSession.setCoreSession( userSession );
View Full Code Here

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

     */
    private CoreSession authenticate( String user, String password ) throws InvalidNameException, Exception
    {
        LdapSession ldapSession = getLdapSession();
        CoreSession adminSession = getAdminSession();
        DirectoryService directoryService = adminSession.getDirectoryService();
        LdapServer ldapServer = ldapSession.getLdapServer();
        OperationManager operationManager = directoryService.getOperationManager();

        // first, we have to find the entries which has the uid value
        EqualityNode<String> filter = new EqualityNode<String>(
            directoryService.getSchemaManager().getAttributeType( SchemaConstants.UID_AT ), new StringValue( user ) );

        SearchOperationContext searchContext = new SearchOperationContext( directoryService.getAdminSession() );
        searchContext.setDn( directoryService.getDnFactory().create( ldapServer.getSearchBaseDn() ) );
        searchContext.setScope( SearchScope.SUBTREE );
        searchContext.setFilter( filter );
        searchContext.setNoAttributes( true );

        EntryFilteringCursor cursor = operationManager.search( searchContext );
        Exception bindException = new LdapAuthenticationException( "Cannot authenticate user uid=" + user );

        while ( cursor.next() )
        {
            Entry entry = cursor.get();

            try
            {
                BindOperationContext bindContext = new BindOperationContext( ldapSession.getCoreSession() );
                bindContext.setDn( entry.getDn() );
                bindContext.setCredentials( Strings.getBytesUtf8( password ) );
                bindContext.setIoSession( ldapSession.getIoSession() );
                bindContext.setInterceptors( directoryService.getInterceptors( OperationEnum.BIND ) );

                operationManager.bind( bindContext );

                cursor.close();

View Full Code Here

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

    {
        LdapResult result = req.getResultResponse().getLdapResult();
        Entry entry = null;
        boolean isReferral = false;
        boolean isparentReferral = false;
        DirectoryService directoryService = session.getCoreSession().getDirectoryService();
        ReferralManager referralManager = directoryService.getReferralManager();
        Dn reqTargetDn = req.getBase();

        reqTargetDn.apply( directoryService.getSchemaManager() );

        // Check if the entry itself is a referral
        referralManager.lockRead();

        try
View Full Code Here

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

    private boolean isSubSchemaSubEntrySearch( LdapSession session, SearchRequest req ) throws Exception
    {
        Dn base = req.getBase();
        String baseNormForm = ( base.isSchemaAware() ? base.getNormName() : base.getNormName() );

        DirectoryService ds = session.getCoreSession().getDirectoryService();
        PartitionNexus nexus = ds.getPartitionNexus();

        if ( SUBSCHEMA_SUBENTRY_AT == null )
        {
            SUBSCHEMA_SUBENTRY_AT = session.getCoreSession().getDirectoryService().getSchemaManager().getAttributeType(
                SchemaConstants.SUBSCHEMA_SUBENTRY_AT );
        }

        Value<?> subschemaSubentry = nexus.getRootDseValue( SUBSCHEMA_SUBENTRY_AT );
        Dn subschemaSubentryDn = ds.getDnFactory().create( subschemaSubentry.getString() );
        String subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();

        return subschemaSubentryDnNorm.equals( baseNormForm );
    }
View Full Code Here

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

    })
    @CreateLdapServer(transports =
        { @CreateTransport(port = 16000, protocol = "LDAP") })
    public static void startProvider() throws Exception
    {
        DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();

        providerServer = ServerAnnotationProcessor.getLdapServer( provDirService );

        providerServer.setReplicationReqHandler( new SyncReplRequestHandler() );
        providerServer.startReplicationProducer();
View Full Code Here

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

                    searchRequest.setScope( config.getSearchScope() );
                    searchRequest.setTypesOnly( false );

                    searchRequest.addAttributes( config.getAttributes() );

                    DirectoryService directoryService = new MockDirectoryService();
                    directoryService.setSchemaManager( schemaManager );
                    ( ( MockSyncReplConsumer ) syncreplClient ).init( directoryService );
                   
                    directoryService.setDnFactory( new DefaultDnFactory( schemaManager, null ) );
                    syncreplClient.connect( true );
                    syncreplClient.startSync();
                }
                catch ( Exception e )
                {
View Full Code Here

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

        LOG.debug( "Starting DS {}...", dsBuilder.name() );
        Class<?> factory = dsBuilder.factory();
        DirectoryServiceFactory dsf = ( DirectoryServiceFactory ) factory
            .newInstance();

        DirectoryService service = dsf.getDirectoryService();
        service.setAccessControlEnabled( dsBuilder.enableAccessControl() );
        service.setAllowAnonymousAccess( dsBuilder.allowAnonAccess() );
        service.getChangeLog().setEnabled( dsBuilder.enableChangeLog() );

        dsf.init( dsBuilder.name() );

        for ( Class<?> interceptorClass : dsBuilder.additionalInterceptors() )
        {
            service.addLast( ( Interceptor ) interceptorClass.newInstance() );
        }

        List<Interceptor> interceptorList = service.getInterceptors();

        if ( dsBuilder.authenticators().length != 0 )
        {
            AuthenticationInterceptor authenticationInterceptor = null;

            for ( Interceptor interceptor : interceptorList )
            {
                if ( interceptor instanceof AuthenticationInterceptor )
                {
                    authenticationInterceptor = ( AuthenticationInterceptor ) interceptor;
                    break;
                }
            }

            if ( authenticationInterceptor == null )
            {
                throw new IllegalStateException(
                    "authentication interceptor not found" );
            }

            Set<Authenticator> authenticators = new HashSet<Authenticator>();

            for ( CreateAuthenticator createAuthenticator : dsBuilder
                .authenticators() )
            {
                Authenticator auth = createAuthenticator.type().newInstance();

                if ( auth instanceof DelegatingAuthenticator )
                {
                    DelegatingAuthenticator dauth = ( DelegatingAuthenticator ) auth;
                    dauth.setDelegateHost( createAuthenticator.delegateHost() );
                    dauth.setDelegatePort( createAuthenticator.delegatePort() );
                    dauth.setDelegateSsl( createAuthenticator.delegateSsl() );
                    dauth.setDelegateTls( createAuthenticator.delegateTls() );
                    dauth.setDelegateBaseDn( createAuthenticator.delegateBaseDn() );
                    dauth.setDelegateSslTrustManagerFQCN( createAuthenticator.delegateSslTrustManagerFQCN() );
                    dauth.setDelegateTlsTrustManagerFQCN( createAuthenticator.delegateTlsTrustManagerFQCN() );
                }

                authenticators.add( auth );
            }

            authenticationInterceptor.setAuthenticators( authenticators );
            authenticationInterceptor.init( service );
        }

        service.setInterceptors( interceptorList );

        SchemaManager schemaManager = service.getSchemaManager();

        // process the schemas
        for ( LoadSchema loadedSchema : dsBuilder.loadedSchemas() )
        {
            String schemaName = loadedSchema.name();
            Boolean enabled = loadedSchema.enabled();

            // Check if the schema is loaded or not
            boolean isLoaded = schemaManager.isSchemaLoaded( schemaName );

            if ( !isLoaded )
            {
                // We have to load the schema, if it exists
                try
                {
                    isLoaded = schemaManager.load( schemaName );
                }
                catch ( LdapUnwillingToPerformException lutpe )
                {
                    // Cannot load the schema, it does not exists
                    LOG.error( lutpe.getMessage() );
                    continue;
                }
            }

            if ( isLoaded )
            {
                if ( enabled )
                {
                    schemaManager.enable( schemaName );

                    if ( schemaManager.isDisabled( schemaName ) )
                    {
                        LOG.error( "Cannot enable " + schemaName );
                    }
                }
                else
                {
                    schemaManager.disable( schemaName );

                    if ( schemaManager.isEnabled( schemaName ) )
                    {
                        LOG.error( "Cannot disable " + schemaName );
                    }
                }
            }

            LOG.debug( "Loading schema {}, enabled= {}", schemaName, enabled );
        }

        // Process the Partition, if any.
        for ( CreatePartition createPartition : dsBuilder.partitions() )
        {
            Partition partition;

            // Determine the partition type
            if ( createPartition.type() == Partition.class )
            {
                // The annotation does not specify a specific partition type.
                // We use the partition factory to create partition and index
                // instances.
                PartitionFactory partitionFactory = dsf.getPartitionFactory();
                partition = partitionFactory.createPartition(
                    schemaManager,
                    service.getDnFactory(),
                    createPartition.name(),
                    createPartition.suffix(),
                    createPartition.cacheSize(),
                    new File( service.getInstanceLayout().getPartitionsDirectory(), createPartition.name() ) );
               
                partition.setCacheService( service.getCacheService() );

                CreateIndex[] indexes = createPartition.indexes();

                for ( CreateIndex createIndex : indexes )
                {
                    partitionFactory.addIndex( partition,
                        createIndex.attribute(), createIndex.cacheSize() );
                }

                partition.initialize();
            }
            else
            {
                // The annotation contains a specific partition type, we use
                // that type.
                Class<?> partypes[] = new Class[]
                    { SchemaManager.class, DnFactory.class };
                Constructor<?> constructor = createPartition.type().getConstructor( partypes );
                partition = ( Partition ) constructor.newInstance( new Object[]
                    { schemaManager, service.getDnFactory() } );
                partition.setId( createPartition.name() );
                partition.setSuffixDn( new Dn( schemaManager, createPartition.suffix() ) );

                if ( partition instanceof AbstractBTreePartition )
                {
                    AbstractBTreePartition btreePartition = ( AbstractBTreePartition ) partition;
                    btreePartition.setCacheSize( createPartition.cacheSize() );
                    btreePartition.setPartitionPath( new File( service
                        .getInstanceLayout().getPartitionsDirectory(),
                        createPartition.name() ).toURI() );

                    // Process the indexes if any
                    CreateIndex[] indexes = createPartition.indexes();

                    for ( CreateIndex createIndex : indexes )
                    {
                        // The annotation does not specify a specific index
                        // type.
                        // We use the generic index implementation.
                        JdbmIndex index = new JdbmIndex( createIndex.attribute(), false );

                        btreePartition.addIndexedAttributes( index );
                    }
                }
            }

            partition.setSchemaManager( schemaManager );

            // Inject the partition into the DirectoryService
            service.addPartition( partition );

            // Last, process the context entry
            ContextEntry contextEntry = createPartition.contextEntry();

            if ( contextEntry != null )
View Full Code Here

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

        })
    @CreateLdapServer(transports =
        { @CreateTransport(port = 16000, protocol = "LDAP") })
    public static void startProvider( final CountDownLatch counter ) throws Exception
    {
        DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();

        providerServer = ServerAnnotationProcessor.getLdapServer( provDirService );
        providerServer.setReplicationReqHandler( new SyncReplRequestHandler() );
        providerServer.startReplicationProducer();
View Full Code Here

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

            refreshInterval = 1000,
            replicaId = 1
        )
        public static void startConsumer( final CountDownLatch counter ) throws Exception
    {
        DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();
        consumerServer = ServerAnnotationProcessor.getLdapServer( provDirService );

        final ReplicationConsumerImpl consumer = ( ReplicationConsumerImpl ) ServerAnnotationProcessor.createConsumer();

        List<ReplicationConsumer> replConsumers = new ArrayList<ReplicationConsumer>();
        replConsumers.add( consumer );

        consumerServer.setReplConsumers( replConsumers );

        Runnable r = new Runnable()
        {
            public void run()
            {
                try
                {
                    DirectoryService ds = consumerServer.getDirectoryService();

                    Dn configDn = new Dn( ds.getSchemaManager(), "ads-replConsumerId=localhost,ou=system" );
                    consumer.getConfig().setConfigEntryDn( configDn );

                    Entry provConfigEntry = new DefaultEntry( ds.getSchemaManager(), configDn,
                        "objectClass: ads-replConsumer",
                        "ads-replConsumerId: localhost",
                        "ads-searchBaseDN", consumer.getConfig().getBaseDn(),
                        "ads-replProvHostName", consumer.getConfig().getRemoteHost(),
                        "ads-replProvPort", String.valueOf( consumer.getConfig().getRemotePort() ),
View Full Code Here

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

    })
    @CreateLdapServer(transports =
        { @CreateTransport(port = 16000, protocol = "LDAP") })
    public static void startProvider() throws Exception
    {
        DirectoryService provDirService = DSAnnotationProcessor.getDirectoryService();

        providerServer = ServerAnnotationProcessor.getLdapServer( provDirService );

        providerServer.setReplicationReqHandler( new SyncReplRequestHandler() );
        providerServer.startReplicationProducer();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.