Package org.apache.directory.server.core

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


       
        byte[] credential = getCredential( env );
        String authentication = getAuthentication( env );
        String providerUrl = getProviderUrl( env );

        DirectoryService service = ( DirectoryService ) env.get( DirectoryService.JNDI_KEY );

        if ( service == null )
        {
            throw new ConfigurationException( I18n.err( I18n.ERR_477, env ) );
        }

        if ( ! service.isStarted() )
        {
            return new DeadContext();
        }

        ServerLdapContext ctx = null;
        try
        {
            CoreSession session = service.getSession( principalDn, credential );
            ctx = new ServerLdapContext( service, session, new LdapName( providerUrl ) );
        }
        catch ( Exception e )
        {
            JndiUtils.wrap( e );
View Full Code Here


        }
        else
        {
            LOG.info( "server: using default settings ..." );
            DefaultDirectoryServiceFactory.DEFAULT.init( "default" );
            DirectoryService directoryService = DefaultDirectoryServiceFactory.DEFAULT.getDirectoryService();
            directoryService.startup();
            ldapServer = new LdapServer();
            ldapServer.setDirectoryService( directoryService );
            TcpTransport tcpTransportSsl = new TcpTransport( 10636 );
            tcpTransportSsl.enableSSL( true );
            ldapServer.setTransports( new TcpTransport( 10389 ), tcpTransportSsl );
View Full Code Here

        ClonedServerEntry dsEntry = configPartition.lookup( forwardEntry.getId() );

        LOG.debug( "directory service entry {}", dsEntry );

        DirectoryService dirService = new DefaultDirectoryService();
        // MUST attributes
        dirService.setInstanceId( getString( "ads-directoryServiceId", dsEntry ) );
        dirService.setReplicaId( getInt( "ads-dsReplicaId", dsEntry ) );

        DN interceptorsDN = new DN( dsEntry.get( "ads-dsInterceptors" ).getString() );
        interceptorsDN.normalize( configPartition.getSchemaManager().getNormalizerMapping() );
        List<Interceptor> interceptors = getInterceptors( interceptorsDN );
        dirService.setInterceptors( interceptors );

        DN partitionsDN = new DN( dsEntry.get( "ads-dsPartitions" ).getString() );
        partitionsDN.normalize( configPartition.getSchemaManager().getNormalizerMapping() );

        Map<String, Partition> partitions = getPartitions( partitionsDN );

        Partition systemPartition = partitions.remove( "system" );

        if ( systemPartition == null )
        {
            throw new Exception( I18n.err( I18n.ERR_505 ) );
        }

        dirService.setSystemPartition( systemPartition );
        dirService.setPartitions( new HashSet<Partition>( partitions.values() ) );

        // MAY attributes
        EntryAttribute acEnabledAttr = dsEntry.get( "ads-dsAccessControlEnabled" );

        if ( acEnabledAttr != null )
        {
            dirService.setAccessControlEnabled( Boolean.parseBoolean( acEnabledAttr.getString() ) );
        }

        EntryAttribute anonAccessAttr = dsEntry.get( "ads-dsAllowAnonymousAccess" );

        if ( anonAccessAttr != null )
        {
            dirService.setAllowAnonymousAccess( Boolean.parseBoolean( anonAccessAttr.getString() ) );
        }

        EntryAttribute changeLogAttr = dsEntry.get( "ads-dsChangeLog" );

        if ( changeLogAttr != null )
        {
            DN clDN = new DN( changeLogAttr.getString() );
            clDN.normalize( schemaManager.getNormalizerMapping() );
            ChangeLog cl = getChangeLog( clDN );
            dirService.setChangeLog( cl );
        }

        EntryAttribute denormAttr = dsEntry.get( "ads-dsDenormalizeOpAttrsEnabled" );

        if ( denormAttr != null )
        {
            dirService.setDenormalizeOpAttrsEnabled( Boolean.parseBoolean( denormAttr.getString() ) );
        }

        EntryAttribute journalAttr = dsEntry.get( "ads-dsJournal" );

        if ( journalAttr != null )
        {
            DN journalDN = new DN( journalAttr.getString() );
            journalDN.normalize( schemaManager.getNormalizerMapping() );
            dirService.setJournal( getJournal( journalDN ) );
        }

        EntryAttribute maxPduAttr = dsEntry.get( "ads-dsMaxPDUSize" );

        if ( maxPduAttr != null )
        {
            dirService.setMaxPDUSize( Integer.parseInt( maxPduAttr.getString() ) );
        }

        EntryAttribute passwordHidAttr = dsEntry.get( "ads-dsPasswordHidden" );

        if ( passwordHidAttr != null )
        {
            dirService.setPasswordHidden( Boolean.parseBoolean( passwordHidAttr.getString() ) );
        }

        EntryAttribute replAttr = dsEntry.get( "ads-dsReplication" );

        if ( replAttr != null )
        {
            // configure replication
        }

        EntryAttribute syncPeriodAttr = dsEntry.get( "ads-dsSyncPeriodMillis" );

        if ( syncPeriodAttr != null )
        {
            // FIXME the DirectoryService interface doesn't have this setter
            //dirService.setSyncPeriodMillis( Long.parseLong( syncPeriodAttr.getString() ) );
        }

        EntryAttribute testEntryAttr = dsEntry.get( "ads-dsTestEntries" );

        if ( testEntryAttr != null )
        {
            String entryFilePath = testEntryAttr.getString();
            dirService.setTestEntries( getTestEntries( entryFilePath ) );
        }

        if ( !isEnabled( dsEntry ) )
        {
            // will only be useful if we ever allow more than one DS to be configured and
View Full Code Here

        if ( !schemaDirectory.exists() )
        {
            throw new LdapConfigurationException( I18n.err( I18n.ERR_697, schemaDirectory ) );
        }

        DirectoryService directoryService = new DefaultDirectoryService();
        //schemaPartition.init( directoryService );

        // --------------------------------------------------------------------
        // Initialize schema subsystem and reset registries
        // --------------------------------------------------------------------
View Full Code Here

     */
    public void go() throws Exception
    {
        LOG.debug( "Starting the DNS server" );
       
        DirectoryService directoryService = new DefaultDirectoryService();
        dnsConfiguration = new DnsServer();
        dnsConfiguration.setDirectoryService( directoryService );
        dnsConfiguration.setEnabled( true );
        dnsConfiguration.setTransports( new TcpTransport( 10053 ), new UdpTransport( 10053 ) );
        dnsConfiguration.start();
View Full Code Here

   

    @Test
    public void testCreateDS() throws Exception
    {
        DirectoryService service = DSAnnotationProcessor.getDirectoryService();
       
        assertTrue( service.isStarted() );
        assertEquals( "classDS", service.getInstanceId() );
       
        service.shutdown();
        FileUtils.deleteDirectory( service.getWorkingDirectory() );
    }
View Full Code Here

    @Test
    @CreateDS( name = "methodDS" )
    public void testCreateMethodDS() throws Exception
    {
        DirectoryService service = DSAnnotationProcessor.getDirectoryService();
       
        assertTrue( service.isStarted() );
        assertEquals( "methodDS", service.getInstanceId() );
       
        service.shutdown();
        FileUtils.deleteDirectory( service.getWorkingDirectory() );
    }
View Full Code Here

                    @CreateIndex( attribute = "ou" )
                } )
        } )
    public void testCreateMethodDSWithPartition() throws Exception
    {
        DirectoryService service = DSAnnotationProcessor.getDirectoryService();
       
        assertTrue( service.isStarted() );
        assertEquals( "MethodDSWithPartition", service.getInstanceId() );
       
        Set<String> expectedNames = new HashSet<String>();
       
        expectedNames.add( "example" );
        expectedNames.add( "schema" );
       
        assertEquals( 2, service.getPartitions().size() );
       
        for ( Partition partition : service.getPartitions() )
        {
            assertTrue( expectedNames.contains( partition.getId() ) );
           
            if ( "example".equalsIgnoreCase( partition.getId() ) )
            {
                assertTrue( partition.isInitialized() );
                assertEquals( "dc=example,dc=com", partition.getSuffixDn().getName() );
            }
            else if ( "schema".equalsIgnoreCase( partition.getId() ) )
            {
                assertTrue( partition.isInitialized() );
                assertEquals( "ou=schema", partition.getSuffixDn().getName() );
            }
        }
       
        assertTrue( service.getAdminSession().exists( new DN( "dc=example,dc=com" ) ) );

        service.shutdown();
        FileUtils.deleteDirectory( service.getWorkingDirectory() );
    }
View Full Code Here

            @CreateTransport( protocol = "LDAPS" )
        })
    public void testCreateLdapServer() throws Exception
    {
        // First, get the service
        DirectoryService service = DSAnnotationProcessor.getDirectoryService();
       
        // Check that the service is running
        assertTrue( service.isStarted() );
        assertEquals( "MethodDSWithPartitionAndServer", service.getInstanceId() );
       
       
        Set<String> expectedNames = new HashSet<String>();
       
        expectedNames.add( "example" );
        expectedNames.add( "schema" );
       
        assertEquals( 2, service.getPartitions().size() );
       
        for ( Partition partition : service.getPartitions() )
        {
            assertTrue( expectedNames.contains( partition.getId() ) );
           
            if ( "example".equalsIgnoreCase( partition.getId() ) )
            {
                assertTrue( partition.isInitialized() );
                assertEquals( "dc=example,dc=com", partition.getSuffixDn().getName() );
            }
            else if ( "schema".equalsIgnoreCase( partition.getId() ) )
            {
                assertTrue( partition.isInitialized() );
                assertEquals( "ou=schema", partition.getSuffixDn().getName() );
            }
        }
       
        assertTrue( service.getAdminSession().exists( new DN( "dc=example,dc=com" ) ) );

        // Now, get the server
        LdapServer ldapServer = ServerAnnotationProcessor.getLdapServer( service, 1024 );

        // Check that the server is running
        assertTrue( ldapServer.isStarted() );
       
        // Try to read an entry in the server
        LdapContext ctx = ( LdapContext ) getWiredContext( ldapServer, null ).lookup( "dc=example,dc=com" );
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
        controls.setReturningAttributes( new String[]{"*"} );
       
        NamingEnumeration<SearchResult> enumeration = ctx.search( "", "(objectClass=*)", controls );
       
        // collect all results
        HashSet<String> results = new HashSet<String>();
       
        while ( enumeration.hasMore() )
        {
            SearchResult result = enumeration.next();
            results.add( result.getNameInNamespace() );
        }
       
        assertEquals( 1, results.size() );
        assertTrue( results.contains( "dc=example,dc=com" ) );

        enumeration.close();
        ctx.close();
        ldapServer.stop();
        service.shutdown();
       
        FileUtils.deleteDirectory( service.getWorkingDirectory() );
    }
View Full Code Here

    private static boolean isSubSchemaSubEntrySearch( LdapSession session, InternalSearchRequest req ) throws Exception
    {
        DN base = req.getBase();
        String baseNormForm = ( base.isNormalized() ? base.getNormName() : base.toNormName() );

        DirectoryService ds = session.getCoreSession().getDirectoryService();
        PartitionNexus nexus = ds.getPartitionNexus();
        Value<?> subschemaSubentry = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
        DN subschemaSubentryDn = new DN( subschemaSubentry.getString() );
        subschemaSubentryDn.normalize( ds.getSchemaManager().getNormalizerMapping() );
        String subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();
       
        return subschemaSubentryDnNorm.equals( baseNormForm );
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.server.core.DirectoryService

Copyright © 2018 www.massapicom. 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.