Java Code Examples for org.apache.directory.ldap.client.api.LdapConnection#lookup()

The following examples show how to use org.apache.directory.ldap.client.api.LdapConnection#lookup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> T lookup( Dn dn, String[] attributes, EntryMapper<T> entryMapper )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        Entry entry = attributes == null
            ? connection.lookup( dn )
            : connection.lookup( dn, attributes );
        return entry == null ? null : entryMapper.map( entry );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example 2
Source File: LdapDirectoryServerConnectionTest.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public void testUserCreation() {
        LdapConnection connection = new LdapNetworkConnection( "localhost", 10389 );
        try {
            connection.bind( "uid=admin,ou=system", "secret" );

            connection.add(new DefaultEntry(
                    "ou=acsadmins,ou=users,ou=system",
            "objectClass: organizationalUnit",
// might also need to be           objectClass: top
            "ou: acsadmins"
            ));
            connection.add(new DefaultEntry(
                    "uid=dahn,ou=acsadmins,ou=users,ou=system",
                    "objectClass: inetOrgPerson",
                    "objectClass: top",
                    "cn: dahn",
                    "sn: Hoogland",
                    "givenName: Daan",
                    "mail: [email protected]",
                    "uid: dahn"
            ));

            connection.add(
                    new DefaultEntry(
                            "cn=JuniorAdmins,ou=groups,ou=system", // The Dn
                            "objectClass: groupOfUniqueNames",
                            "ObjectClass: top",
                            "cn: JuniorAdmins",
                            "uniqueMember: uid=dahn,ou=acsadmins,ou=system,ou=users") );

            assertTrue( connection.exists( "cn=JuniorAdmins,ou=groups,ou=system" ) );
            assertTrue( connection.exists( "uid=dahn,ou=acsadmins,ou=users,ou=system" ) );

            Entry ourUser = connection.lookup("uid=dahn,ou=acsadmins,ou=users,ou=system");
            ourUser.add("memberOf", "cn=JuniorAdmins,ou=groups,ou=system");
            AddRequest addRequest = new AddRequestImpl();
            addRequest.setEntry( ourUser );
            AddResponse response = connection.add( addRequest );
            assertNotNull( response );
            // We would need to either
//            assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );
            // or have the automatic virtual attribute

            List<LdapUser> usahs = ldapManager.getUsers(1L);
            assertEquals("now an admin and a normal user should be present",2, usahs.size());

        } catch (LdapException | NoLdapUserMatchingQueryException e) {
            fail(e.getLocalizedMessage());
        }
    }
 
Example 3
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 3 votes vote down vote up
/**
 * Read the ldap record from specified location.
 *
 * @param connection handle to ldap connection.
 * @param dn         contains ldap distinguished name.
 * @param attrs      array contains array names to pull back.
 * @return ldap entry.
 * @throws LdapException in the event system error occurs.
 */
protected Entry read( LdapConnection connection, String dn, String[] attrs ) throws LdapException
{
    COUNTERS.incrementRead();

    return connection.lookup( dn, attrs );
}
 
Example 4
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 3 votes vote down vote up
/**
 * Read the ldap record from specified location.
 *
 * @param connection handle to ldap connection.
 * @param dn         contains ldap distinguished name.
 * @param attrs      array contains array names to pull back.
 * @return ldap entry.
 * @throws LdapException in the event system error occurs.
 */
protected Entry read( LdapConnection connection, Dn dn, String[] attrs ) throws LdapException
{
    COUNTERS.incrementRead();

    return connection.lookup( dn, attrs );
}
 
Example 5
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 3 votes vote down vote up
/**
 * Read the ldap record from specified location with user assertion.
 *
 * @param connection handle to ldap connection.
 * @param dn         contains ldap distinguished name.
 * @param attrs      array contains array names to pull back.                                        ,
 *                   PoolMgr.ConnType.USER
 * @param userDn     string value represents the identity of user on who's behalf the request was initiated.  The
 *                   value will be stored in openldap auditsearch record AuthZID's attribute.
 * @return ldap entry.
 * @throws LdapException                in the event system error occurs.
 * @throws UnsupportedEncodingException for search control errors.
 */
protected Entry read( LdapConnection connection, String dn, String[] attrs, String userDn ) throws LdapException
{
    COUNTERS.incrementRead();

    return connection.lookup( dn, attrs );
}