use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class ReviewMgrImplTest method permissionRoles.
/**
* @param msg
* @param pObjArray
* @param pOpArray
* @param rArray
*/
public static void permissionRoles(String msg, String[][] pObjArray, String[][] pOpArray, String[][] rArray) {
LogUtil.logIt(msg);
Permission pOp;
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] obj : pObjArray) {
for (String[] op : pOpArray) {
pOp = new Permission();
pOp.setObjName(PermTestData.getName(obj));
pOp.setOpName(PermTestData.getName(op));
pOp.setObjId(PermTestData.getObjId(op));
List<String> roles = reviewMgr.permissionRoles(pOp);
assertNotNull(roles);
assertTrue(CLS_NM + "permissionRoles permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", rArray.length == roles.size());
for (String[] rle : rArray) {
int indx = roles.indexOf(RoleTestData.getName(rle));
if (indx != -1) {
String roleNm = roles.get(indx);
assertEquals(CLS_NM + ".permissionRoles failed compare role name", RoleTestData.getName(rle), roleNm);
LOG.debug(".permissionRoles permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] roleNm [" + roleNm + "] successful");
} else {
msg = "permissionRoles permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] role [" + RoleTestData.getName(rle) + "] failed list search";
LogUtil.logIt(msg);
fail(msg);
}
}
}
}
} catch (SecurityException ex) {
LOG.error("permissionRoles 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 permissionUsers.
/**
* @param msg
* @param pObjArray
* @param pOpArray
* @param uArray
*/
public static void permissionUsers(String msg, String[][] pObjArray, String[][] pOpArray, String[][] uArray) {
LogUtil.logIt(msg);
Permission pOp;
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
for (String[] obj : pObjArray) {
for (String[] op : pOpArray) {
pOp = new Permission();
pOp.setObjName(PermTestData.getName(obj));
pOp.setOpName(PermTestData.getName(op));
pOp.setObjId(PermTestData.getObjId(op));
List<String> users = reviewMgr.permissionUsers(pOp);
assertNotNull(users);
assertTrue(CLS_NM + "permissionUsers permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", uArray.length == users.size());
for (String[] usr : uArray) {
int indx = users.indexOf(RoleTestData.getName(usr));
if (indx != -1) {
String userId = users.get(indx);
assertEquals(CLS_NM + ".permissionUsers failed compare userId", UserTestData.getUserId(usr), userId);
LOG.debug("permissionUsers permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] userId [" + userId + "] successful");
} else {
msg = "permissionUsers permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] userId [" + UserTestData.getUserId(usr) + "] failed list search";
LogUtil.logIt(msg);
fail(msg);
}
}
}
}
} catch (SecurityException ex) {
LOG.error("permissionUsers 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 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.model.Permission 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());
}
}
use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.
the class CheckAccess method runTest.
/**
*224
* Description of the Method
*
* @param samplerContext Description of the Parameter
* @return Description of the Return Value
*/
public SampleResult runTest(JavaSamplerContext samplerContext) {
SampleResult sampleResult = new SampleResult();
try {
int opCount = ++ctr % 10;
if (opCount == 0)
opCount = 10;
int objCount = (ctr / 10) + 1;
if (objCount > 10) {
objCount = objCount % 10;
}
if (objCount == 0) {
objCount = 1;
}
// int objCount = ((ctr / 10) + 1) % 10;
String opName = "oper" + opCount;
String objName = "loadtestobject" + objCount;
sampleResult.sampleStart();
String message;
if (isFortress) {
message = "FT ";
} else {
message = "AC ";
}
message += "CheckAccess isFortress: " + isFortress + ", userId: " + userId + ", objName:" + objName + ", opName: " + opName;
/*
LOG.info( message );
System.out.println( message );
*/
assertNotNull(session);
assertTrue(session.isAuthenticated());
Permission perm = new Permission();
perm.setObjName(objName);
perm.setOpName(opName);
boolean result;
if (isFortress) {
assertNotNull(accessMgr);
result = accessMgr.checkAccess(session, perm);
} else {
assertNotNull(accelMgr);
result = accelMgr.checkAccess(session, perm);
}
// positive test case:
assertTrue(message, result);
sampleResult.sampleEnd();
sampleResult.setBytes(1);
sampleResult.setResponseMessage("test checkAccess completed");
sampleResult.setSuccessful(true);
} catch (org.apache.directory.fortress.core.SecurityException se) {
String error = "ThreadId:" + getThreadId() + "Error running test: " + se;
LOG.error(error);
System.out.println(error);
se.printStackTrace();
fail(error);
sampleResult.setSuccessful(false);
}
return sampleResult;
}
Aggregations