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