Search in sources :

Example 41 with UserRole

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

the class ReviewMgrImplTest method readUserRoleConstraint.

public static void readUserRoleConstraint(String msg, String[] usr, String[] rle, RoleConstraint rc) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        User user = UserTestData.getUser(usr);
        Role role = RoleTestData.getRole(rle);
        List<UserRole> urs = reviewMgr.assignedRoles(user);
        boolean uraFound = false;
        boolean urcFound = false;
        for (UserRole ur : urs) {
            if (ur.getName().equals(role.getName())) {
                uraFound = true;
                List<RoleConstraint> rcs = ur.getRoleConstraints();
                for (RoleConstraint r : rcs) {
                    if (r.getPaSetName().equals(rc.getPaSetName())) {
                        urcFound = true;
                        assertEquals(rc.getType(), r.getType());
                        assertEquals(rc.getValue(), r.getValue());
                        assertNotNull(r.getId());
                    }
                }
            }
        }
        if (!uraFound) {
            fail("User Role Assignment Not Found");
        }
        if (!urcFound) {
            fail("User Role Constraint Not Found");
        }
        LOG.debug("readUserRoleConstraint value [" + rc.getValue() + "] successful");
    } catch (SecurityException ex) {
        LOG.error("readUserRoleConstraint value [" + rc.getValue() + "] 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) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 42 with UserRole

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

the class RoleTestData method getUserRoleConstraint.

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

Example 43 with UserRole

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

the class TestAccelerator method testAddActiveRole.

// @Test
public void testAddActiveRole() {
    LOG.info("testAddActiveRole...");
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        Session session;
        User user = new User();
        // positive test case:
        user.setUserId("rbacuser1");
        user.setPassword("secret");
        user.setRoleName("rbacrole1");
        // user.setRole( "rbacrole2" );
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        assertTrue(session.isAuthenticated());
        UserRole userRole = new UserRole(user.getUserId(), "rbacrole2");
        accelMgr.addActiveRole(session, userRole);
    } catch (SecurityException se) {
        se.printStackTrace();
        fail();
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccelMgr(org.apache.directory.fortress.core.AccelMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 44 with UserRole

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

the class TestAccelerator method testDropActiveRole.

@Test
public void testDropActiveRole() {
    LOG.info("testDropActiveRole...");
    // AcceleratorDAO aDao = new org.apache.directory.fortress.core.impl.AcceleratorDAO();
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        Session session;
        User user = new User();
        // positive test case:
        user.setUserId("rbacuser1");
        user.setPassword("secret");
        // user.setRole( "rbacrole1" );
        // user.setRole( "rbacrole2" );
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        assertTrue(session.isAuthenticated());
        UserRole userRole = new UserRole(user.getUserId(), "rbacrole2");
        accelMgr.dropActiveRole(session, userRole);
    } catch (SecurityException se) {
        se.printStackTrace();
        fail();
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccelMgr(org.apache.directory.fortress.core.AccelMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session) Test(org.junit.Test)

Example 45 with UserRole

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

the class AccelMgrImplTest method dropActiveRoles.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void dropActiveRoles(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accelMgr.createSession(user, false);
            assertNotNull(session);
            // remove all roles from the user's session:
            for (String[] rle : rArray) {
                // Drop Role:
                accelMgr.dropActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(rle)));
                // session)
                try {
                    // Drop Role3 (this better fail):
                    accelMgr.dropActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(rle)));
                    String error = "dropActiveRoles failed negative test 2 User [" + user.getUserId() + "] Role [" + RoleTestData.getName(rle) + "]";
                    LOG.info(error);
                    fail(error);
                } catch (SecurityException se) {
                    assertTrue("dropActiveRoles excep id check", se.getErrorId() == GlobalErrIds.URLE_NOT_ACTIVE);
                }
            }
            accelMgr.deleteSession(session);
        }
    } catch (SecurityException ex) {
        LOG.error("dropActiveRoles: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccelMgr(org.apache.directory.fortress.core.AccelMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Aggregations

UserRole (org.apache.directory.fortress.core.model.UserRole)89 User (org.apache.directory.fortress.core.model.User)55 SecurityException (org.apache.directory.fortress.core.SecurityException)48 Session (org.apache.directory.fortress.core.model.Session)28 AccessMgr (org.apache.directory.fortress.core.AccessMgr)17 ArrayList (java.util.ArrayList)16 Role (org.apache.directory.fortress.core.model.Role)16 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)16 AdminMgr (org.apache.directory.fortress.core.AdminMgr)14 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)12 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)11 Constraint (org.apache.directory.fortress.core.model.Constraint)10 AdminRole (org.apache.directory.fortress.core.model.AdminRole)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)7 AccelMgr (org.apache.directory.fortress.core.AccelMgr)6 FinderException (org.apache.directory.fortress.core.FinderException)6 SDSet (org.apache.directory.fortress.core.model.SDSet)6 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)6 Enumeration (java.util.Enumeration)5