use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class CreatePermOrgSample method testCreatePermOrg.
/**
* Create a new Permission OrgUnit entity in LDAP. The Permission OrgUnit entity must have the
* OrgUnit name and the OrgUnit type set before being added.
*/
public static void testCreatePermOrg() {
String szLocation = ".testCreatePermOrg";
try {
DelReviewMgr dRevAdminMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
// The OrgUnit requires name and type to be set before use.
OrgUnit inOU = new OrgUnit(TEST_PERM_OU_NM, OrgUnit.Type.PERM);
try {
dRevAdminMgr.read(inOU);
// if org is found, return.
return;
} catch (FinderException fe) {
assertTrue(szLocation + " excep id check", fe.getErrorId() == GlobalErrIds.ORG_NOT_FOUND_PERM);
// 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());
}
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class ExampleDAO method findByKey.
/**
* @param name
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
public Example findByKey(String name) throws FinderException {
Example entity = null;
LdapConnection ld = null;
String dn = SchemaConstants.CN_AT + "=" + name + "," + Config.getInstance().getProperty(EIds.EXAMPLE_ROOT);
if (LOG.isDebugEnabled()) {
LOG.debug("findByKey dn [" + dn + "]");
}
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, EXAMPLE_ATRS);
entity = getEntityFromLdapEntry(findEntry);
if (entity == null) {
String error = "findByKey could not find entry for example name [" + name + "]";
LOG.error(error);
throw new FinderException(EErrIds.EXAMPLE_NOT_FOUND, error);
}
} catch (LdapNoSuchObjectException e) {
String error = "findByKey COULD NOT FIND ENTRY for example name [" + name + "]";
throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, error);
} catch (LdapException e) {
String error = "findByKey name [" + name + "] caught LDAPException=" + e;
LOG.warn(error);
throw new FinderException(EErrIds.EXAMPLE_READ_FAILED, error);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class CreateRoleSample method testDeleteRoles.
/**
* Remove the Role from the directory. Role removal will trigger automatic deassignment from all Users or revocation of Permission as well.
*/
public static void testDeleteRoles() {
String szLocation = ".testDeleteRoles";
if (AllSamplesJUnitTest.isFirstRun()) {
return;
}
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
for (int i = 1; i < 11; i++) {
// The key that must be set to locate any Role is simply the name.
Role inRole = new Role(TEST_ROLE_PREFIX + i);
// Remove the Role from directory along with associated assignments:
adminMgr.deleteRole(inRole);
// Instantiate the ReviewMgr implementation which is used to interrogate RBAC policy information.
ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
try {
// this should fail because the Role was deleted above:
reviewMgr.readRole(inRole);
fail(szLocation + " role [" + inRole.getName() + "] delete failed");
} catch (FinderException se) {
assertTrue(szLocation + " excep id check", se.getErrorId() == GlobalErrIds.ROLE_NOT_FOUND);
// pass
}
LOG.info(szLocation + " role [" + inRole.getName() + "] success");
}
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class CreatePermOrgSample method testCreatePermOrg2.
/**
*/
public static void testCreatePermOrg2() {
String szLocation = ".testCreatePermOrg2";
try {
DelReviewMgr dRevAdminMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
// The OrgUnit requires name and type to be set before use.
OrgUnit inOU = new OrgUnit(TEST_PERM_OU_NM2, OrgUnit.Type.PERM);
try {
dRevAdminMgr.read(inOU);
// if org is found, return.
return;
} catch (FinderException fe) {
assertTrue(szLocation + " excep id check", fe.getErrorId() == GlobalErrIds.ORG_NOT_FOUND_PERM);
// 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());
}
}
use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class SdDAO method search.
/**
* @param roles
* @param sdSet
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
Set<SDSet> search(Set<String> roles, SDSet sdSet) throws FinderException {
Set<SDSet> sdList = new HashSet<>();
LdapConnection ld = null;
String ssdRoot = getSdRoot(sdSet.getContextId());
String objectClass = SSD_OBJECT_CLASS_NM;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
objectClass = DSD_OBJECT_CLASS_NM;
}
try {
if (CollectionUtils.isNotEmpty(roles)) {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(objectClass);
filterbuf.append(")(|");
for (String rle : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(rle);
filterbuf.append(")");
}
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filterbuf.toString(), SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
}
}
} catch (LdapException e) {
String error = "search type [" + sdSet.getType() + "] caught LdapException=" + e.getMessage();
int errCode;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} catch (CursorException e) {
String error = "search type [" + sdSet.getType() + "] caught CursorException=" + e.getMessage();
int errCode;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return sdList;
}
Aggregations