use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class AdminMgrImplTest method addRoleGrantsHB.
/**
* @param msg
* @param rArray
* @param objArray
* @param opArray
*/
public static void addRoleGrantsHB(String msg, String[][] uArray, String[][] rArray, String[][] objArray, String[][] opArray) {
LogUtil.logIt(msg);
try {
AdminMgr adminMgr = getManagedAdminMgr();
for (String[] obj : objArray) {
int i = 0;
for (String[] rle : rArray) {
// Get Role[i] from test data:
Role role = RoleTestData.getRole(rle);
// Get Permission[i] from test data:
String[] op = opArray[i];
// Load the Permission entity with data:
Permission pOp = PermTestData.getOp(PermTestData.getName(obj), op);
// Grant Permission[i] to Role[i]:
adminMgr.grantPermission(pOp, role);
// Get User[i] from test data:
String[] usr = uArray[i];
// Load the User entity with data:
User user = UserTestData.getUser(usr);
// Grant Permission[i] to User[i]:
adminMgr.grantPermission(pOp, user);
i++;
LOG.debug("addRoleGrantsHB userId [" + user.getUserId() + "] role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
}
}
} catch (SecurityException ex) {
LOG.error("addRoleGrantsHB 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 delRoleGrants.
/**
* @param rArray
* @param objArray
* @param opArray
*/
public static void delRoleGrants(String msg, String[][] rArray, String[][] objArray, String[][] opArray, boolean isAdmin) {
LogUtil.logIt(msg);
Permission pOp = new Permission();
Role role = new Role();
try {
AdminMgr adminMgr;
if (isAdmin) {
adminMgr = getManagedAdminMgr();
} else {
adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
}
for (String[] rle : rArray) {
for (String[] obj : objArray) {
for (String[] op : opArray) {
role = new Role(RoleTestData.getName(rle));
pOp = PermTestData.getOp(PermTestData.getName(obj), op);
adminMgr.revokePermission(pOp, role);
LOG.debug("delRoleGrants role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
}
}
}
} catch (SecurityException ex) {
LOG.error("delRoleGrants role name [" + role.getName() + "] 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 delPermOps.
/**
* @param objArray
* @param opArray
*/
public static void delPermOps(String msg, String[][] objArray, String[][] opArray, boolean isAdmin, boolean canFail) {
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.deletePermission(pOp);
LOG.debug("delPermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] successful");
}
}
} catch (SecurityException ex) {
if (!canFail) {
LOG.error("delPermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] 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 delRoleGrantsHB.
/**
* @param msg
* @param rArray
* @param objArray
* @param opArray
*/
private void delRoleGrantsHB(String msg, String[][] uArray, String[][] rArray, String[][] objArray, String[][] opArray) {
LogUtil.logIt(msg);
try {
AdminMgr adminMgr = getManagedAdminMgr();
for (String[] obj : objArray) {
int i = 0;
for (String[] rle : rArray) {
// Get Role[i] from test data:
Role role = RoleTestData.getRole(rle);
// Get Permission[i] from test data:
String[] op = opArray[i];
// Load the permission entity with data:
Permission pOp = PermTestData.getOp(PermTestData.getName(obj), op);
// Grant Permission[i] to Role[i]:
adminMgr.revokePermission(pOp, role);
// Get User[i] from test data:
String[] usr = uArray[i];
// Load the User entity with data:
User user = UserTestData.getUser(usr);
// Grant Permission[i] to User[i]:
adminMgr.revokePermission(pOp, user);
i++;
LOG.debug("delRoleGrantsHB userId [" + user.getUserId() + "] role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
}
}
} catch (SecurityException ex) {
LOG.error("delRoleGrantsHB 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 DelegatedMgrImplTest method checkAccess.
public static void checkAccess(String msg, String[][] uArray, String[][] oArray, String[][] opArray, String[][] oArrayBad, String[][] opArrayBad) {
LogUtil.logIt(msg);
try {
DelAccessMgr dAccessMgr = DelAccessMgrFactory.createInstance(TestUtils.getContext());
AccessMgr accessMgr = (AccessMgr) dAccessMgr;
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) {
// Call checkAccess method
assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "]", dAccessMgr.checkAccess(session, new Permission(PermTestData.getName(obj), PermTestData.getName(op))));
j++;
}
i++;
}
i = 0;
for (String[] obj : oArrayBad) {
int j = 0;
for (String[] op : opArrayBad) {
// Call checkAccess method (this should fail):
try {
boolean result = dAccessMgr.checkAccess(session, new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j])));
assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(oArrayBad[i]) + "] operationName [" + PermTestData.getName(opArrayBad[j]) + "]", !result);
} catch (SecurityException se) {
// The expected condition is security exception perm not exist:
assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(oArrayBad[i]) + "] operationName [" + PermTestData.getName(opArrayBad[j]) + "], negative use case, incorrect exception id=" + se.getErrorId(), se.getErrorId() == GlobalErrIds.PERM_NOT_EXIST);
}
j++;
}
i++;
}
}
LOG.debug("checkAccess successful");
} catch (SecurityException ex) {
LOG.error("checkAccess: caught SecurityException rc=" + ex.getErrorId() + ", msg: " + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations