use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.
the class ReviewMgrImplTest method readUsers.
/**
* @param msg
* @param uArray
*/
public static void readUsers(String msg, String[][] uArray) {
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] usr : uArray) {
User entity = reviewMgr.readUser(new User(UserTestData.getUserId(usr)));
assertNotNull(entity);
UserTestData.assertEquals(entity, usr);
LOG.debug("readUsers userId [" + entity.getUserId() + "] successful");
}
} catch (SecurityException ex) {
LOG.error("readUsers caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.
the class ReviewMgrImplTest method readPermissionOps.
/**
* @param msg
* @param pObjArray
* @param pOpArray
*/
public static void readPermissionOps(String msg, String[][] pObjArray, String[][] pOpArray) {
Permission pOp = new Permission();
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] objs : pObjArray) {
for (String[] ops : pOpArray) {
pOp = new Permission();
pOp.setObjName(PermTestData.getName(objs));
pOp.setOpName(PermTestData.getName(ops));
pOp.setObjId(PermTestData.getObjId(ops));
Permission entity = reviewMgr.readPermission(pOp);
assertNotNull(entity);
PermTestData.assertEquals(PermTestData.getName(objs), entity, ops);
LOG.debug("readPermissionOps object name [" + pOp.getObjName() + "] operation name [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] successful");
}
}
} catch (SecurityException ex) {
LOG.error("readPermissionOps object name [" + pOp.getObjName() + "] operation name [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage() + ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.ReviewMgr 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.ReviewMgr in project directory-fortress-core by apache.
the class CreateUserSample method testCreateUser.
/**
* Demonstrate how to create a simple user and assign to a single RBAC Role in one API call. The example will
* also read the User back from LDAP after creation but this is not required for real world examples.
*/
public static void testCreateUser() {
String szLocation = ".testCreateUser";
try {
// Instantiate the AdminMgr implementation. All AdminMgr APIs can throw a SecurityException in the event
// of rule violation or system error.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// You do not have to assign a Role to User when calling 'addUser'. Role assignment may be done using the 'assignUser' API.
/**
* Create new User entity:
* {@link org.apache.directory.fortress.core.model.User#userId}="sampleUser1"
* {@link User#password}="password1"
* {@link User#setRole(String)}="sampleRole1"
* {@link User#ou}="sampleUserOU1"
*/
// User inUser = new User(TEST_USERID, TEST_PASSWORD, CreateRoleSample.TEST_SIMPLE_ROLE, CreateUserOrgSample.TEST_USER_OU_NM);
// User inUser = new User(TEST_USERID, TEST_PASSWORD, CreateRoleSample.TEST_SIMPLE_ROLE, CreateUserOrgSample.TEST_USER_OU_NM);
User inUser = new User(TEST_USERID, TEST_PASSWORD);
inUser.setOu(CreateUserOrgSample.TEST_USER_OU_NM);
// Now call the add API. The API will return User entity with associated LDAP dn if creation was successful.
User outUser = adminMgr.addUser(inUser);
assertNotNull(outUser);
// Instantiate the ReviewMgr implementation which is used to interrogate policy information.
ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
// now read the newly created User entity back:
User outUser2 = reviewMgr.readUser(inUser);
assertTrue(szLocation + " failed read", inUser.equals(outUser2));
LOG.info(szLocation + " user [" + outUser2.getUserId() + "] 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.ReviewMgr in project directory-fortress-core by apache.
the class LoadTestUserSample method teardownRequired.
/**
* Determines if teardown needs to occur on sample data.
*
* @return true if teardown is required
*/
static boolean teardownRequired() {
// The default for this check is 'true'
boolean tearDown = true;
String methodName = ".teardownRequired";
try {
ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
User inUser = new User(TEST_USERID + 1, TEST_PASSWORD);
reviewMgr.readUser(inUser);
// If we get here, the sample data needs to be removed:
} catch (SecurityException ex) {
if (ex.getErrorId() == GlobalErrIds.USER_NOT_FOUND) {
// If we get here the sample data does not need to be removed:
tearDown = false;
} else {
String warning = methodName + " caught SecurityException=" + ex.getMessage();
LOG.warn(warning);
}
}
LOG.info(methodName + ":" + tearDown);
return tearDown;
}
Aggregations