use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class AdminRoleDAO method deassign.
/**
* This method will remove the supplied DN as a role occupant to the target record.
* This data will be stored in the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
*
* @param entity record contains {@link AdminRole#name}. Null attributes will be ignored.
* @param userDn contains the DN for userId who is being deassigned.
* @return input record back to client.
* @throws UpdateException in the event LDAP errors occur.
*/
AdminRole deassign(AdminRole entity, String userDn) throws UpdateException {
LdapConnection ld = null;
String dn = getDn(entity);
try {
List<Modification> mods = new ArrayList<Modification>();
mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, ROLE_OCCUPANT, userDn));
ld = getAdminConnection();
modify(ld, dn, mods, entity);
} catch (LdapException e) {
String error = "deassign role name [" + entity.getName() + "] user dn [" + userDn + "] caught LdapException=" + e.getMessage();
throw new UpdateException(GlobalErrIds.ARLE_USER_DEASSIGN_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class AdminRoleDAO method findAssignedRoles.
/**
* @param userDn
* @return
* @throws FinderException
*/
List<String> findAssignedRoles(String userDn, String contextId) throws FinderException {
List<String> roleNameList = new ArrayList<>();
LdapConnection ld = null;
String roleRoot = getRootDn(contextId, GlobalIds.ADMIN_ROLE_ROOT);
try {
String filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")";
filter += "(" + ROLE_OCCUPANT + "=" + userDn + "))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_NM_ATR, false, GlobalIds.BATCH_SIZE);
while (searchResults.next()) {
roleNameList.add(getAttribute(searchResults.getEntry(), ROLE_NM));
}
} catch (LdapException e) {
String error = "findAssignedRoles userDn [" + userDn + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_OCCUPANT_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findAssignedRoles userDn [" + userDn + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_OCCUPANT_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roleNameList;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class AdminRoleDAO method remove.
/**
* This method will completely remove the AdminRole from the directory. It will use {@link AdminRole#name} as key.
* This operation is performed on the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
*
* @param role record contains {@link AdminRole#name}.
* @throws RemoveException in the event LDAP errors occur.
*/
void remove(AdminRole role) throws RemoveException {
LdapConnection ld = null;
String dn = getDn(role);
try {
ld = getAdminConnection();
delete(ld, dn, role);
} catch (LdapException e) {
String error = "remove role name=" + role.getName() + " LdapException=" + e.getMessage();
throw new RemoveException(GlobalErrIds.ARLE_DELETE_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class AdminRoleDAO method getAllDescendants.
/**
* @param contextId
* @return
* @throws FinderException
*/
List<Graphable> getAllDescendants(String contextId) throws FinderException {
String[] DESC_ATRS = { ROLE_NM, GlobalIds.PARENT_NODES };
List<Graphable> descendants = new ArrayList<>();
LdapConnection ld = null;
String roleRoot = getRootDn(contextId, GlobalIds.ADMIN_ROLE_ROOT);
String filter = null;
try {
filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + GlobalIds.PARENT_NODES + "=*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, DESC_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
descendants.add(unloadDescendants(searchResults.getEntry(), sequence++));
}
} catch (LdapException e) {
String error = "getAllDescendants filter [" + filter + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "getAllDescendants filter [" + filter + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return descendants;
}
use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.
the class PermDAO method createObject.
/**
* @param entity
* @return
* @throws org.apache.directory.fortress.core.CreateException
*/
PermObj createObject(PermObj entity) throws CreateException {
LdapConnection ld = null;
String dn = getDn(entity, entity.getContextId());
try {
Entry entry = new DefaultEntry(dn);
entry.add(SchemaConstants.OBJECT_CLASS_AT, PERM_OBJ_OBJ_CLASS);
entry.add(GlobalIds.POBJ_NAME, entity.getObjName());
// this will generatre a new random, unique id on this entity:
entity.setInternalId();
// create the rDN:
entry.add(GlobalIds.FT_IID, entity.getInternalId());
// ou is required:
entry.add(SchemaConstants.OU_AT, entity.getOu());
// description is optional:
if (StringUtils.isNotEmpty(entity.getDescription())) {
entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
}
// type is optional:
if (StringUtils.isNotEmpty(entity.getType())) {
entry.add(GlobalIds.TYPE, entity.getType());
}
// if the props is null don't try to load these attributes
if (PropUtil.isNotEmpty(entity.getProperties())) {
loadProperties(entity.getProperties(), entry, GlobalIds.PROPS);
}
// now add the new entry to directory:
ld = getAdminConnection();
add(ld, entry, entity);
entity.setDn(dn);
} catch (LdapException e) {
String error = "createObject perm obj [" + entity.getObjName() + "] caught LdapException=" + e.getMessage();
throw new CreateException(GlobalErrIds.PERM_ADD_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
Aggregations