Search in sources :

Example 66 with Permission

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());
    }
}
Also used : ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 67 with Permission

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());
    }
}
Also used : ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 68 with Permission

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());
    }
}
Also used : ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 69 with Permission

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());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) PermObj(org.apache.directory.fortress.core.model.PermObj) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 70 with Permission

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;
}
Also used : org.apache.directory.fortress.core(org.apache.directory.fortress.core) Permission(org.apache.directory.fortress.core.model.Permission) SampleResult(org.apache.jmeter.samplers.SampleResult) SecurityException(org.apache.directory.fortress.core.SecurityException)

Aggregations

Permission (org.apache.directory.fortress.core.model.Permission)99 SecurityException (org.apache.directory.fortress.core.SecurityException)58 Role (org.apache.directory.fortress.core.model.Role)24 User (org.apache.directory.fortress.core.model.User)24 AdminMgr (org.apache.directory.fortress.core.AdminMgr)18 UserRole (org.apache.directory.fortress.core.model.UserRole)17 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)16 Session (org.apache.directory.fortress.core.model.Session)12 FortRequest (org.apache.directory.fortress.core.model.FortRequest)11 FortResponse (org.apache.directory.fortress.core.model.FortResponse)11 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)11 ArrayList (java.util.ArrayList)10 FinderException (org.apache.directory.fortress.core.FinderException)10 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)9 AdminRole (org.apache.directory.fortress.core.model.AdminRole)9 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)9 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)9 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)7 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)7 AccessMgr (org.apache.directory.fortress.core.AccessMgr)7