Search in sources :

Example 31 with UpdateException

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

the class PermDAO method revoke.

/**
 * @param pOp
 * @param user
 * @throws org.apache.directory.fortress.core.UpdateException
 *
 * @throws org.apache.directory.fortress.core.FinderException
 */
void revoke(Permission pOp, User user) throws UpdateException, FinderException {
    LdapConnection ld = null;
    String dn = getDn(pOp, pOp.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, USERS, user.getUserId()));
        ld = getAdminConnection();
        modify(ld, dn, mods, pOp);
    } catch (LdapNoSuchAttributeException e) {
        String warning = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] userId [" + user.getUserId() + "] assignment does not exist.";
        throw new FinderException(GlobalErrIds.PERM_USER_NOT_EXIST, warning);
    } catch (LdapException e) {
        String error = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] userId [" + user.getUserId() + "] caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.PERM_REVOKE_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) FinderException(org.apache.directory.fortress.core.FinderException) 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 32 with UpdateException

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

the class PermDAO method updateObj.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
PermObj updateObj(PermObj entity) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity, entity.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (StringUtils.isNotEmpty(entity.getOu())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.OU_AT, entity.getOu()));
        }
        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 (PropUtil.isNotEmpty(entity.getProperties())) {
            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 = "updateObj objName [" + entity.getObjName() + "] 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)

Example 33 with UpdateException

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

the class PropertyDAO method addProperties.

/**
 * 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.getMessage();
        throw new UpdateException(GlobalErrIds.USER_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return propProvider.getEntity(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 34 with UpdateException

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

the class PropertyDAO method deleteProperties.

/**
 * 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.getMessage();
        throw new UpdateException(GlobalErrIds.USER_UPDATE_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) 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 35 with UpdateException

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

the class AdminRoleDAO method update.

/**
 * Update existing AdminRole entity using supplied data.  Required attribute is {@link AdminRole#name}.
 * This data will be stored in the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
 *
 * @param entity record contains AdminRole data.  Null attributes will be ignored.
 * @return input record back to client.
 * @throws UpdateException in the event LDAP errors occur.
 */
AdminRole update(AdminRole entity) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, entity.getDescription()));
        }
        if (CollectionUtils.isNotEmpty(entity.getOccupants())) {
            for (String name : entity.getOccupants()) {
                mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, ROLE_OCCUPANT, name));
            }
        }
        if (entity.isTemporalSet()) {
            String szRawData = ConstraintUtil.setConstraint(entity);
            if (StringUtils.isNotEmpty(szRawData)) {
                mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.CONSTRAINT, szRawData));
            }
        }
        loadAttrs(entity.getOsUSet(), mods, ROLE_OSU);
        loadAttrs(entity.getOsPSet(), mods, ROLE_OSP);
        String szRaw = entity.getRoleRangeRaw();
        if (StringUtils.isNotEmpty(szRaw)) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, ROLE_RANGE, szRaw));
        }
        loadAttrs(entity.getParents(), mods, GlobalIds.PARENT_NODES);
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods, entity);
        }
    } catch (LdapException e) {
        String error = "update name [" + entity.getName() + "] caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.ARLE_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