Search in sources :

Example 16 with UpdateException

use of org.apache.directory.fortress.core.UpdateException in project directory-fortress-core by apache.

the class UserDAO method unlock.

/**
 * @param user
 * @throws UpdateException
 */
void unlock(User user) throws UpdateException {
    LdapConnection ld = null;
    String userDn = getDn(user.getUserId(), user.getContextId());
    try {
        // ld = getAdminConnection();
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, OPENLDAP_PW_LOCKED_TIME));
        ld = getAdminConnection();
        modify(ld, userDn, mods, user);
    } catch (LdapNoSuchAttributeException e) {
        LOG.info("unlock user [" + user.getUserId() + "] no such attribute:" + OPENLDAP_ACCOUNT_LOCKED_TIME);
    } catch (LdapException e) {
        String error = "unlock user [" + user.getUserId() + "] caught LDAPException= " + e.getMessage();
        throw new UpdateException(GlobalErrIds.USER_PW_UNLOCK_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 17 with UpdateException

use of org.apache.directory.fortress.core.UpdateException in project directory-fortress-core by apache.

the class UserDAO method deassign.

/**
 * @param uRole
 * @return
 * @throws UpdateException
 * @throws FinderException
 */
String deassign(UserRole uRole) throws UpdateException, FinderException {
    LdapConnection ld = null;
    String userDn = getDn(uRole.getUserId(), uRole.getContextId());
    try {
        // read the user's RBAC role assignments to locate target record.  Need the raw data before attempting
        // removal:
        List<UserRole> roles = getUserRoles(uRole.getUserId(), uRole.getContextId());
        int indx = -1;
        // Does the user have any roles assigned?
        if (roles != null) {
            // function call will set indx to -1 if name not found:
            indx = roles.indexOf(uRole);
            // Is the targeted name assigned to user?
            if (indx > -1) {
                // Retrieve the targeted name:
                UserRole fRole = roles.get(indx);
                // delete the name assignment attribute using the raw name data:
                List<Modification> mods = new ArrayList<Modification>();
                // Remove user role constraints
                for (RoleConstraint rc : fRole.getRoleConstraints()) {
                    this.deassign(fRole, rc);
                }
                mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, GlobalIds.USER_ROLE_DATA, fRole.getRawData()));
                mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, GlobalIds.USER_ROLE_ASSIGN, fRole.getName()));
                ld = getAdminConnection();
                modify(ld, userDn, mods, uRole);
            }
        }
        // target name not found:
        if (indx == -1) {
            // The user does not have the target name assigned,
            String warning = "deassign userId [" + uRole.getUserId() + "] name [" + uRole.getName() + "] " + "assignment does not exist.";
            throw new FinderException(GlobalErrIds.URLE_ASSIGN_NOT_EXIST, warning);
        }
    } catch (LdapException e) {
        String warning = "deassign userId [" + uRole.getUserId() + "] name [" + uRole.getName() + "] caught " + "LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.URLE_DEASSIGN_FAILED, warning, e);
    } finally {
        closeAdminConnection(ld);
    }
    return userDn;
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) FinderException(org.apache.directory.fortress.core.FinderException) UserRole(org.apache.directory.fortress.core.model.UserRole) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 18 with UpdateException

use of org.apache.directory.fortress.core.UpdateException in project directory-fortress-core by apache.

the class UserDAO method assign.

/**
 * @param uRole
 * @return
 * @throws UpdateException
 * @throws FinderException
 */
String assign(UserAdminRole uRole) throws UpdateException, FinderException {
    LdapConnection ld = null;
    String userDn = getDn(uRole.getUserId(), uRole.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        String szUserRole = uRole.getRawData();
        mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, GlobalIds.USER_ADMINROLE_DATA, szUserRole));
        mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, GlobalIds.USER_ADMINROLE_ASSIGN, uRole.getName()));
        ld = getAdminConnection();
        modify(ld, userDn, mods, uRole);
    } catch (LdapAttributeInUseException e) {
        String warning = "assign userId [" + uRole.getUserId() + "] name [" + uRole.getName() + "] assignment " + "already exists.";
        throw new FinderException(GlobalErrIds.ARLE_ASSIGN_EXIST, warning);
    } catch (LdapException e) {
        String warning = "assign userId [" + uRole.getUserId() + "] name [" + uRole.getName() + "] caught " + "LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.ARLE_ASSIGN_FAILED, warning, e);
    } finally {
        closeAdminConnection(ld);
    }
    return userDn;
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) FinderException(org.apache.directory.fortress.core.FinderException) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 19 with UpdateException

use of org.apache.directory.fortress.core.UpdateException in project directory-fortress-core by apache.

the class UserDAO method lock.

/**
 * @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.getMessage();
        throw new UpdateException(GlobalErrIds.USER_PW_LOCK_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 20 with UpdateException

use of org.apache.directory.fortress.core.UpdateException in project directory-fortress-core by apache.

the class UserDAO method deassign.

/**
 * @param uRole
 * @param roleConstraint
 * @throws UpdateException
 * @throws FinderException
 */
void deassign(UserRole uRole, RoleConstraint roleConstraint) throws UpdateException, FinderException {
    LdapConnection ld = null;
    String szRoleConstraint = "";
    String userDn = getDn(uRole.getUserId(), uRole.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        szRoleConstraint = roleConstraint.getRawData(uRole);
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, GlobalIds.USER_ROLE_DATA, szRoleConstraint));
        ld = getAdminConnection();
        modify(ld, userDn, mods, uRole);
    } catch (LdapException e) {
        String warning = "deassign userId [" + uRole.getUserId() + "] role constraint [" + szRoleConstraint + "] ";
        warning += "caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.URLE_ASSIGN_FAILED, warning, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

Modification (org.apache.directory.api.ldap.model.entry.Modification)41 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)41 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)41 ArrayList (java.util.ArrayList)40 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)39 FinderException (org.apache.directory.fortress.core.FinderException)7 LdapAttributeInUseException (org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException)4 LdapNoSuchAttributeException (org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)4 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)3 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)2 UserRole (org.apache.directory.fortress.core.model.UserRole)2 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)1 CreateException (org.apache.directory.fortress.core.CreateException)1 PasswordException (org.apache.directory.fortress.core.PasswordException)1 RemoveException (org.apache.directory.fortress.core.RemoveException)1 User (org.apache.directory.fortress.core.model.User)1