Package javax.naming.directory

Examples of javax.naming.directory.DirContext


     * Test a search done on cn=schema
     */
    @Test
    public void testSubSchemaSubEntrySearch() throws Exception
    {
        DirContext ctx = getWiredContext( getLdapServer() );

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
        searchControls.setReturningAttributes( new String[]
            { "objectClasses" } );
        NamingEnumeration<SearchResult> results = ctx.search( "cn=schema", "(ObjectClass=*)", searchControls );

        assertTrue( results.hasMore() );
        SearchResult result = results.next();
        Attributes entry = result.getAttributes();

View Full Code Here


     * "c=usa, ou=system", and ask for a subtree search
     */
    @Test
    public void testSearchBaseWithReferralThrowAfterMoveAndRename() throws Exception
    {
        DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );

        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );

        try
        {
            ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
            fail( "Should fail here throwing a ReferralException" );
        }
        catch ( ReferralException re )
        {
            String referral = ( String ) re.getReferralInfo();
            assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
        }

        ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
            { new ManageReferralControl() } );

        // Now let's move the entry
        ctx.rename( "c=america,ou=Countries,ou=system", "c=us,ou=system" );

        controls.setSearchScope( SearchControls.OBJECT_SCOPE );

        ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
            {} );

        try
        {
            NamingEnumeration<SearchResult> results = ctx.search( "c=us,ou=system", "(cn=alex karasulu)", controls );

            results.next();
            fail( "Should fail here throwing a ReferralException" );
        }
        catch ( ReferralException re )
View Full Code Here

        // Create entry cn=Sid Vicious, ou=system
        Attributes vicious = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: person",
            "cn: Sid Vicious",
            "sn: Vicious", "description: (sex*pis\\tols)" );

        DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
        assertNotNull( ctx );

        ctx = ( DirContext ) sysRoot.lookup( "cn=Sid Vicious" );
        assertNotNull( ctx );

        Attributes attributes = ctx.getAttributes( "" );

        assertEquals( "(sex*pis\\tols)", attributes.get( "description" ).get() );

        // Now, search for the description
        SearchControls controls = new SearchControls();
View Full Code Here

        // Create entry cn=Sid Vicious, ou=system
        Attributes vicious = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: person",
            "cn: Sid Vicious",
            "sn: Vicious", "description: (sex*pis\\tols)" );

        DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
        assertNotNull( ctx );

        ctx = ( DirContext ) sysRoot.lookup( "cn=Sid Vicious" );
        assertNotNull( ctx );

        Attributes attributes = ctx.getAttributes( "" );

        assertEquals( "(sex*pis\\tols)", attributes.get( "description" ).get() );

        // Now, search for the description
        SearchControls controls = new SearchControls();
View Full Code Here

     * if they are requested.
     */
    @Test
    public void testRequestOperationalAttributes() throws Exception
    {
        DirContext ctx = getWiredContext( getLdapServer() );
        SearchControls ctls = new SearchControls();

        String[] attrNames =
            { "creatorsName", "createTimestamp", "modifiersName", "modifyTimestamp" };

        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
        ctls.setReturningAttributes( attrNames );

        NamingEnumeration<SearchResult> result = ctx.search( DN, FILTER, ctls );

        if ( result.hasMore() )
        {
            SearchResult entry = result.next();
            checkForAttributes( entry.getAttributes(), attrNames );
View Full Code Here

     * if + is requested.
     */
    @Test
    public void testRequestAllOperationalAttributes() throws Exception
    {
        DirContext ctx = getWiredContext( getLdapServer() );
        SearchControls ctls = new SearchControls();

        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
        ctls.setReturningAttributes( new String[]
            { "+" } );

        NamingEnumeration<SearchResult> result = ctx.search( DN, FILTER, ctls );

        if ( result.hasMore() )
        {
            SearchResult entry = result.next();
            String[] attrNames =
View Full Code Here

     * the dynamic schema fails when no result is found.
     */
    @Test
    public void testSearchingNewSchemaElements() throws Exception
    {
        DirContext ctx = getWiredContext( getLdapServer() );

        // create an entry with the schema objectClass personActiveDirectory
        Attributes person = new BasicAttributes( "objectClass", "top", true );
        person.get( "objectClass" ).add( "person" );
        person.get( "objectClass" ).add( "personActiveDirectory" );
        person.put( "cn", "foobar" );
        person.put( "sn", "bar" );
        person.put( "pwdLastSet", "3" );
        person.put( "SourceAD", "blah" );
        person.put( "useraccountcontrol", "7" );
        person.put( "sAMAccountName", "foobar" );
        ctx.createSubcontext( "cn=foobar,ou=system", person );

        // Confirm creation with a lookup
        Attributes read = ctx.getAttributes( "cn=foobar,ou=system" );
        assertNotNull( read );
        assertEquals( "3", read.get( "pwdLastSet" ).get() );

        // Now search for foobar with pwdLastSet value of 3
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
        NamingEnumeration<SearchResult> results = ctx.search( "ou=system", "(pwdLastSet=3)", searchControls );
        assertTrue( results.hasMore() );
        SearchResult result = results.next();
        assertNotNull( result );
        assertEquals( "cn=foobar", result.getName() );
        Attributes attributes = result.getAttributes();
        assertEquals( "3", attributes.get( "pwdLastSet" ).get() );
        results.close();

        // Now search with bogus value for pwdLastSet
        results = ctx.search( "ou=system", "(pwdLastSet=300)", searchControls );
        assertFalse( results.hasMore() );
        results.close();
    }
View Full Code Here

     */
    @Test
    public void testPagedSearchtest12() throws Exception
    {
        getLdapServer().setMaxSizeLimit( 5 );
        DirContext ctx = getWiredContext( getLdapServer() );
        SearchControls controls = createSearchControls( ctx, 4, 3 );

        doLoop( ctx, controls, 3, 2, 4, true );
    }
View Full Code Here

     */
    @Test
    public void testPagedSearchtest13() throws Exception
    {
        getLdapServer().setMaxSizeLimit( 4 );
        DirContext ctx = getWiredContext( getLdapServer() );
        SearchControls controls = createSearchControls( ctx, 5, 3 );

        doLoop( ctx, controls, 3, 2, 5, true );
    }
View Full Code Here

     */
    @Test
    public void testPagedSearchtest14() throws Exception
    {
        getLdapServer().setMaxSizeLimit( 4 );
        DirContext ctx = getWiredContext( getLdapServer() );
        SearchControls controls = createSearchControls( ctx, 3, 5 );

        doLoop( ctx, controls, 5, 1, 3, true );
    }
View Full Code Here

TOP

Related Classes of javax.naming.directory.DirContext

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.