use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class AccessMgrImplTest method checkAccess.
public static void checkAccess(String msg, String[][] uArray, String[][] oArray, String[][] opArray, String[][] oArrayBad, String[][] opArrayBad) {
LogUtil.logIt(msg);
try {
AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
for (String[] usr : uArray) {
User user = UserTestData.getUser(usr);
Session session = accessMgr.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) + "]", accessMgr.checkAccess(session, goodPerm));
Permission badPerm;
if (StringUtils.isNotEmpty(PermTestData.getObjId(opArrayBad[j]))) {
// with an objectId:
badPerm = new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j]), PermTestData.getObjId(opArrayBad[j]));
} else {
// without an objectId:
badPerm = new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j]));
}
// LOG.warn("Assert False userId [" + user.getUserId() + "], perm: " + badPerm);
// 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]) + "]", accessMgr.checkAccess(session, badPerm));
j++;
}
i++;
}
}
LOG.debug("checkAccess successful");
} catch (SecurityException ex) {
LOG.error("checkAccess: failed with 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 AccessMgrImplTest method sessionPermissionsH.
/**
* @param msg
* @param uArray
* @param oArray
* @param opArray
*/
public static void sessionPermissionsH(String msg, String[][] uArray, String[][] oArray, String[][] opArray) {
LogUtil.logIt(msg);
try {
AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
int i = 0;
for (String[] usr : uArray) {
i++;
User user = UserTestData.getUser(usr);
Session session = accessMgr.createSession(user, false);
assertNotNull(session);
List<Permission> pOps = accessMgr.sessionPermissions(session);
assertNotNull(pOps);
// LOG.warn("sessionPermissionsH list size user [" + user.getUserId() + "] expected len=" +
// (11 - i) * opArray.length + " actual len=" + pOps.size());
assertEquals(CLS_NM + ".sessionPermissionsH failed list size user[" + user.getUserId() + "]", (11 - i) * opArray.length, pOps.size());
// Iterate over objs x ops, see if every expected valid permission is contained within the returned list:
int j = 0;
for (String[] obj : oArray) {
j++;
// positive tests:
if (i == j || i < j) {
int k = 0;
for (String[] op : opArray) {
k++;
Permission validPOp = PermTestData.getOp(PermTestData.getName(obj), op);
assertTrue(CLS_NM + ".sessionPermissionsH failed perm list compare USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", pOps.contains(validPOp));
boolean result = accessMgr.checkAccess(session, new Permission(PermTestData.getName(obj), PermTestData.getName(op)));
assertTrue(CLS_NM + ".sessionPermissionsH failed checkAccess USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", result);
}
} else // negative tests:
{
int k = 0;
for (String[] op : opArray) {
k++;
Permission validPOp = PermTestData.getOp(PermTestData.getName(obj), op);
assertTrue(CLS_NM + ".sessionPermissionsH failed negative perm list compare USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", !pOps.contains(validPOp));
boolean result = accessMgr.checkAccess(session, new Permission(PermTestData.getName(obj), PermTestData.getName(op)));
assertTrue(CLS_NM + ".sessionPermissionsH failed negative checkAccess USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", !result);
}
}
}
}
} catch (SecurityException ex) {
LOG.error("sessionPermissionsH: failed with 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 AccessMgrImplTest method sessionPermissions.
/**
* @param msg
* @param uArray
* @param oArray
* @param opArray
*/
public static void sessionPermissions(String msg, String[][] uArray, String[][] oArray, String[][] opArray) {
LogUtil.logIt(msg);
try {
AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
for (String[] usr : uArray) {
User user = UserTestData.getUser(usr);
Session session = accessMgr.createSession(user, false);
assertNotNull(session);
List<Permission> pOps = accessMgr.sessionPermissions(session);
assertNotNull(pOps);
// There should be objs * ops number of perms in the list returned from sessionPermissions method:
assertEquals(CLS_NM + ".sessionPermissions failed list size user[" + user.getUserId() + "]", oArray.length * opArray.length, pOps.size());
// Iterate over objs x ops, see if every expected valid permission is contained within the returned list:
for (String[] obj : oArray) {
for (String[] op : opArray) {
Permission validPOp = PermTestData.getOp(PermTestData.getName(obj), op);
assertTrue(CLS_NM + ".sessionPermissions failed perm list compare USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", pOps.contains(validPOp));
}
}
}
} catch (SecurityException ex) {
LOG.error("sessionPermissions: failed with 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 AdminMgrImplTest method delUserGrants.
/**
* @param uArray
* @param objArray
* @param opArray
*/
private void delUserGrants(String msg, String[][] uArray, String[][] objArray, String[][] opArray) {
LogUtil.logIt(msg);
Permission pOp = new Permission();
User user = new User();
try {
AdminMgr adminMgr = getManagedAdminMgr();
for (String[] usr : uArray) {
for (String[] obj : objArray) {
for (String[] op : opArray) {
user = new User(UserTestData.getUserId(usr));
pOp = PermTestData.getOp(PermTestData.getName(obj), op);
adminMgr.revokePermission(pOp, user);
LOG.debug("delUserGrants userId [" + user.getUserId() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
}
}
}
} catch (SecurityException ex) {
LOG.error("delUserGrants userId [" + user.getUserId() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] 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 AdminMgrImplTest method updatePermOps.
/**
* @param objArray
* @param opArray
*/
public static void updatePermOps(String msg, String[][] objArray, String[][] opArray, boolean isAdmin) {
LogUtil.logIt(msg);
Permission pOp = new Permission();
try {
AdminMgr adminMgr;
if (isAdmin) {
adminMgr = getManagedAdminMgr();
} else {
adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
}
for (String[] obj : objArray) {
for (String[] op : opArray) {
pOp = PermTestData.getOp(PermTestData.getName(obj), op);
adminMgr.updatePermission(pOp);
LOG.debug("updatePermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] successful");
}
}
} catch (SecurityException ex) {
LOG.error("updatePermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations