Search in sources :

Example 16 with Session

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

the class AccessMgrImplTest method getUserIds.

/**
 * @param msg
 * @param uArray
 */
public static void getUserIds(String msg, String[][] uArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.authenticate(user.getUserId(), user.getPassword());
            assertNotNull(session);
            String userId = accessMgr.getUserId(session);
            assertTrue("getUserIds failed compare found userId [" + userId + "] valid userId [" + UserTestData.getUserId(usr) + "]", userId.equalsIgnoreCase(UserTestData.getUserId(usr)));
        }
        LOG.debug("getUserIds successful");
    } catch (SecurityException ex) {
        LOG.error("getUserIds: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 17 with Session

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

the class AccessMgrImplTest method createSessionsWithRolesTrusted.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessionsWithRolesTrusted(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            List<UserRole> rlsRequested = new ArrayList<>();
            int cnt = 0;
            for (String[] rle : rArray) {
                rlsRequested.add(RoleTestData.getUserRole(user.getUserId(), rle));
                user.setRoles(rlsRequested);
                Session session = accessMgr.createSession(user, true);
                assertTrue(CLS_NM + ".createSessionsWithRolesTrusted failed role search USER [" + user.getUserId() + "] CNT [" + ++cnt + "] size [" + session.getRoles().size() + "]", cnt == session.getRoles().size());
                String userId = accessMgr.getUserId(session);
                assertTrue(CLS_NM + ".createSessionsWithRolesTrusted failed compare found userId [" + userId + "] valid userId [" + UserTestData.getUserId(usr) + "]", userId.equalsIgnoreCase(UserTestData.getUserId(usr)));
                UserTestData.assertEquals(user, usr);
            }
        }
        LOG.debug("createSessionsWithRolesTrusted successful");
    } catch (SecurityException ex) {
        LOG.error("createSessionsWithRolesTrusted: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) ArrayList(java.util.ArrayList) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 18 with Session

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

the class AccessMgrImplTest method createSessionsDSD.

/**
 * @param msg
 * @param uArray
 * @param dsdArray
 */
public static void createSessionsDSD(String msg, String[][] uArray, String[][] dsdArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        int i = 0;
        for (String[] usr : uArray) {
            SDSet dsd = RoleTestData.getSDSet(dsdArray[i++]);
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            String userId = accessMgr.getUserId(session);
            assertTrue(CLS_NM + ".createSessionsDSD failed compare found userId [" + userId + "] valid userId [" + UserTestData.getUserId(usr) + "]", userId.equalsIgnoreCase(UserTestData.getUserId(usr)));
            UserTestData.assertEquals(user, usr);
            List<UserRole> uRoles = session.getRoles();
            assertNotNull(uRoles);
            // was the number of members in test DSD greater than the cardinality?
            if (dsd.getMembers().size() < dsd.getCardinality()) {
                assertEquals(CLS_NM + ".createSessionsDSD role list size check failed user-role user [" + user.getUserId() + "]", dsd.getMembers().size(), uRoles.size());
            } else {
                assertEquals(CLS_NM + ".createSessionsDSD role cardinality check failed user-role list size user [" + user.getUserId() + "] dsd set [" + dsd.getName() + "] card [" + dsd.getCardinality() + "] listsize [" + uRoles.size() + "]", dsd.getCardinality() - 1, uRoles.size());
            }
        }
        LOG.debug("createSessionsDSD successful");
    } catch (SecurityException ex) {
        LOG.error("createSessionsDSD: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 19 with Session

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

the class AccessMgrImplTest method dropActiveRoles.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void dropActiveRoles(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            List<UserRole> uRoles = session.getRoles();
            assertNotNull(uRoles);
            assertEquals(CLS_NM + ".dropActiveRoles failed list size user[" + user.getUserId() + "]", rArray.length, uRoles.size());
            for (String[] rle : rArray) {
                assertTrue(CLS_NM + ".dropActiveRoles failed role search USER [" + user.getUserId() + "] ROLE [" + RoleTestData.getName(rle) + "] should be present", uRoles.contains(RoleTestData.getUserRole(UserTestData.getUserId(usr), rle)));
            }
            // remove all roles from the user's session:
            int ctr = rArray.length;
            for (String[] rle : rArray) {
                // Drop Role:
                accessMgr.dropActiveRole(session, new UserRole(RoleTestData.getName(rle)));
                assertEquals(CLS_NM + ".dropActiveRoles failed list size user[" + user.getUserId() + "]", (--ctr), session.getRoles().size());
                assertTrue(CLS_NM + ".dropActiveRoles failed role search USER [" + user.getUserId() + "] ROLE [" + RoleTestData.getName(rle) + "] should not contain role", !session.getRoles().contains(RoleTestData.getUserRole(UserTestData.getUserId(usr), rle)));
                // Drop Role again: (This better fail because role  has already been deactivated from user's session)
                try {
                    // Drop Role3 (this better fail):
                    accessMgr.dropActiveRole(session, new UserRole(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);
                }
            }
        }
    } 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) AccessMgr(org.apache.directory.fortress.core.AccessMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 20 with Session

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

the class AccessMgrImplTest method createSessions.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessions(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            String userId = accessMgr.getUserId(session);
            assertTrue(CLS_NM + ".createSessions failed compare found userId [" + userId + "] valid userId [" + UserTestData.getUserId(usr) + "]", userId.equalsIgnoreCase(UserTestData.getUserId(usr)));
            UserTestData.assertEquals(user, usr);
            List<UserRole> uRoles = session.getRoles();
            assertNotNull(uRoles);
            assertEquals(CLS_NM + ".createSessions user role check failed list size user [" + user.getUserId() + "]", rArray.length, uRoles.size());
            for (String[] rle : rArray) {
                assertTrue(CLS_NM + ".createSessions failed role search USER [" + user.getUserId() + "] ROLE1 [" + RoleTestData.getName(rle) + "] should be present", uRoles.contains(RoleTestData.getUserRole(UserTestData.getUserId(usr), rle)));
            }
            // now try negative test case:
            try {
                User userBad = new User(user.getUserId(), "badpw");
                accessMgr.createSession(userBad, false);
                fail(CLS_NM + ".createSessions failed negative test");
            } catch (SecurityException se) {
                assertTrue(CLS_NM + "createSessions excep id check", se.getErrorId() == GlobalErrIds.USER_PW_INVLD);
            // pass
            }
        }
        LOG.debug("createSessions successful");
    } catch (SecurityException ex) {
        LOG.error("createSessions: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Aggregations

Session (org.apache.directory.fortress.core.model.Session)70 SecurityException (org.apache.directory.fortress.core.SecurityException)62 User (org.apache.directory.fortress.core.model.User)51 AccessMgr (org.apache.directory.fortress.core.AccessMgr)32 UserRole (org.apache.directory.fortress.core.model.UserRole)28 AccelMgr (org.apache.directory.fortress.core.AccelMgr)12 Permission (org.apache.directory.fortress.core.model.Permission)12 FortRequest (org.apache.directory.fortress.core.model.FortRequest)10 FortResponse (org.apache.directory.fortress.core.model.FortResponse)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 DelAccessMgr (org.apache.directory.fortress.core.DelAccessMgr)4 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)4 PasswordException (org.apache.directory.fortress.core.PasswordException)3 lombok.val (lombok.val)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 org.apache.directory.fortress.core (org.apache.directory.fortress.core)2 AdminRole (org.apache.directory.fortress.core.model.AdminRole)2 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)2 Role (org.apache.directory.fortress.core.model.Role)2