Package javax.naming.directory

Examples of javax.naming.directory.InitialDirContext


        DirContext ctx = null;
       
        // Create the initial context
        try
        {
            ctx = new InitialDirContext(env);
        }
        catch ( NamingException ne )
        {
            fail();
        }
View Full Code Here


        env.put(Context.SECURITY_CREDENTIALS, "");

        // Create the initial context
        try
        {
            new InitialDirContext(env);
        }
        catch ( OperationNotSupportedException onse )
        {
            assertEquals( "Cannot Bind for DN uid=admin,ou=system", onse.getMessage() );
        }
View Full Code Here

        env.put(Context.SECURITY_CREDENTIALS, "secret");

        // Create the initial context
        try
        {
            new InitialDirContext(env);
        }
        catch ( LdapNameNotFoundException lnnfe )
        {
            assertTrue( true );
        }
View Full Code Here

        Hashtable<String,Object> env = new Hashtable<String, Object>();
        env.put( DirectoryService.JNDI_KEY, service );
        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
        env.put( Context.PROVIDER_URL, "ou=system" );

        DirContext ctx = new InitialDirContext( env );

        ctx.createSubcontext( rdn, attrs );

        // Add the first value for description
        String description1 = "an American singer-songwriter";
        Attribute firstDescr = new BasicAttribute( "description", description1 );
        ModificationItem modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, firstDescr);
        ctx.modifyAttributes(rdn, new ModificationItem[] { modification });

        // Add a second value to description
        String description2 = "Grammy award winning";
        Attribute otherDescr = new BasicAttribute( "description", description2 );

        modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, otherDescr );
        ctx.modifyAttributes(rdn, new ModificationItem[] { modification } );
     
        // Add a third value to description
        String description3 = "MTV Music Award winning";
        Attribute thirdDescr = new BasicAttribute( "description", description3 );

        modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, thirdDescr );
        ctx.modifyAttributes(rdn, new ModificationItem[] { modification });

        // Search Entry
        SearchControls sctls = new SearchControls();
        sctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
        String filter = '(' + rdn + ')';
        String base = "";

        // Check entry
        NamingEnumeration<SearchResult> enm = ctx.search(base, filter, sctls);
        assertTrue(enm.hasMore());

        while (enm.hasMore())
        {
            SearchResult sr = enm.next();
            Attribute desc = sr.getAttributes().get("description");
            assertNotNull(desc);
            assertTrue(desc.contains(description1));
            assertTrue(desc.contains(description2));
            assertTrue(desc.contains(description3));
            assertEquals(3, desc.size());
        }

        // Remove the person entry
        ctx.destroySubcontext(rdn);
    }
View Full Code Here

        createData();
        Hashtable<String, Object> env = new Hashtable<String, Object>();
        env.put( DirectoryService.JNDI_KEY, service );
        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
        env.put( Context.PROVIDER_URL, "ou=system" );
        DirContext ctx = new InitialDirContext( env );

        // remove "cn=aaa", which is not part of the RDN
        Attribute attr = new BasicAttribute( "cn", "aaa" );
        ModificationItem modification = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
        ctx.modifyAttributes( "cn=test", new ModificationItem[]
            { modification } );

        Attributes attrs = ctx.getAttributes( "cn=test", new String[]
            { "cn" } );
        Attribute cn = attrs.get( "cn" );

        // cn=aaa must be removed, cn=test must exist
        assertEquals( "number of cn values", 1, cn.size() );
View Full Code Here

        createData();
        Hashtable<String, Object> env = new Hashtable<String, Object>();
        env.put( DirectoryService.JNDI_KEY, service );
        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
        env.put( Context.PROVIDER_URL, "ou=system" );
        DirContext ctx = new InitialDirContext( env );

        // replace cn attribute with "cn=test", must remove the previous "cn=aaa"
        Attribute attr = new BasicAttribute( "cn", "test" );
        ModificationItem modification = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
        ctx.modifyAttributes( "cn=test", new ModificationItem[]
            { modification } );

        Attributes attrs = ctx.getAttributes( "cn=test", new String[]
            { "cn" } );
        Attribute cn = attrs.get( "cn" );

        // cn=aaa must be removed, cn=test must exist
        assertEquals( "number of cn values", 1, cn.size() );
View Full Code Here

        createData();
        Hashtable<String, Object> env = new Hashtable<String, Object>();
        env.put( DirectoryService.JNDI_KEY, service );
        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
        env.put( Context.PROVIDER_URL, "ou=system" );
        DirContext ctx = new InitialDirContext( env );

        // try to add an non-existing objectClass "test", must be rejected
        Attribute attr = new BasicAttribute( "objectclass", "test" );
        ModificationItem modification = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
        try
        {
            ctx.modifyAttributes( "cn=test", new ModificationItem[]
                { modification } );
            fail( "Exception expected" );
        }
        catch ( SchemaViolationException sve )
        {
            // Valid behavior
        }
        catch ( InvalidAttributeValueException iave )
        {
            // Valid behavior
        }
        catch ( NamingException ne )
        {
            // Valid behavior
        }

        // re-read the entry, the non-existing objectClass "test" must not be present
        Attributes attrs = ctx.getAttributes( "cn=test", new String[]
            { "objectClass" } );
        Attribute ocls = attrs.get( "objectClass" );
        assertEquals( "number of objectClasses", 4, ocls.size() );
        assertTrue( ocls.contains( "top" ) );
        assertTrue( ocls.contains( "person" ) );
View Full Code Here

        createData();
        Hashtable<String, Object> env = new Hashtable<String, Object>();
        env.put( DirectoryService.JNDI_KEY, service );
        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
        env.put( Context.PROVIDER_URL, "ou=system" );
        DirContext ctx = new InitialDirContext( env );

        // try to add an unallowed attribute, must be rejected
        Attribute attr = new BasicAttribute( "javaDoc", "test" );
        ModificationItem modification = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
        try
        {
            ctx.modifyAttributes( "cn=test", new ModificationItem[]
                { modification } );
            fail( "Exception expected" );
        }
        catch ( SchemaViolationException sve )
        {
View Full Code Here

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

        ctx = new InitialDirContext( env );

        attrs = getOrgUnitAttributes( "users" );
        DirContext users = ctx.createSubcontext( "ou=users", attrs );

        attrs = getPrincipalAttributes( "Nelson", "Horatio Nelson", "hnelson", "secret", "hnelson@EXAMPLE.COM" );
View Full Code Here

                    env.put( "javax.security.sasl.server.authentication", "true" );

                    // Request high-strength cryptographic protection
                    env.put( "javax.security.sasl.strength", "high" );

                    DirContext ctx = new InitialDirContext( env );

                    String[] attrIDs =
                        { "uid" };

                    Attributes attrs = ctx.getAttributes( "uid=hnelson,ou=users,dc=example,dc=com", attrIDs );

                    String uid = null;

                    if ( attrs.get( "uid" ) != null )
                    {
View Full Code Here

TOP

Related Classes of javax.naming.directory.InitialDirContext

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.