org.apache.directory.ldap.client.api.LdapConnection Java Examples

The following examples show how to use org.apache.directory.ldap.client.api.LdapConnection. 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: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method will search the directory and return at most one record.  If more than one record is found
 * an ldap exception will be thrown.
 *
 * @param connection is LdapConnection object used for all communication with host.
 * @param baseDn     contains address of distinguished name to begin ldap search
 * @param scope      indicates depth of search starting at basedn.  0 (base dn),
 *                   1 (one level down) or 2 (infinite) are valid values.
 * @param filter     contains the search criteria
 * @param attrs      is the requested list of attritubutes to return from directory search.
 * @param attrsOnly  if true pull back attribute names only.
 * @return entry   containing target ldap node.
 * @throws LdapException   thrown in the event of error in ldap client or server code.
 * @throws CursorException If we weren't able to fetch an element from the search result
 */
protected Entry searchNode( LdapConnection connection, String baseDn, SearchScope scope, String filter,
    String[] attrs, boolean attrsOnly ) throws LdapException, CursorException
{
    SearchRequest searchRequest = new SearchRequestImpl();

    searchRequest.setBase( new Dn( baseDn ) );
    searchRequest.setFilter( filter );
    searchRequest.setScope( scope );
    searchRequest.setTypesOnly( attrsOnly );
    searchRequest.addAttributes( attrs );

    SearchCursor result = connection.search( searchRequest );

    Entry entry = result.getEntry();

    if ( result.next() )
    {
        throw new LdapException( "searchNode failed to return unique record for LDAP search of base DN [" +
            baseDn + "] filter [" + filter + "]" );
    }

    return entry;
}
 
Example #2
Source File: PropertyDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * Delete properties to the provided entity using the provided property provider    
 *
 * @param entity A FortressEntity that supports properties (Role, AdminRole, Group, Permission, PermObj)
 * @param properties
 * @param propProvider DAO for entity type that implements property provider interface
 * @throws UpdateException
 * @throws FinderException
 */
void deleteProperties( FortEntity entity, Properties properties, PropertyProvider propProvider ) throws UpdateException, FinderException
{
    LdapConnection ld = null;
    String entityDn = propProvider.getDn( entity );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        removeProperties( properties, mods, GlobalIds.PROPS );            

        ld = getAdminConnection();
        modify( ld, entityDn, mods, entity );            
    }
    catch ( LdapException e )
    {
        String error = "delete entity properties[" + entity.getClass().getSimpleName() + "] caught LDAPException=" + e;
        throw new UpdateException( GlobalErrIds.USER_UPDATE_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}
 
Example #3
Source File: PropertyDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * Add properties to the provided entity using the provided property provider
 *
 * @param entity A FortressEntity that supports properties (Role, AdminRole, Group, Permission, PermObj)
 * @param properties
 * @param propProvider DAO for entity type that implements property provider interface
 * @return Entity with current property value
 * @throws UpdateException
 * @throws FinderException
 */
FortEntity addProperties( FortEntity entity, Properties properties, PropertyProvider propProvider ) throws UpdateException, FinderException
{ 
    LdapConnection ld = null;
    String entityDn = propProvider.getDn( entity );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        loadProperties( properties, mods, GlobalIds.PROPS, false );

        ld = getAdminConnection();
        modify( ld, entityDn, mods, entity );            
    }
    catch ( LdapException e )
    {
        String error = "add entity properties[" + entity.getClass().getSimpleName() + "] caught LDAPException=" + e;
        throw new UpdateException( GlobalErrIds.USER_UPDATE_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }

    return propProvider.getEntity( entity );
}
 
Example #4
Source File: AdminRoleDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param entity
 * @throws UpdateException
 */
void deleteParent( AdminRole entity ) throws UpdateException
{
    LdapConnection ld = null;
    String dn = getDn( entity );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add( new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, GlobalIds.PARENT_NODES ) );
        ld = getAdminConnection();
        modify( ld, dn, mods, entity );
    }
    catch ( LdapException e )
    {
        String error = "deleteParent name [" + entity.getName() + "] caught LdapException=" + e;
        throw new UpdateException( GlobalErrIds.ARLE_REMOVE_PARENT_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}
 
Example #5
Source File: RoleDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * @param entity
 * @param userDn
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 *
 */
Role deassign( Role entity, String userDn ) throws UpdateException
{
    LdapConnection ld = null;
    String dn = getDn( entity.getName(), entity.getContextId() );
    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add( new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
            SchemaConstants.ROLE_OCCUPANT_AT, userDn ) );
        ld = getAdminConnection();
        modify( ld, dn, mods, entity );
    }
    catch ( LdapException e )
    {
        String error = "deassign role name [" + entity.getName() + "] user dn [" + userDn
            + "] caught LdapException=" + e;
        throw new UpdateException( GlobalErrIds.ROLE_USER_DEASSIGN_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }

    return entity;
}
 
Example #6
Source File: RoleDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param entity
 * @throws UpdateException
 */
void deleteParent( Role entity ) throws UpdateException
{
    LdapConnection ld = null;
    String dn = getDn( entity.getName(), entity.getContextId() );
    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add( new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
            GlobalIds.PARENT_NODES ) );
        ld = getAdminConnection();
        modify( ld, dn, mods, entity );
    }
    catch ( LdapException e )
    {
        String error = "deleteParent name [" + entity.getName() + "] caught LdapException=" + e;
        throw new UpdateException( GlobalErrIds.ROLE_REMOVE_PARENT_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}
 
Example #7
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AddResponse add( AddRequest addRequest )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return connection.add( addRequest );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #8
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public PasswordWarning authenticate( Dn userDn, char[] password ) throws PasswordException
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return authenticateConnection( connection, userDn, password );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #9
Source File: UserDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * @param user
 * @return
 * @throws UpdateException
 * @throws Exception
 */
String deletePwPolicy( User user ) throws UpdateException
{
    LdapConnection ld = null;
    String userDn = getDn( user.getUserId(), user.getContextId() );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();

        mods.add( new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, OPENLDAP_POLICY_SUBENTRY ) );
        ld = getAdminConnection();
        modify( ld, userDn, mods, user );
    }
    catch ( LdapException e )
    {
        String warning = "deletePwPolicy userId [" + user.getUserId() + "] caught LDAPException=" + e + " msg=" + e;
        throw new UpdateException( GlobalErrIds.USER_PW_PLCY_DEL_FAILED, warning, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }

    return userDn;
}
 
Example #10
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete( DeleteRequest deleteRequest )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return connection.delete( deleteRequest );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #11
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 #12
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void modifyPassword( Dn userDn, char[] oldPassword,
    char[] newPassword, boolean asAdmin ) throws PasswordException
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        if ( !asAdmin )
        {
            authenticateConnection( connection, userDn, oldPassword );
        }

        modifyPassword( connection, userDn, newPassword );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #13
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ModifyResponse modify( ModifyRequest modifyRequest )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return connection.modify( modifyRequest );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #14
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> T execute( ConnectionCallback<T> connectionCallback )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return connectionCallback.doWithConnection( connection );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #15
Source File: GroupDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * @param entity
 * @param userDn
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 *
 */
Group assign( Group entity, String userDn ) throws FinderException, UpdateException
{
    LdapConnection ld = null;
    String dn = getDn( entity.getName(), entity.getContextId() );
    LOG.debug( "assign group property dn [{}], member dn [{}]", dn, userDn );
    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add( new DefaultModification(
            ModificationOperation.ADD_ATTRIBUTE, SchemaConstants.MEMBER_AT, userDn ) );
        ld = getAdminConnection();
        modify( ld, dn, mods, entity );
    }
    catch ( LdapException e )
    {
        String error = "assign group name [" + entity.getName() + "] user dn [" + userDn + "] caught " +
            "LDAPException=" + e;
        throw new UpdateException( GlobalErrIds.GROUP_USER_ASSIGN_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
    return get( entity );
}
 
Example #16
Source File: UserDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * @param user
 * @throws org.apache.directory.fortress.core.UpdateException
 */
void lock( User user ) throws UpdateException
{
    LdapConnection ld = null;
    String userDn = getDn( user.getUserId(), user.getContextId() );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, OPENLDAP_PW_LOCKED_TIME,
            LOCK_VALUE ) );
        ld = getAdminConnection();
        modify( ld, userDn, mods, user );
    }
    catch ( LdapException e )
    {
        String error = "lock user [" + user.getUserId() + "] caught LDAPException=" + e;
        throw new UpdateException( GlobalErrIds.USER_PW_LOCK_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}
 
Example #17
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new ldap entry to the directory.  Add audit context.
 *
 * @param connection handle to ldap connection.
 * @param entry      contains data to add..
 * @param entity     contains audit context.
 * @throws LdapException in the event system error occurs.
 */
protected void add( LdapConnection connection, Entry entry, FortEntity entity ) throws LdapException
{
    COUNTERS.incrementAdd();

    if ( !Config.getInstance().isAuditDisabled() && ( entity != null ) && ( entity.getAdminSession() != null ) )
    {
        if ( StringUtils.isNotEmpty( entity.getAdminSession().getInternalUserId() ) )
        {
            entry.add( GlobalIds.FT_MODIFIER, entity.getAdminSession().getInternalUserId() );
        }

        if ( StringUtils.isNotEmpty( entity.getModCode() ) )
        {
            entry.add( GlobalIds.FT_MODIFIER_CODE, entity.getModCode() );
        }

        if ( StringUtils.isNotEmpty( entity.getModId() ) )
        {
            entry.add( GlobalIds.FT_MODIFIER_ID, entity.getModId() );
        }
    }

    connection.add( entry );
}
 
Example #18
Source File: GroupDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method will remove group node from diretory.
 *
 * @param group
 * @throws org.apache.directory.fortress.core.RemoveException
 *
 */
Group remove( Group group ) throws RemoveException
{
    LdapConnection ld = null;
    String nodeDn = getDn( group.getName(), group.getContextId() );
    LOG.debug( "remove group dn [{}]", nodeDn );
    try
    {
        ld = getAdminConnection();
        delete( ld, nodeDn, group );
    }
    catch ( LdapException e )
    {
        String error = "remove group node dn [" + nodeDn + "] caught LDAPException=" + e;
        throw new RemoveException( GlobalErrIds.GROUP_DELETE_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
    return group;
}
 
Example #19
Source File: AdminRoleDAO.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method will remove the supplied DN as a role occupant to the target record.
 * This data will be stored in the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
 *
 * @param entity record contains {@link AdminRole#name}.  Null attributes will be ignored.
 * @param userDn contains the DN for userId who is being deassigned.
 * @return input record back to client.
 * @throws UpdateException in the event LDAP errors occur.
 */
AdminRole deassign( AdminRole entity, String userDn ) throws UpdateException
{
    LdapConnection ld = null;
    String dn = getDn( entity );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add( new DefaultModification(
            ModificationOperation.REMOVE_ATTRIBUTE, ROLE_OCCUPANT, userDn ) );
        ld = getAdminConnection();
        modify( ld, dn, mods, entity );
    }
    catch ( LdapException e )
    {
        String error = "deassign role name [" + entity.getName() + "] user dn [" + userDn
            + "] caught LdapException=" + e;
        throw new UpdateException( GlobalErrIds.ARLE_USER_DEASSIGN_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
    return entity;
}
 
Example #20
Source File: AcceleratorDAO.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Deactivate user role from impl session
 * This function follows the pattern from: {@link org.apache.directory.fortress.core.AccessMgr#dropActiveRole(org.apache.directory.fortress.core.model.Session, org.apache.directory.fortress.core.model.UserRole)}.
 * Success will result in impl session state to be modified inside server-side cache.
 * It uses the {@link RbacDropRoleRequest} and {@link RbacDropRoleResponse} accelerator APIs.
 *
 * @param session contains a valid sessionId captured from accelerator createSession method.
 * @param userRole both the {@link org.apache.directory.fortress.core.model.UserRole#userId} and {@link UserRole#name} fields must be set before invoking.
 * @throws SecurityException rethrows {@code LdapException} with {@code GlobalErrIds.ACEL_DROP_ROLE_ERR}.
 */
void dropActiveRole( Session session, UserRole userRole ) throws SecurityException
{
    LdapConnection ld = null;

    try
    {
        ld = getAdminConnection();
        RbacDropRoleRequest dropRoleRequest = new RbacDropRoleRequestImpl();
        dropRoleRequest.setSessionId( session.getSessionId() );
        dropRoleRequest.setRole( userRole.getName() );
        dropRoleRequest.setUserIdentity( userRole.getUserId() );
        // Send the request
        RbacDropRoleResponse rbacDropRoleResponse = ( RbacDropRoleResponse ) ld.extended(
            dropRoleRequest );
        LOG.debug( "dropActiveRole result: {}", rbacDropRoleResponse.getLdapResult().getResultCode() );

        if ( rbacDropRoleResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS )
        {
            String info = "dropActiveRole Role [" + userRole.getName() + "] User ["
                + session.getUserId() + "], not previously activated.";
            throw new SecurityException( GlobalErrIds.URLE_NOT_ACTIVE, info );
        }
    }
    catch ( LdapException e )
    {
        String error = "dropActiveRole role name [" + userRole.getName() + "] caught LDAPException=" + " msg=" + e
            .getMessage();
        throw new SecurityException( GlobalErrIds.ACEL_DROP_ROLE_ERR, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}
 
Example #21
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private static void bindAdmin(LdapConnection conn, LdapOptions options) throws LdapException {
	if (!Strings.isEmpty(options.adminDn)) {
		conn.bind(options.adminDn, options.adminPasswd);
	} else {
		conn.bind();
	}
}
 
Example #22
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Delete exiting ldap entry and all descendants from the directory.  Add audit context.  This method will call
 * modify prior to delete which will
 * force corresponding audit record to be written to slapd access log.
 *
 * @param connection handle to ldap connection.
 * @param dn         contains distinguished node of entry targeted for removal..
 * @param entity     contains audit context.
 * @throws LdapException   in the event system error occurs.
 * @throws CursorException
 */
protected void deleteRecursive( LdapConnection connection, String dn, FortEntity entity ) throws LdapException,
    CursorException
{
    List<Modification> mods = new ArrayList<Modification>();
    audit( mods, entity );

    if ( mods.size() > 0 )
    {
        modify( connection, dn, mods );
    }

    deleteRecursive( connection, dn );
}
 
Example #23
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Perform normal ldap search accepting default batch size.
 *
 * @param connection is LdapConnection object used for all communication with host.
 * @param baseDn     contains address of distinguished name to begin ldap search
 * @param scope      indicates depth of search starting at basedn.  0 (base dn),
 *                   1 (one level down) or 2 (infinite) are valid values.
 * @param filter     contains the search criteria
 * @param attrs      is the requested list of attritubutes to return from directory search.
 * @param attrsOnly  if true pull back attribute names only.
 * @return result set containing ldap entries returned from directory.
 * @throws LdapException thrown in the event of error in ldap client or server code.
 */
protected SearchCursor search( LdapConnection connection, String baseDn, SearchScope scope, String filter,
    String[] attrs, boolean attrsOnly ) throws LdapException
{
    COUNTERS.incrementSearch();

    SearchRequest searchRequest = new SearchRequestImpl();
    searchRequest.setBase( new Dn( baseDn ) );
    searchRequest.setScope( scope );
    searchRequest.setFilter( filter );
    searchRequest.setTypesOnly( attrsOnly );
    searchRequest.addAttributes( attrs );

    return connection.search( searchRequest );
}
 
Example #24
Source File: LDAPApi.java    From mamute with Apache License 2.0 5 votes vote down vote up
private LdapConnection connection(String username, String password) throws LdapException {
	// Manually build the configuration since the convenience constructor in 
	// the LdapNetworkConnection doesn't let us specify a TLS setting			
	LdapConnectionConfig config = new LdapConnectionConfig();
	config.setLdapHost(host);
	config.setLdapPort(port);
	config.setUseTls(useTls);
	config.setUseSsl(useSsl);
       LdapNetworkConnection conn = new LdapNetworkConnection(config);
	
	conn.bind(username, password);
	return conn;
}
 
Example #25
Source File: SuffixDAO.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * @param se
 * @throws org.apache.directory.fortress.core.CreateException
 */
void create( Suffix se )
    throws CreateException
{
    LdapConnection ld = null;
    String nodeDn = getDn( se );
    try
    {
        LOG.info( "create suffix dn [{}]", nodeDn );
        Entry myEntry = new DefaultEntry( nodeDn );
        myEntry.add( SchemaConstants.OBJECT_CLASS_AT, SUFFIX_OBJ_CLASS );
        myEntry.add( SchemaConstants.DC_AT, se.getName() );
        myEntry.add( SchemaConstants.O_AT, se.getDescription() );

        ld = getAdminConnection();
        add( ld, myEntry );
    }
    catch ( LdapException e )
    {
        String error = "create container node dn [" + nodeDn + "] caught LDAPException="
            + e;
        throw new CreateException( GlobalErrIds.SUFX_CREATE_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}
 
Example #26
Source File: MultipleResponseFuture.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of ResponseFuture.
 *
 * @param connection The LdapConnection used by the request
 * @param messageId The associated message ID
 */
public MultipleResponseFuture( LdapConnection connection, int messageId )
{
    queue = new LinkedBlockingQueue<>();
    this.messageId = messageId;
    this.connection = connection;
}
 
Example #27
Source File: UserDAO.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * @param entity
 * @param replace
 * @return
 * @throws UpdateException
 */
User updateProps( User entity, boolean replace ) throws UpdateException
{
    LdapConnection ld = null;
    String userDn = getDn( entity.getUserId(), entity.getContextId() );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();

        if ( PropUtil.isNotEmpty( entity.getProperties() ) )
        {
            loadProperties( entity.getProperties(), mods, GlobalIds.PROPS, replace );
        }

        if ( mods.size() > 0 )
        {
            ld = getAdminConnection();
            modify( ld, userDn, mods, entity );
            entity.setDn( userDn );
        }

        entity.setDn( userDn );
    }
    catch ( LdapException e )
    {
        String error = "updateProps userId [" + entity.getUserId() + "] isReplace [" + replace + "] caught " +
            "LDAPException=" + e;
        throw new UpdateException( GlobalErrIds.USER_UPDATE_FAILED, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }

    return entity;
}
 
Example #28
Source File: OrgUnitDAO.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.RemoveException
 *
 */
OrgUnit remove( OrgUnit entity ) throws RemoveException
{
    LdapConnection ld = null;
    Dn dn = getDn( entity );

    try
    {
        ld = getAdminConnection();
        delete( ld, dn, entity );
    }
    catch ( LdapException e )
    {
        String error = "remove orgUnit name [" + entity.getName() + "] type [" + entity.getType()
            + "] root [" + dn + "] caught LdapException=" + e;
        int errCode;

        if ( entity.getType() == OrgUnit.Type.PERM )
        {
            errCode = GlobalErrIds.ORG_DELETE_FAILED_PERM;
        }
        else
        {
            errCode = GlobalErrIds.ORG_DELETE_FAILED_USER;
        }

        throw new RemoveException( errCode, error, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }

    return entity;
}
 
Example #29
Source File: LdapConnectionProvider.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Calls the PoolMgr to get an Log connection to the LDAP server.
 *
 * @return ldap connection.
 * @throws LdapException If we had an issue getting an LDAP connection
 */
public LdapConnection getLogConnection() throws LdapException
{
    try
    {
        return logPool.getConnection();
    }
    catch ( Exception e )
    {
        throw new LdapException( e );
    }
}
 
Example #30
Source File: UserDAO.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * @param user
 * @throws UpdateException
 */
void resetUserPassword( User user ) throws UpdateException
{
    LdapConnection ld = null;
    String userDn = getDn( user.getUserId(), user.getContextId() );

    try
    {
        List<Modification> mods = new ArrayList<Modification>();

        mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants
            .USER_PASSWORD_AT, user.getPassword() ) );

        mods.add( new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, OPENLDAP_PW_RESET, "TRUE" ) );

        ld = getAdminConnection();
        modify( ld, userDn, mods, user );
    }
    catch ( LdapException e )
    {
        String warning = "resetUserPassword userId [" + user.getUserId() + "] caught LDAPException=" + e
            .getMessage();
        throw new UpdateException( GlobalErrIds.USER_PW_RESET_FAILED, warning, e );
    }
    finally
    {
        closeAdminConnection( ld );
    }
}