use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class ReviewMgrImplTest method teardownRequired.
/**
* Determine if old fortress regression test cases are loaded in this directory and must be torn down.
*
* @param msg
* @param rArray
*/
public static boolean teardownRequired(String msg, String[][] rArray) {
// default return is 'true':
boolean tearDown = true;
String methodName = ".teardownRequired";
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] rle : rArray) {
Role entity = reviewMgr.readRole(new Role(RoleTestData.getName(rle)));
RoleTestData.assertEquals(entity, rle);
}
// if we get to here it means that old test data must be removed from directory.
} catch (SecurityException ex) {
// This is the expected when teardown is not required:
if (ex.getErrorId() == GlobalErrIds.ROLE_NOT_FOUND) {
// did not find old test data no need to teardown
tearDown = false;
} else {
// Something unexpected occurred here, Report as warning to the logger:
String warning = methodName + " caught SecurityException=" + ex.getMessage();
LOG.warn(warning);
// TODO: Determine if it would be better to throw a SecurityException here.
}
}
LOG.info(methodName + ":" + tearDown);
return tearDown;
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class ReviewMgrImplTest method authorizedUsersHier.
/**
* @param msg
* @param roleMap
*/
public static void authorizedUsersHier(String msg, Map roleMap) {
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
// iterate over every role entry found in map:
for (Object o : roleMap.entrySet()) {
Map.Entry pairs = (Map.Entry) o;
String roleName = (String) pairs.getKey();
String szValidUsers = (String) pairs.getValue();
Set<String> userSet = TestUtils.getSets(szValidUsers);
assertNotNull(userSet);
assertTrue(userSet.size() > 0);
List<User> actualUsers = reviewMgr.authorizedUsers(new Role(roleName));
assertNotNull(actualUsers);
assertTrue(actualUsers.size() > 0);
// Ensure the two list sizes match or fail the test case.
assertTrue(CLS_NM + "authorizedUsersHier failed list size test case", userSet.size() == actualUsers.size());
// for each valid user expected, ensure it actually pulled from API:
for (String userId : userSet) {
User validUser = new User(userId);
assertTrue(CLS_NM + ".authorizedUsersHier failed authorizedUsers test, role [" + roleName + "] does not have user [" + validUser.getUserId() + "] as authorized", actualUsers.contains(validUser));
}
}
} catch (SecurityException ex) {
LOG.error("authorizedUsersHier caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class RoleTestData method getRoleConstraint.
/**
* @param rle
* @return
*/
public static Constraint getRoleConstraint(String[] rle) {
Role role = new Role();
role.setBeginDate(getBeginDate(rle));
role.setEndDate(getEndDate(rle));
role.setBeginLockDate(getBeginLockDate(rle));
role.setEndLockDate(getEndLockDate(rle));
role.setBeginTime(getBeginTime(rle));
role.setEndTime(getEndTime(rle));
role.setDayMask(getDayMask(rle));
role.setTimeout(getTimeOut(rle));
return role;
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class RoleTestData method getRole.
/**
* @param rle
* @return
*/
public static Role getRole(String[] rle) {
Role role = (Role) getRoleConstraint(rle);
role.setName(getName(rle));
role.setDescription(getDescription(rle));
return role;
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class CreatePermSample method testAddShoppingCartObjects.
/**
*/
public static void testAddShoppingCartObjects() {
String szLocation = ".testAddShoppingCartObjects";
try {
// Instantiate the AdminMgr first
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// Now Instantiate the Object
PermObj shoppingCart = new PermObj("ShoppingCart", "KillerBikes.com");
// Add it to the directory
adminMgr.addPermObj(shoppingCart);
// Now create the permission operations and grant...
Permission create = new Permission(shoppingCart.getObjName(), "create");
adminMgr.addPermission(create);
adminMgr.grantPermission(create, new Role("Customer"));
Permission read = new Permission(shoppingCart.getObjName(), "read");
adminMgr.addPermission(read);
adminMgr.grantPermission(read, new Role("Customer"));
Permission update = new Permission(shoppingCart.getObjName(), "update");
adminMgr.addPermission(update);
adminMgr.grantPermission(update, new Role("Admin"));
Permission delete = new Permission(shoppingCart.getObjName(), "delete");
adminMgr.addPermission(delete);
adminMgr.grantPermission(delete, new Role("Manager"));
Permission checkout = new Permission(shoppingCart.getObjName(), "checkout");
adminMgr.addPermission(checkout);
adminMgr.grantPermission(delete, new Role("Customer"));
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations