Search in sources :

Example 21 with UpdateException

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

the class RoleDAO method deleteParent.

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

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

the class RoleDAO method assign.

/**
 * @param entity
 * @param userDn
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Role assign(Role entity, String userDn) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity.getName(), entity.getContextId());
    try {
        // ld = getAdminConnection();
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, SchemaConstants.ROLE_OCCUPANT_AT, userDn));
        ld = getAdminConnection();
        modify(ld, dn, mods, entity);
    } catch (LdapException e) {
        String error = "assign role name [" + entity.getName() + "] user dn [" + userDn + "] caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.ROLE_USER_ASSIGN_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 23 with UpdateException

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

the class ExampleDAO method update.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
public Example update(Example entity) throws UpdateException {
    LdapConnection ld = null;
    String dn = SchemaConstants.CN_AT + "=" + entity.getName() + "," + Config.getInstance().getProperty(EIds.EXAMPLE_ROOT);
    if (LOG.isDebugEnabled()) {
        LOG.debug("update dn [" + dn + "]");
    }
    try {
        ld = getAdminConnection();
        List<Modification> mods = new ArrayList<Modification>();
        if (entity.getDescription() != null && entity.getDescription().length() > 0) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, entity.getDescription()));
        }
        String szRawData = ConstraintUtil.setConstraint(entity);
        if (szRawData != null && szRawData.length() > 0) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.CONSTRAINT, szRawData));
        }
        if (mods.size() > 0) {
            modify(ld, dn, mods);
        }
    } catch (LdapException e) {
        String error = "update [" + entity.getName() + "] caught LDAPException=" + e;
        LOG.error(error);
        throw new UpdateException(EErrIds.EXAMPLE_UPDATE_FAILED, error);
    } 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 24 with UpdateException

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

the class SdDAO method update.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
SDSet update(SDSet entity) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity.getName(), entity.getContextId());
    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 (entity.getCardinality() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SD_SET_CARDINALITY, entity.getCardinality().toString()));
        }
        loadAttrs(entity.getMembers(), mods, ROLES);
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods, entity);
        }
    } catch (LdapException e) {
        String error = "update name [" + entity.getName() + "] type [" + entity.getType() + "] caught LdapException=" + e.getMessage();
        int errCode;
        if (entity.getType() == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_UPDATE_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_UPDATE_FAILED;
        }
        throw new UpdateException(errCode, 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 25 with UpdateException

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

the class UserDAO method deleteResetFlag.

/**
 *1     * @param user
 * @throws UpdateException
 */
private void deleteResetFlag(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_PW_RESET));
        ld = getAdminConnection();
        modify(ld, userDn, mods, user);
    } catch (LdapNoSuchAttributeException e) {
        // Log, but don't throw, if reset attribute not present on account.
        LOG.info("deleteResetFlag user [" + user.getUserId() + "] no such attribute:" + OPENLDAP_PW_RESET);
    } catch (LdapException e) {
        String warning = "deleteResetFlag userId [" + user.getUserId() + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.USER_PW_RESET_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) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

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