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