use of org.apache.directory.fortress.core.model.UserRole 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());
}
}
use of org.apache.directory.fortress.core.model.UserRole in project directory-fortress-core by apache.
the class AdminMgrImplTest method deassignUsersH.
/**
* @param msg
* @param uArray
* @param rArray
*/
void deassignUsersH(String msg, String[][] uArray, String[][] rArray) {
LogUtil.logIt(msg);
User user = null;
Role role = null;
try {
AdminMgr adminMgr = getManagedAdminMgr();
int i = 0;
for (String[] usr : uArray) {
user = UserTestData.getUser(usr);
role = RoleTestData.getRole(rArray[i++]);
UserRole uRole = new UserRole(user.getUserId(), role.getName());
adminMgr.deassignUser(uRole);
}
} catch (SecurityException ex) {
LOG.error("deassignUsersH user [" + (user != null ? user.getUserId() : null) + "] role [" + (role != null ? role.getName() : null) + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.UserRole in project directory-fortress-core by apache.
the class AdminMgrImplTest method assignUsersDSD.
/**
* @param msg
* @param uArray
* @param sArray
*/
public static void assignUsersDSD(String msg, String[][] uArray, String[][] sArray) {
LogUtil.logIt(msg);
try {
AdminMgr adminMgr = getManagedAdminMgr();
int i = 0;
for (String[] usr : uArray) {
SDSet dsd = RoleTestData.getSDSet(sArray[i++]);
Set<String> roles = dsd.getMembers();
User user = UserTestData.getUser(usr);
int j = 0;
for (String role : roles) {
j++;
UserRole uRole = new UserRole(user.getUserId(), role);
try {
adminMgr.assignUser(uRole);
} catch (SecurityException ex) {
LOG.error("assignUsersDSD caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(CLS_NM + "assignUsersDSD user [" + user.getUserId() + "] role [" + role + "] dsd [" + dsd.getName() + "] failed");
}
}
}
} catch (SecurityException ex) {
LOG.error("assignUsersDSD caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.UserRole in project directory-fortress-core by apache.
the class AdminMgrImplTest method deassignUsers.
/**
* @param msg
* @param uArray
* @param rArray
*/
void deassignUsers(String msg, String[][] uArray, String[][] rArray) {
LogUtil.logIt(msg);
try {
AdminMgr adminMgr = getManagedAdminMgr();
ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
int i = 0;
for (String[] usr : uArray) {
i++;
for (String[] rle : rArray) {
UserRole uRole = new UserRole(UserTestData.getUserId(usr), RoleTestData.getName(rle));
adminMgr.deassignUser(uRole);
LOG.debug("deassignUsers user [" + uRole.getUserId() + "] role [" + uRole.getName() + "] successful");
// Double check the number of users associated with role:
// This one retrieves the collection of all "roleOccupant" attributes associated with the role node:
List<String> users = reviewMgr.assignedUsers(RoleTestData.getRole(rle), rArray.length);
// This one searches across all Users and pull back list of type "User":
List<User> users2 = reviewMgr.authorizedUsers(RoleTestData.getRole(rle));
assertNotNull(users);
assertNotNull(users2);
// If this is the last user deassigned from role, both lists will be returned empty:
if (i == uArray.length) {
assertTrue(users.size() == 0);
assertTrue(users2.size() == 0);
} else {
assertTrue(CLS_NM + "deassignUsers list size check", (rArray.length - i) == users.size());
assertTrue(CLS_NM + "deassignUsers list2 size check", (rArray.length - i) == users2.size());
}
}
}
} catch (SecurityException ex) {
LOG.error("deassignUsers caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.UserRole in project directory-fortress-core by apache.
the class FortressAntLoadTest method testAssignedRoles.
@Test
public void testAssignedRoles() {
// gather assigned user to role input data:
List<Adduserrole> adduserroles = fortressAntTask.getAdduserroles();
for (Adduserrole adduserrole : adduserroles) {
List<UserRole> userroles = adduserrole.getUserRoles();
assignedRoles("ASGN-RLS", userroles);
}
}
Aggregations