Package org.apache.directory.server.core.jndi

Examples of org.apache.directory.server.core.jndi.ServerLdapContext


    @Test
    public void testSMD5() throws Exception
    {
        apply( service, getUserAddLdif() );
        String userDn = "uid=akarasulu,ou=users,ou=system";
        LdapContext ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );

        // Check that we can get the attributes
        Attributes attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // now modify the password for akarasulu : 'secret', encrypted using SMD5
        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
        ctx.modifyAttributes( "", new ModificationItem[] {
            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );

        // close and try with old password (should fail)
        ctx.close();

        try
        {
            ctx = new ServerLdapContext( service,
                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
            fail( "Authentication with old password should fail" );
        }
        catch ( Exception e )
        {
            // we should fail
        }
        finally
        {
            if ( ctx != null )
            {
                ctx.close();
            }
        }

        // try again now with new password (should be successful)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // try again now with new password, to check that the
        // cache is updated (should be successfull)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
    }
View Full Code Here


    @Test
    public void testCRYPT() throws Exception
    {
        apply( service, getUserAddLdif() );
        String userDn = "uid=akarasulu,ou=users,ou=system";
        LdapContext ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );

        // Check that we can get the attributes
        Attributes attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // now modify the password for akarasulu : 'secret', encrypted using CRYPT
        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "{crypt}qFkH8Z1woBlXw" );
        ctx.modifyAttributes( "", new ModificationItem[] {
            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );

        // close and try with old password (should fail)
        ctx.close();

        try
        {
            ctx = new ServerLdapContext( service,
                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
            fail( "Authentication with old password should fail" );
        }
        catch ( Exception e )
        {
            // we should fail
        }
        finally
        {
            if ( ctx != null )
            {
                ctx.close();
            }
        }

        // try again now with new password (should be successfull)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );

        // try again now with new password, to check that the
        // cache is updated (should be successfull)
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );
        attrs = ctx.getAttributes( "" );
        assertNotNull( attrs );
        assertTrue( attrs.get( "uid" ).contains( "akarasulu" ) );
    }
View Full Code Here

    {
        apply( service, getUserAddLdif() );

        // bind as akarasulu
        String userDn = "uid=akarasulu,ou=users,ou=system";
        LdapContext ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
        ctx.close();

        // bind as admin
        userDn = "uid=admin,ou=system";
        ctx = new ServerLdapContext( service,
            service.getSession( new DN( userDn ), "secret".getBytes() ), new DN( userDn ) );

        // now modify the password for akarasulu (while we're admin)
        Attribute userPasswordAttribute = new BasicAttribute( "userPassword", "newpwd" );
        ctx.modifyAttributes( "", new ModificationItem[] {
            new ModificationItem( DirContext.REPLACE_ATTRIBUTE, userPasswordAttribute ) } );
        ctx.close();

        try
        {
            ctx = new ServerLdapContext( service,
                service.getSession( new DN( userDn ), "test".getBytes() ), new DN( userDn ) );
            fail( "Authentication with old password should fail" );
        }
        catch ( Exception e )
        {
            // we should fail
        }
        finally
        {
            if ( ctx != null )
            {
                ctx.close();
            }
        }
    }
View Full Code Here

        {
            dn = "";
        }
       
        CoreSession session = service.getSession( principal );
        LdapContext ctx = new ServerLdapContext( service, session, new DN( dn ) );
        return ctx;
    }
View Full Code Here

        try
        {
            GetRecords getRecords = new GetRecords( question );
            String baseDn = catalog.getBaseDn( question.getDomainName() );
            CoreSession session = directoryService.getSession();
            DirContext dirContext = new ServerLdapContext( directoryService, session, new LdapName( baseDn ) );
            return getRecords.execute( dirContext, null );
        }
        catch ( LdapNoSuchObjectException lnnfe )
        {
            LOG.debug( "Name for DNS record search does not exist.", lnnfe );
View Full Code Here

        {
            dn = "";
        }

        CoreSession session = service.getSession( principal );
        LdapContext ctx = new ServerLdapContext( service, session, new LdapName( dn ) );
        return ctx;
    }
View Full Code Here

    public void testLdapClassLoaderWithClassLoadedAnywhere() throws Exception
    {
        LdapContext root = getRootContext( getService() );

        // get default naming context to work on
        ServerLdapContext defaultContext = ( ServerLdapContext ) root.lookup( "ou=system" );

        // set up
        Attributes attributes = new BasicAttributes( "objectClass", "top", true );
        attributes.get( "objectClass" ).add( "javaClass" );
        attributes.put( "fullyQualifiedJavaClassName", "HelloWorld" );
        attributes.put( "javaClassByteCode", HELLOWORLD_CLASS_BYTES );
        defaultContext.createSubcontext( "fullyQualifiedJavaClassName=HelloWorld", attributes );

        // assert set up successfull
        assertNotNull( defaultContext.lookup( "fullyQualifiedJavaClassName=HelloWorld" ) );

        // load the class
        LdapClassLoader loader = new LdapClassLoader( getService() );
        Class<?> clazz = loader.loadClass( "HelloWorld" );
View Full Code Here

    public void testLdapClassLoaderWithClassLoadedAtDefaultSearchSubtree() throws Exception
    {
        LdapContext root = getRootContext( getService() );

        // get default naming context to work on
        ServerLdapContext defaultContext = ( ServerLdapContext ) root.lookup( "ou=system" );

        // create an extensible object for holding custom config data
        Attributes classLoaderDefaultSearchContextConfig = new BasicAttributes( true );
        Attribute objectClass = new BasicAttribute( "objectClass" );
        objectClass.add( "top" );
        objectClass.add( "javaContainer" );

        // We need to ad this extensibleObject OC in order to avoid an error
        // with the classLoaderDefaultSearchContext AT used later (no OC contains
        // this AT)
        objectClass.add( "extensibleObject" );

        // create custom config entry
        classLoaderDefaultSearchContextConfig.put( objectClass );
        classLoaderDefaultSearchContextConfig.put( new BasicAttribute( "cn", "classLoaderDefaultSearchContext" ) );

        // add a default search context to the configuration
        classLoaderDefaultSearchContextConfig
            .put( new BasicAttribute( "classLoaderDefaultSearchContext", "ou=system" ) );

        // add the configuration entry to the DIT
        ServerLdapContext configContext = ( ServerLdapContext ) defaultContext.lookup( "ou=configuration" );
        configContext.createSubcontext( "cn=classLoaderDefaultSearchContext", classLoaderDefaultSearchContextConfig );

        // create a class holder entry and add it to the DIT
        Attributes attributes = new BasicAttributes( "objectClass", "top", true );
        attributes.get( "objectClass" ).add( "javaClass" );
        attributes.put( "fullyQualifiedJavaClassName", "HelloWorld" );
View Full Code Here

        {
            dn = "";
        }

        CoreSession session = service.getSession( principal );
        LdapContext ctx = new ServerLdapContext( service, session, new LdapName( dn ) );
        return ctx;
    }
View Full Code Here

        {
            dn = "";
        }

        CoreSession session = service.getSession( principal );
        LdapContext ctx = new ServerLdapContext( service, session, new LdapName( dn ) );
        return ctx;
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.server.core.jndi.ServerLdapContext

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.