use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class RoleDAO method findAssignedRoles.
/**
* @param userDn
* @param contextId
* @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.ROLE_ROOT);
try {
String filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")";
filter += "(" + SchemaConstants.ROLE_OCCUPANT_AT + "=" + 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.ROLE_OCCUPANT_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findAssignedRoles userDn [" + userDn + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_OCCUPANT_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roleNameList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class RoleDAO method findRoles.
/**
* @param role
* @param limit
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<String> findRoles(Role role, int limit) throws FinderException {
List<String> roleList = new ArrayList<>();
LdapConnection ld = null;
String roleRoot = getRootDn(role.getContextId(), GlobalIds.ROLE_ROOT);
String filter = null;
try {
String searchVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + ROLE_NM + "=" + searchVal + "*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_NM_ATR, false, limit);
while (searchResults.next()) {
Entry entry = searchResults.getEntry();
roleList.add(getAttribute(entry, ROLE_NM));
}
} catch (LdapException e) {
String error = "findRoles filter [" + filter + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findRoles filter [" + filter + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roleList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class RoleP method removeOccupant.
/**
* Remove the User dn occupant attribute from the OrganizationalRole entity in ldap. This method is called by AdminMgrImpl
* when the User is being deleted.
*
* @param userDn contains the userId targeted for attribute removal.
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @throws SecurityException in the event of DAO search error.
*/
void removeOccupant(String userDn, String contextId) throws SecurityException {
List<String> list;
try {
list = rDao.findAssignedRoles(userDn, contextId);
for (String roleNm : list) {
Role role = new Role(roleNm);
role.setContextId(contextId);
deassign(role, userDn);
}
} catch (FinderException fe) {
String error = "removeOccupant userDn [" + userDn + "] caught FinderException=" + fe;
throw new SecurityException(GlobalErrIds.ROLE_REMOVE_OCCUPANT_FAILED, error, fe);
}
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class ExampleDAO method findExamples.
/**
* @param searchVal
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
public List<Example> findExamples(String searchVal) throws FinderException {
List<Example> exampleList = new ArrayList<>();
LdapConnection ld = null;
String exampleRoot = Config.getInstance().getProperty(EIds.EXAMPLE_ROOT);
if (LOG.isDebugEnabled()) {
LOG.debug("findExamples: " + EIds.EXAMPLE_ROOT + " [" + exampleRoot + "]");
}
try {
searchVal = encodeSafeText(searchVal, GlobalIds.ROLE_LEN);
ld = getAdminConnection();
String filter = GlobalIds.FILTER_PREFIX + Arrays.toString(EIds.EXAMPLE_OBJ_CLASS) + ")(" + EIds.EXAMPLE_NM + "=" + searchVal + "*))";
SearchCursor searchResults = search(ld, exampleRoot, SearchScope.SUBTREE, filter, EXAMPLE_ATRS, false, GlobalIds.BATCH_SIZE);
while (searchResults.next()) {
exampleList.add(getEntityFromLdapEntry(searchResults.getEntry()));
}
} catch (LdapException e) {
String error = "findExamples caught LDAPException=" + e;
LOG.warn(error);
throw new FinderException(EErrIds.EXAMPLE_SEARCH_FAILED, error);
} catch (CursorException e) {
String error = "findExamples caught CursorException=" + e;
throw new FinderException(EErrIds.EXAMPLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return exampleList;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class CreateUserOrgSample method testCreateUserOrg.
/**
* Before a User can be added to ldap directory an OrgUnit must be created. The User OrgUnit entity
* supports general hierarchies meaning an OrgUnit can have zero or more parents. The User OrgUnit
* organizational structure is represented logically as a simple directional graph though that
* functionality is not demonstrated here.
*/
public static void testCreateUserOrg() {
String szLocation = ".testCreateUserOrg";
try {
DelReviewMgr dRevAdminMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
// The OrgUnit requires name and type to be set before use.
OrgUnit inOU = new OrgUnit(TEST_USER_OU_NM, OrgUnit.Type.USER);
try {
dRevAdminMgr.read(inOU);
// if org is found, return.
return;
} catch (FinderException fe) {
assertTrue(szLocation + " excep id check", fe.getErrorId() == GlobalErrIds.ORG_NOT_FOUND_USER);
// pass
}
// Instantiate the Delegated AdminMgr implementation object which provisions OrgUnits and AdminRoles to the system.
DelAdminMgr dAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
// Add the OrgUnit to the directory.
dAdminMgr.add(inOU);
// Instantiate the Delegated RevewMgr implementation which interrogates the OrgUnit and AdminRole data.
DelReviewMgr dReviewMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
// Now read the OrgUnit back to make sure it got added OK.
OrgUnit outOU = dReviewMgr.read(inOU);
assertTrue(szLocation + " failed read", inOU.equals(outOU));
LOG.info(szLocation + " [" + outOU.getName() + "] success");
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations