Search in sources :

Example 81 with Role

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

the class ReviewMgrImplTest method teardownRequired.

/**
 * Determine if old fortress regression test cases are loaded in this directory and must be torn down.
 *
 * @param msg
 * @param rArray
 */
public static boolean teardownRequired(String msg, String[][] rArray) {
    // default return is 'true':
    boolean tearDown = true;
    String methodName = ".teardownRequired";
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] rle : rArray) {
            Role entity = reviewMgr.readRole(new Role(RoleTestData.getName(rle)));
            RoleTestData.assertEquals(entity, rle);
        }
    // if we get to here it means that old test data must be removed from directory.
    } catch (SecurityException ex) {
        // This is the expected when teardown is not required:
        if (ex.getErrorId() == GlobalErrIds.ROLE_NOT_FOUND) {
            // did not find old test data no need to teardown
            tearDown = false;
        } else {
            // Something unexpected occurred here, Report as warning to the logger:
            String warning = methodName + " caught SecurityException=" + ex.getMessage();
            LOG.warn(warning);
        // TODO: Determine if it would be better to throw a SecurityException here.
        }
    }
    LOG.info(methodName + ":" + tearDown);
    return tearDown;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 82 with Role

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

the class ReviewMgrImplTest method authorizedUsersHier.

/**
 * @param msg
 * @param roleMap
 */
public static void authorizedUsersHier(String msg, Map roleMap) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        // iterate over every role entry found in map:
        for (Object o : roleMap.entrySet()) {
            Map.Entry pairs = (Map.Entry) o;
            String roleName = (String) pairs.getKey();
            String szValidUsers = (String) pairs.getValue();
            Set<String> userSet = TestUtils.getSets(szValidUsers);
            assertNotNull(userSet);
            assertTrue(userSet.size() > 0);
            List<User> actualUsers = reviewMgr.authorizedUsers(new Role(roleName));
            assertNotNull(actualUsers);
            assertTrue(actualUsers.size() > 0);
            // Ensure the two list sizes match or fail the test case.
            assertTrue(CLS_NM + "authorizedUsersHier failed list size test case", userSet.size() == actualUsers.size());
            // for each valid user expected, ensure it actually pulled from API:
            for (String userId : userSet) {
                User validUser = new User(userId);
                assertTrue(CLS_NM + ".authorizedUsersHier failed authorizedUsers test, role [" + roleName + "] does not have user [" + validUser.getUserId() + "] as authorized", actualUsers.contains(validUser));
            }
        }
    } catch (SecurityException ex) {
        LOG.error("authorizedUsersHier caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) Map(java.util.Map)

Example 83 with Role

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

the class RoleTestData method getRoleConstraint.

/**
 * @param rle
 * @return
 */
public static Constraint getRoleConstraint(String[] rle) {
    Role role = new Role();
    role.setBeginDate(getBeginDate(rle));
    role.setEndDate(getEndDate(rle));
    role.setBeginLockDate(getBeginLockDate(rle));
    role.setEndLockDate(getEndLockDate(rle));
    role.setBeginTime(getBeginTime(rle));
    role.setEndTime(getEndTime(rle));
    role.setDayMask(getDayMask(rle));
    role.setTimeout(getTimeOut(rle));
    return role;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole)

Example 84 with Role

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

the class RoleTestData method getRole.

/**
 * @param rle
 * @return
 */
public static Role getRole(String[] rle) {
    Role role = (Role) getRoleConstraint(rle);
    role.setName(getName(rle));
    role.setDescription(getDescription(rle));
    return role;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole)

Example 85 with Role

use of org.apache.directory.fortress.core.model.Role 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)

Aggregations

Role (org.apache.directory.fortress.core.model.Role)117 UserRole (org.apache.directory.fortress.core.model.UserRole)83 SecurityException (org.apache.directory.fortress.core.SecurityException)66 AdminMgr (org.apache.directory.fortress.core.AdminMgr)40 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)30 User (org.apache.directory.fortress.core.model.User)30 AdminRole (org.apache.directory.fortress.core.model.AdminRole)25 Permission (org.apache.directory.fortress.core.model.Permission)24 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)17 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)15 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)15 Relationship (org.apache.directory.fortress.core.model.Relationship)7 SDSet (org.apache.directory.fortress.core.model.SDSet)7 FinderException (org.apache.directory.fortress.core.FinderException)6 PermObj (org.apache.directory.fortress.core.model.PermObj)6 ArrayList (java.util.ArrayList)5 Group (org.apache.directory.fortress.core.model.Group)5 Constraint (org.apache.directory.fortress.core.model.Constraint)4 FortRequest (org.apache.directory.fortress.core.model.FortRequest)4 FortResponse (org.apache.directory.fortress.core.model.FortResponse)4