Package org.apache.directory.api.ldap.model.entry

Examples of org.apache.directory.api.ldap.model.entry.Entry


        String attribVal = "Johnny";
        attrib.add( attribVal );

        Modification add = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );

        assertEquals( "WAlkeR", lookedup.get( "sn" ).get().getString() ); // before replacing

        lookedup = store.modify( dn, add );
        assertEquals( attribVal, lookedup.get( "sn" ).get().getString() );

        // testing the store.modify( dn, mod, entry ) API
        Modification replace = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SN_AT, "JWalker" );

        lookedup = store.modify( dn, replace );
        assertEquals( "JWalker", lookedup.get( "sn" ).get().getString() );
        assertEquals( 1, lookedup.get( "sn" ).size() );
    }
View Full Code Here


        Attribute attrib = new DefaultAttribute( SchemaConstants.SN_AT, SN_AT );

        Modification add = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );

        assertNotNull( lookedup.get( "sn" ).get() );

        lookedup = store.modify( dn, add );
        assertNull( lookedup.get( "sn" ) );

        // add an entry for the sake of testing the remove operation
        add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, SN_AT, "JWalker" );
        lookedup = store.modify( dn, add );
        assertNotNull( lookedup.get( "sn" ) );

        Modification remove = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, SN_AT );
        lookedup = store.modify( dn, remove );
        assertNull( lookedup.get( "sn" ) );
    }
View Full Code Here

    @Test
    public void testModifyDelete() throws LdapException, CursorException, IOException
    {
        // Add the entry
        Dn dn = new Dn( "uid=1,dc=example,dc=com" );
        Entry entry = new DefaultEntry(
            getService().getSchemaManager(),
            dn,
            "objectClass: top",
            "objectClass: person",
            "objectClass: organizationalPerson",
            "objectClass: inetOrgPerson",
            "uid: 1",
            "mail: test@acme.com",
            "title: technician",
            "sn: Test",
            "departmentNumber: Dep1",
            "cn: entryTest",
            "cn: test2",
            "description: Test entry",
            "telephoneNumber: 123 456",
            "givenName: Test user",
            "displayName: testEntry",
            "businessCategory: Test ops",
            "employeeNumber: Test user",
            "pwdPolicySubEntry: ads-pwdId=cproint,ou=passwordPolicies,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config" );

        connection.add( entry );

        // Check the search using the cn index
        EntryCursor results = connection.search( "dc=example,dc=com", "(cn=e*)", SearchScope.SUBTREE, "*" );

        int nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        results.close();

        assertEquals( 1, nbFound );

        // Ok, now replace the cn
        Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, "displayName",
            "testEntry" );

        connection.modify( dn, modification );

        // We should not find anything using the substring filter for the displayName AT
        results = connection.search( "dc=example,dc=com", "(displayName=t*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Check that we cannot find the displayName using the presence index
        results = connection.search( "dc=example,dc=com", "(displayName=n*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Now, Delete one value from the cn index
        modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, "cn", "test2" );

        connection.modify( dn, modification );

        // Check the cn index using the remaining value
        results = connection.search( "dc=example,dc=com", "(cn=E*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertFalse( result.contains( "cn", "test2" ) );
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Check the cn index using the removed value
        results = connection.search( "dc=example,dc=com", "(cn=t*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Now, check the presence index
        results = connection.search( "dc=example,dc=com", "(cn=*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertFalse( result.contains( "cn", "test2" ) );
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

View Full Code Here

    @Test
    public void testModifyReplaceNonExistingIndexAttribute() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=Tim B,ou=Sales,o=Good Times Co." );
        Entry entry = new DefaultEntry( schemaManager, dn,
            "objectClass: top",
            "objectClass: person",
            "objectClass: organizationalPerson",
            "cn", "Tim B",
            "entryCSN", new CsnFactory( 1 ).newInstance().toString(),
            "entryUUID", UUID.randomUUID().toString() );

        AddOperationContext addContext = new AddOperationContext( null, entry );
        store.add( addContext );

        Attribute attrib = new DefaultAttribute( SchemaConstants.OU_AT, OU_AT );

        String attribVal = "Marketing";
        attrib.add( attribVal );

        Modification add = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attrib );

        Entry lookedup = store.fetch( store.getEntryId( dn ), dn );

        assertNull( lookedup.get( "ou" ) ); // before replacing

        lookedup = store.modify( dn, add );
        assertEquals( attribVal, lookedup.get( "ou" ).get().getString() );
    }
View Full Code Here

    @Test
    public void testSimpleSearch() throws Exception
    {
        // Add an entry in ou=system
        Dn dn1 = new Dn( "cn=test,ou=system" );
        Entry entry1 = new DefaultEntry( getService().getSchemaManager(), dn1,
            "ObjectClass: top",
            "ObjectClass: person",
            "sn: TEST",
            "cn: test" );

        connection.add( entry1 );

        // Add an entry in dc=test
        Dn dn2 = new Dn( "cn=test,dc=test,dc=com" );
        Entry entry2 = new DefaultEntry( getService().getSchemaManager(), dn2,
            "ObjectClass: top",
            "ObjectClass: person",
            "sn: TEST",
            "cn: test" );

        connection.add( entry2 );

        // Add an entry in dc=example
        Dn dn3 = new Dn( "cn=test,dc=example,dc=com" );
        Entry entry3 = new DefaultEntry( getService().getSchemaManager(), dn3,
            "ObjectClass: top",
            "ObjectClass: person",
            "sn: TEST",
            "cn: test" );

        connection.add( entry3 );

        // Now search the entry from the root
        EntryCursor cursor = connection.search( "", "(cn=test)", SearchScope.SUBTREE );
        List<String> entries = new ArrayList<String>();

        while ( cursor.next() )
        {
            Entry entryFound = cursor.get();
            assertNotNull( entryFound );
            entries.add( entryFound.getDn().getName() );
        }

        SearchResultDone done = cursor.getSearchResultDone();

        assertNotNull( done );
View Full Code Here

        EntryCursor cursor = userCtx.search( base.getName(), filter, scope, "*" );
        int counter = 0;
   
        while ( cursor.next() )
        {
            Entry result = cursor.get();
            results.put( result.getDn().getName(), result );
            counter++;
        }
   
        cursor.close();
   
View Full Code Here

        EntryCursor cursor = userCtx.search( base.getName(), "(objectClass=*)", scope, "*" );
        int counter = 0;
   
        while ( cursor.next() )
        {
            Entry result = cursor.get();
            results.put( result.getDn().getName(), result );
            counter++;
        }
   
        cursor.close();
   
View Full Code Here

     * @throws Exception if the search fails w/ exception other than no permission
     */
    private Entry checkCanSearchSubentryAs( String uid, String password, Dn dn ) throws Exception
    {
        LdapConnection userCtx = getConnectionAs( new Dn( "uid=" + uid + ",ou=users,ou=system" ), password );
        Entry result = null;
        EntryCursor list = null;
   
        list = userCtx.search( dn.getName(), "(objectClass=*)", SearchScope.OBJECT, "*" );
   
        if ( list.next() )
View Full Code Here

   
        // get a context as the user and try a lookup of a non-existant entry under ou=groups,ou=system
        LdapConnection userCtx = getConnectionAs( "uid=billyd,ou=users,ou=system", "billyd" );
   
        // we should not see ou=groups,ou=system for the remaining name
        Entry entry = userCtx.lookup( "cn=blah,ou=groups" );
        assertNull( entry );
   
        // now delete and replace subentry with one that does not excluse ou=groups,ou=system
        deleteAccessControlSubentry( "selectiveDiscloseOnError" );
        createAccessControlSubentry( "selectiveDiscloseOnError",
View Full Code Here

    {
        // create the non-admin user
        createUser( "billyd", "billyd" );
   
        // create an entry subordinate to the user
        Entry phoneBook = new DefaultEntry( "ou=phoneBook,uid=billyd,ou=users,ou=system" );
        phoneBook.add( SchemaConstants.OU_AT, "phoneBook" );
        phoneBook.add( SchemaConstants.OBJECT_CLASS_AT, "organizationalUnit" );
   
        getAdminConnection().add( phoneBook );
   
        // now add a subentry that enables anyone to search below their own entries
        createAccessControlSubentry( "anybodySearchTheirSubordinates",
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.entry.Entry

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.