Search in sources :

Example 6 with UpdateException

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

the class PolicyDAO method update.

/**
 * @param entity
 * @throws org.apache.directory.fortress.core.UpdateException
 */
void update(PwPolicy entity) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (entity.getMinAge() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_MIN_AGE, entity.getMinAge().toString()));
        }
        if (entity.getMaxAge() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_MAX_AGE, entity.getMaxAge().toString()));
        }
        if (entity.getInHistory() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_IN_HISTORY, entity.getInHistory().toString()));
        }
        if (entity.getCheckQuality() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_CHECK_QUALITY, entity.getCheckQuality().toString()));
        }
        if (entity.getMinLength() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_MIN_LENGTH, entity.getMinLength().toString()));
        }
        if (entity.getExpireWarning() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_EXPIRE_WARNING, entity.getExpireWarning().toString()));
        }
        if (entity.getGraceLoginLimit() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_GRACE_LOGIN_LIMIT, entity.getGraceLoginLimit().toString()));
        }
        if (entity.getLockout() != null) {
            /**
             * OpenLDAP requires the boolean values to be upper case:
             */
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_LOCKOUT, entity.getLockout().toString().toUpperCase()));
        }
        if (entity.getLockoutDuration() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_LOCKOUT_DURATION, entity.getLockoutDuration().toString()));
        }
        if (entity.getMaxFailure() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_MAX_FAILURE, entity.getMaxFailure().toString()));
        }
        if (entity.getFailureCountInterval() != null) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_FAILURE_COUNT_INTERVAL, entity.getFailureCountInterval().toString()));
        }
        if (entity.getMustChange() != null) {
            /**
             * OpenLDAP requires the boolean values to be upper case:
             */
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_MUST_CHANGE, entity.getMustChange().toString().toUpperCase()));
        }
        if (entity.getAllowUserChange() != null) {
            /**
             * OpenLDAP requires the boolean values to be upper case:
             */
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_ALLOW_USER_CHANGE, entity.getAllowUserChange().toString().toUpperCase()));
        }
        if (entity.getSafeModify() != null) {
            /**
             * OpenLDAP requires the boolean values to be upper case:
             */
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, PW_SAFE_MODIFY, entity.getSafeModify().toString().toUpperCase()));
        }
        if (mods != null && 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.PSWD_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) 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 7 with UpdateException

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

the class ConfigDAO method update.

/**
 * @param name
 * @param props
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Properties update(String name, Properties props) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("update dn [{}]", dn);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (PropUtil.isNotEmpty(props)) {
            loadProperties(props, mods, GlobalIds.PROPS, true);
        }
        ld = getAdminConnection();
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods);
        }
    } catch (LdapException e) {
        String error = "update dn [" + dn + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.FT_CONFIG_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
Also used : 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 8 with UpdateException

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

the class ConfigDAO method remove.

/**
 * @param name
 * @param props
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Properties remove(String name, Properties props) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("remove props dn [{}]", dn);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (PropUtil.isNotEmpty(props)) {
            removeProperties(props, mods, GlobalIds.PROPS);
        }
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods);
        }
    } catch (LdapException e) {
        String error = "remove props dn [" + dn + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.FT_CONFIG_DELETE_PROPS_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
Also used : 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 9 with UpdateException

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

the class GroupDAO method update.

/**
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
Group update(Group group) throws FinderException, UpdateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());
    try {
        LOG.debug("update group dn [{}]", nodeDn);
        List<Modification> mods = new ArrayList<Modification>();
        if (StringUtils.isNotEmpty(group.getDescription())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, group.getDescription()));
        }
        if (StringUtils.isNotEmpty(group.getProtocol())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol()));
        }
        loadAttrs(group.getMembers(), mods, SchemaConstants.MEMBER_AT);
        loadProperties(group.getProperties(), mods, GROUP_PROPERTY_ATTR_IMPL, true, '=');
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, nodeDn, mods, group);
        }
    } catch (LdapException e) {
        String error = "update group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.GROUP_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return get(group);
}
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 10 with UpdateException

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

the class GroupDAO method deassign.

/**
 * @param entity
 * @param userDn
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Group deassign(Group entity, String userDn) throws FinderException, UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity.getName(), entity.getContextId());
    LOG.debug("deassign group property dn [{}], member dn [{}]", dn, userDn);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, SchemaConstants.MEMBER_AT, userDn));
        ld = getAdminConnection();
        modify(ld, dn, mods, entity);
    } catch (LdapException e) {
        String error = "deassign group name [" + entity.getName() + "] user dn [" + userDn + "] caught " + "LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.GROUP_USER_DEASSIGN_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return get(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