Search in sources :

Example 26 with UpdateException

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

the class UserDAO method deletePwPolicy.

/**
 * @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.getMessage() + " msg=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.USER_PW_PLCY_DEL_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) 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 27 with UpdateException

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

the class UserDAO method update.

/**
 * @param entity
 * @return
 * @throws UpdateException
 */
User update(User entity) throws UpdateException {
    LdapConnection ld = null;
    String userDn = getDn(entity.getUserId(), entity.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (StringUtils.isNotEmpty(entity.getCn())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.CN_AT, entity.getCn()));
        }
        if (StringUtils.isNotEmpty(entity.getSn())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.SN_AT, entity.getSn()));
        }
        if (StringUtils.isNotEmpty(entity.getOu())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.OU_AT, entity.getOu()));
        }
        if (StringUtils.isNotEmpty(entity.getPassword())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.USER_PASSWORD_AT, entity.getPassword()));
        }
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, entity.getDescription()));
        }
        if (StringUtils.isNotEmpty(entity.getEmployeeType())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, EMPLOYEE_TYPE, entity.getEmployeeType()));
        }
        if (StringUtils.isNotEmpty(entity.getTitle())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.TITLE_AT, entity.getTitle()));
        }
        // If password policy is set and either openldap or apacheds in use:
        if ((Config.getInstance().isOpenldap() || Config.getInstance().isApacheds()) && StringUtils.isNotEmpty(entity.getPwPolicy())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, OPENLDAP_POLICY_SUBENTRY, PolicyDAO.getPolicyDn(entity)));
        }
        if (entity.isSystem() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SYSTEM_USER, entity.isSystem().toString().toUpperCase()));
        }
        if (entity.isTemporalSet()) {
            // map the userid to the name field in constraint:
            entity.setName(entity.getUserId());
            String szRawData = ConstraintUtil.setConstraint(entity);
            if (StringUtils.isNotEmpty(szRawData)) {
                mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.CONSTRAINT, szRawData));
            }
        }
        if (PropUtil.isNotEmpty(entity.getProperties())) {
            loadProperties(entity.getProperties(), mods, GlobalIds.PROPS, true);
        }
        loadAddress(entity.getAddress(), mods);
        // These are multi-valued attributes, use the util function to load:
        loadAttrs(entity.getPhones(), mods, SchemaConstants.TELEPHONE_NUMBER_AT);
        loadAttrs(entity.getMobiles(), mods, MOBILE);
        loadAttrs(entity.getEmails(), mods, SchemaConstants.MAIL_AT);
        if (ArrayUtils.isNotEmpty(entity.getJpegPhoto())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, JPEGPHOTO, entity.getJpegPhoto()));
        }
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, userDn, mods, entity);
            entity.setDn(userDn);
        }
        entity.setDn(userDn);
    } catch (LdapException e) {
        String error = "update userId [" + entity.getUserId() + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.USER_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
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 28 with UpdateException

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

the class UserDAO method updateProps.

/**
 * @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.getMessage();
        throw new UpdateException(GlobalErrIds.USER_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) 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 29 with UpdateException

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

the class PermDAO method grant.

/**
 * @param pOp
 * @param role
 * @throws org.apache.directory.fortress.core.UpdateException
 *
 * @throws org.apache.directory.fortress.core.FinderException
 */
void grant(Permission pOp, Role role) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(pOp, pOp.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, ROLES, role.getName()));
        ld = getAdminConnection();
        modify(ld, dn, mods, pOp);
    } catch (LdapAttributeInUseException e) {
        String warning = "grant perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] role [" + role.getName() + "] assignment already exists, Fortress rc=" + GlobalErrIds.PERM_ROLE_EXIST;
        throw new UpdateException(GlobalErrIds.PERM_ROLE_EXIST, warning);
    } catch (LdapNoSuchObjectException e) {
        String warning = "grant perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] role [" + role.getName() + "] perm not found, Fortress rc=" + GlobalErrIds.PERM_OP_NOT_FOUND;
        throw new UpdateException(GlobalErrIds.PERM_OP_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "grant perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] name [" + role.getName() + "]  caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.PERM_GRANT_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) 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) 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 30 with UpdateException

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

the class PermDAO method updateOperation.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Permission updateOperation(Permission entity) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity, entity.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (StringUtils.isNotEmpty(entity.getAbstractName())) {
            // the abstract name is the human readable identifier:
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PERM_NAME, entity.getAbstractName()));
        }
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, entity.getDescription()));
        }
        if (StringUtils.isNotEmpty(entity.getType())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.TYPE, entity.getType()));
        }
        if (CollectionUtils.isNotEmpty(entity.getPaSets())) {
            for (String paSetName : entity.getPaSets()) {
                mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PERMISSION_ATTRIBUTE_SET, paSetName));
            }
        }
        // These are multi-valued attributes, use the util function to load:
        loadAttrs(entity.getRoles(), mods, ROLES);
        loadAttrs(entity.getUsers(), mods, USERS);
        loadProperties(entity.getProperties(), mods, GlobalIds.PROPS, true);
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods, entity);
            entity.setDn(dn);
        }
    } catch (LdapException e) {
        String error = "updateOperation objName [" + entity.getObjName() + "] opName [" + entity.getOpName() + "] caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.PERM_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
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