Java 8 LdapContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 LdapContext class.

This code example shows how to use the following methods:lookup, createSubcontext
        attribute.add( "top" );
        attribute.add( "organizationalUnit" );
        attributes.put( attribute );
        attributes.put( "ou", "testing00" );
 
        DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
        assertNotNull( ctx );
 
        ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
        assertNotNull( ctx );
        attributes = ctx.getAttributes( "" );
        assertNotNull( attributes );
        assertEquals( "testing00", attributes.get( "ou" ).get() );
        attribute = attributes.get( "objectClass" );
        assertNotNull( attribute );
        assertTrue( attribute.contains( "top" ) );
        assertTrue( attribute.contains( "organizationalUnit" ) );
 
        /* 
         * create ou=testing01,ou=system 

5
CodeRank
This code example shows how to use the following methods:lookup, createSubcontext
        Attribute attribute = new BasicAttribute( "objectClass" );
        attribute.add( "top" );
        attribute.add( "organizationalUnit" );
        attributes.put( attribute );
        attributes.put( "ou", "testing00" );
        DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
        assertNotNull( ctx );
 
        ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
        assertNotNull( ctx );
 
        attributes = ctx.getAttributes( "" );
        assertNotNull( attributes );
        assertEquals( "testing00", attributes.get( "ou" ).get() );
        attribute = attributes.get( "objectClass" );
        assertNotNull( attribute );
        assertTrue( attribute.contains( "top" ) );
        assertTrue( attribute.contains( "organizationalUnit" ) );
 
        /* 

5
CodeRank
This code example shows how to use the following methods:lookup, createSubcontext, getAttributes
    public void createData( LdapContext ctx ) throws NamingExceptionAttributes spContainer = new BasicAttributes( "objectClass", "top", true );
        spContainer.get( "objectClass" ).add( "organizationalUnit" );
        spContainer.put( "ou", "Stored Procedures" );
        spCtx = ( LdapContext ) ctx.createSubcontext( "ou=Stored Procedures", spContainer );
    } 
 
 
    @Test
    public void testAfterDeleteBackupDeletedEntryEntryTrigger() throws ExceptionString ldif =
            "version: 1\n" + 
                "\n" + 
                "dn: ou=backupContext, ou=system\n" + 
                "objectClass: top\n" + 
                "objectClass: organizationalUnit\n" + 
                "ou: backupContext\n" + 
                "\n" + 

5
CodeRank
This code example shows how to use the following methods:addToEnvironment
 */ 
public class DefaultTlsDirContextAuthenticationStrategy extends AbstractTlsDirContextAuthenticationStrategy { 
	private static final String SIMPLE_AUTHENTICATION = "simple";
 
	protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
		ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION);
		ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
		ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:lookup, createSubcontext
        Attribute attribute = new BasicAttribute( "objectClass" );
        attribute.add( "top" );
        attribute.add( "organizationalUnit" );
        attributes.put( attribute );
        attributes.put( "ou", "testing00" );
        DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
        assertNotNull( ctx );
 
        ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
        assertNotNull( ctx );
 
        attributes = ctx.getAttributes( "" );
        assertNotNull( attributes );
        assertEquals( "testing00", attributes.get( "ou" ).get() );
        attribute = attributes.get( "objectClass" );
        assertNotNull( attribute );
        assertTrue( attribute.contains( "top" ) );
        assertTrue( attribute.contains( "organizationalUnit" ) );
 
        /* 

5
CodeRank
This code example shows how to use the following methods:close, search
        SearchControls controls = new SearchControls();
        controls.setReturningAttributes( new String[0] );
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
 
        // comparison success 
        NamingEnumeration<SearchResult> answer = ctx.search( "uid=akarasulu,ou=users,ou=system", "(uid=akarasulu)",
            controls );
        assertTrue( answer.hasMore() );
        SearchResult result = answer.next();
        assertEquals( "", result.getName() );
        assertEquals( 0, result.getAttributes().size() );
        assertFalse( answer.hasMore() );
        answer.close();
 
        // referrals failure 
        try 
        { 
            answer = ctx.search( "uid=akarasuluref,ou=users,ou=system", "(uid=akarasuluref)", controls );
            fail( "Should never get here" ); 
        } 

4
CodeRank
This code example shows how to use the following methods:destroySubcontext, createSubcontext, search
        String dn = "ou=Test";
 
        Attributes attributes = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: organizationalUnit",
            "ou: Test" ); 
 
        DirContext ctx = ctxRoot.createSubcontext( dn, attributes );
        assertNotNull( ctx );
 
        ctxRoot.destroySubcontext( dn );
 
        SearchControls sc = new SearchControls();
        sc.setSearchScope( SearchControls.OBJECT_SCOPE );
 
        try 
        { 
            ctxRoot.search( dn, "(objectClass=*)", sc );
            fail( "Search should throw exception." ); 
        } 
        catch ( NamingException e )
        { 
            // ignore 
4
CodeRank
This code example shows how to use the following methods:close, rename, search
 
    @Test
    public void testMoveNoRdnChange() throws ExceptionLdapContext ctx = getWiredContext( getLdapServer() );
        ctx.rename( DN, NEW_DN );
 
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
 
        NamingEnumeration<SearchResult> results = ctx.search( NEW_DN, "(objectClass=*)", controls );
        assertNotNull( results );
        assertTrue( "Could not find entry after move.", results.hasMore() );
        SearchResult result = results.next();
        assertNotNull( result );
        assertEquals( NEW_DN, result.getNameInNamespace() );
 
        results.close();
        ctx.close();
    } 

4
CodeRank
This code example shows how to use the following methods:addToEnvironment, lookup, rename
     * Test a rename of an existing referral, using JNDI ignore.  
     */ 
    @Test
    public void testRenameExistingReferralJNDIIgnore() throws ExceptionMNNCtx.addToEnvironment( DirContext.REFERRAL, "ignore" );
 
        // First check that the object exists 
        Object renamed = MNNCtx.lookup( "ou=Roles" );
        assertNotNull( renamed ); 
 
        // Also check that the new entry does not exist 
        try 
        { 
            renamed = MNNCtx.lookup( "ou=Groups" );
            fail(); 
        } 
        catch ( NameNotFoundException nnfe )
        { 
            assertTrue( true ); 

5
CodeRank
This code example shows how to use the following methods:getResponseControls
 
        byte[] value = encodeValue(sortResult);
        SortResponseControl control = new SortResponseControl(
                "dummy", true, value);
 
        when(ldapContextMock.getResponseControls()).thenReturn( new Control[]{control});
 
        tested.postProcess(ldapContextMock);
 
        assertEquals(true, tested.isSorted());
        assertEquals(0, tested.getResultCode());
    } 
 
    @Test
    public void testPostProcess_NonSuccess() throws Exception {
        byte sortResult = 1;
 
        byte[] value = encodeValue(sortResult);
        SortResponseControl control = new SortResponseControl(
                "dummy", true, value);
4
CodeRank
See Code Examples for Java 8 LdapContext Methods: