use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class ReviewMgrImplTest method userPermissions.
/**
* @param msg
* @param uArray
* @param pObjArray
* @param pOpArray
*/
public static void userPermissions(String msg, String[][] uArray, String[][] pObjArray, String[][] pOpArray) {
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] usr : uArray) {
User user = UserTestData.getUser(usr);
List<Permission> perms = reviewMgr.userPermissions(user);
assertNotNull(perms);
assertTrue(CLS_NM + "userPermissions list size check", pOpArray.length * pObjArray.length == perms.size());
for (String[] obj : pObjArray) {
for (String[] op : pOpArray) {
int indx = perms.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
if (indx != -1) {
Permission pOp = perms.get(indx);
assertNotNull(pOp);
PermTestData.assertEquals(PermTestData.getName(obj), pOp, op);
LOG.debug("userPermissions userId [" + user.getUserId() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] successful");
} else {
msg = "userPermissions userId [" + user.getUserId() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] failed list search";
LogUtil.logIt(msg);
fail(msg);
}
}
}
}
} catch (SecurityException ex) {
LOG.error("userPermissions caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class ReviewMgrImplTest method rolePermissions.
/**
* @param msg
* @param rArray
* @param pObjArray
* @param pOpArray
*/
public static void rolePermissions(String msg, String[][] rArray, String[][] pObjArray, String[][] pOpArray) {
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] rle : rArray) {
Role role = RoleTestData.getRole(rle);
List<Permission> perms = reviewMgr.rolePermissions(role);
assertNotNull(perms);
assertTrue(CLS_NM + "rolePermissions list size check", pOpArray.length * pObjArray.length == perms.size());
for (String[] obj : pObjArray) {
for (String[] op : pOpArray) {
int indx = perms.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
if (indx != -1) {
Permission pOp = perms.get(indx);
assertNotNull(pOp);
PermTestData.assertEquals(PermTestData.getName(obj), pOp, op);
LOG.debug("rolePermissions role name [" + role.getName() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] successful");
} else {
msg = "rolePermissions role name [" + role.getName() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] failed list search";
LogUtil.logIt(msg);
fail(msg);
}
}
}
}
} catch (SecurityException ex) {
LOG.error("rolePermissions caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class TestAccelerator method testCheckAccess.
@Test
public void testCheckAccess() {
AccelMgr accelMgr = null;
LOG.info("testCheckAccess...");
User user = new User();
user.setUserId("rbacuser1");
user.setPassword("secret");
// user.setRole( "rbacrole1" );
// user.setRole( "rbacrole2" );
Session session = null;
try {
accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
session = accelMgr.createSession(user, false);
assertNotNull(session);
} catch (SecurityException se) {
se.printStackTrace();
fail();
}
try {
// positive test case:
Permission perm = new Permission();
perm.setObjName("/impl/cal2.jsp");
// perm.setObjId( "123456" );
perm.setOpName("8am");
boolean result = accelMgr.checkAccess(session, perm);
assertTrue(result);
// negative test case:
perm.setOpName("9am");
result = accelMgr.checkAccess(session, perm);
assertTrue(!result);
} catch (SecurityException se) {
se.printStackTrace();
fail();
}
}
use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class Options method getPermission.
public Permission getPermission() {
Permission perm = new Permission();
perm.setObjName(getName());
perm.setOpName(getOpName());
updateRoleAssigns(perm);
updateProperties(perm);
perm.setType(getType());
return perm;
}
use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class AccelMgrImplTest method checkAccess.
/**
* @param msg
* @param uArray
* @param oArray
* @param opArray
* @param oArrayBad
* @param opArrayBad
*/
public static void checkAccess(String msg, String[][] uArray, String[][] oArray, String[][] opArray, String[][] oArrayBad, String[][] opArrayBad) {
LogUtil.logIt(msg);
try {
AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
for (String[] usr : uArray) {
User user = UserTestData.getUser(usr);
Session session = accelMgr.createSession(user, false);
assertNotNull(session);
int i = 0;
for (String[] obj : oArray) {
int j = 0;
for (String[] op : opArray) {
Permission goodPerm;
if (StringUtils.isNotEmpty(PermTestData.getObjId(opArray[j]))) {
// with an objectId:
goodPerm = new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(opArray[j]));
} else {
// without an objectId:
goodPerm = new Permission(PermTestData.getName(obj), PermTestData.getName(op));
}
// Positive test case, call checkAccess method, should return 'true':
assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "]", accelMgr.checkAccess(session, goodPerm));
Permission badPerm = new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j]), PermTestData.getObjId(opArrayBad[j]));
// Negative test case, call checkAccess method again, should return 'false':
assertFalse(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(oArrayBad[i]) + "] operationName [" + PermTestData.getName(opArrayBad[j]) + "]", accelMgr.checkAccess(session, badPerm));
j++;
}
i++;
}
accelMgr.deleteSession(session);
}
LOG.debug("checkAccess successful");
} catch (SecurityException ex) {
LOG.error("checkAccess: failed with SecurityException rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations