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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations