Search in sources :

Example 61 with Permission

use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.

the class FortressAntLoadTest method readPermissionOps.

/**
 * @param msg
 * @param permissions
 */
private static void readPermissionOps(String msg, List<PermAnt> permissions) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (PermAnt permAnt : permissions) {
            Permission entity = reviewMgr.readPermission(permAnt);
            assertNotNull(entity);
            assertTrue("Failed objName value compare", entity.getObjName().equals(permAnt.getObjName()));
            assertTrue("Failed opName value compare", entity.getOpName().equals(permAnt.getOpName()));
        }
    } catch (SecurityException ex) {
        LOG.error("readPermissionOps caught SecurityException rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage() + ex);
        fail(ex.getMessage());
    }
}
Also used : PermAnt(org.apache.directory.fortress.core.ant.PermAnt) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 62 with Permission

use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.

the class ReviewMgrImplTest method authorizedPermissionUsers.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 * @param uArray
 */
public static void authorizedPermissionUsers(String msg, String[][] pObjArray, String[][] pOpArray, String[][] uArray) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] obj : pObjArray) {
            int i = 0;
            for (String[] op : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(obj));
                pOp.setOpName(PermTestData.getName(op));
                pOp.setObjId(PermTestData.getObjId(op));
                Set<String> users = reviewMgr.authorizedPermissionUsers(pOp);
                assertNotNull(users);
                int expectedAuthZedUsers = i + 1;
                assertTrue(CLS_NM + "authorizedPermissionUsers permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", expectedAuthZedUsers == users.size());
                int j = 1;
                for (String[] usr : uArray) {
                    String userId = UserTestData.getUserId(usr);
                    if (j++ <= expectedAuthZedUsers) {
                        assertTrue(CLS_NM + "authorizedPermissionUsers userId [" + userId + "] should be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", users.contains(userId));
                    } else {
                        assertTrue(CLS_NM + "authorizedPermissionUsers userId [" + userId + "] should not be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", !users.contains(userId));
                    }
                }
                i++;
            }
        }
    } catch (SecurityException ex) {
        LOG.error("authorizedPermissionUsers 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 63 with Permission

use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.

the class ReviewMgrImplTest method authorizedPermissionRoles.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 * @param rArray
 */
public static void authorizedPermissionRoles(String msg, String[][] pObjArray, String[][] pOpArray, String[][] rArray) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] obj : pObjArray) {
            int i = 0;
            for (String[] op : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(obj));
                pOp.setOpName(PermTestData.getName(op));
                pOp.setObjId(PermTestData.getObjId(op));
                Set<String> roles = reviewMgr.authorizedPermissionRoles(pOp);
                assertNotNull(roles);
                int expectedAuthZedRoles = i + 1;
                assertTrue(CLS_NM + "authorizedPermissionRoles permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", expectedAuthZedRoles == roles.size());
                int j = 1;
                for (String[] rle : rArray) {
                    String roleName = RoleTestData.getName(rle);
                    if (j++ <= expectedAuthZedRoles) {
                        assertTrue(CLS_NM + "authorizedPermissionRoles roleName [" + roleName + "] should be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", roles.contains(roleName));
                    } else {
                        assertTrue(CLS_NM + "authorizedPermissionRoles roleName [" + roleName + "] should not be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", !roles.contains(roleName));
                    }
                }
                i++;
            }
        }
    } catch (SecurityException ex) {
        LOG.error("authorizedPermissionRoles 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 64 with Permission

use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.

the class ReviewMgrImplTest method readPASetFromPermission.

public static void readPASetFromPermission(String msg, String paSetName, String obj, String[] op) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        Permission pop = PermTestData.getOp(obj, op);
        Permission entity = reviewMgr.readPermission(pop);
        assertTrue(paSetName, entity.getPaSets().contains(paSetName));
        LOG.debug("readPASetFromPermission name [" + paSetName + "] successful");
    } catch (SecurityException ex) {
        LOG.error("readPASetFromPermission name [" + paSetName + "] 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 65 with Permission

use of org.apache.directory.fortress.core.model.Permission in project directory-fortress-core by apache.

the class ReviewMgrImplTest method searchPermissionOps.

/**
 * @param msg
 * @param srchValue
 * @param pObjArray
 */
public static void searchPermissionOps(String msg, String srchValue, String[][] pObjArray, String[][] pOpArray) {
    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(srchValue);
                List<Permission> ops = reviewMgr.findPermissions(pOp);
                assertNotNull(ops);
                assertTrue(CLS_NM + "searchPermissionOps srchValue [" + srchValue + "] list size check", pOpArray.length == ops.size());
                int indx = ops.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
                if (indx != -1) {
                    Permission entity = ops.get(indx);
                    assertNotNull(entity);
                    PermTestData.assertEquals(PermTestData.getName(obj), entity, op);
                    LOG.debug("searchPermissionOps objName [" + entity.getObjName() + "] operation name [" + entity.getOpName() + "] successful");
                } else {
                    msg = "searchPermissionOps srchValue [" + srchValue + "] failed list search";
                    LogUtil.logIt(msg);
                    fail(msg);
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("searchPermissionOps srchValue [" + srchValue + "] 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)

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