use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class DelegatedMgrImplTest method canAssignUsers.
/**
* @param msg
* @param op
* @param uraArray
* @param uaArray
* @param uArray
* @param rArray
*/
public static void canAssignUsers(String msg, ASSIGN_OP op, String[][] uraArray, String[][] uaArray, String[][] uArray, String[][] rArray) {
LogUtil.logIt(msg);
Role role;
Map<URA, URA> uraTestResults = URATestData.getURAs(uraArray);
try {
DelAccessMgr delAccessMgr = DelAccessMgrFactory.createInstance(TestUtils.getContext());
AccessMgr accessMgr = (AccessMgr) delAccessMgr;
int i = 0;
for (String[] aUsr : uaArray) {
User aUser = UserTestData.getUser(aUsr);
Session session = accessMgr.createSession(aUser, false);
assertNotNull(session);
for (String[] usr : uArray) {
User user = UserTestData.getUser(usr);
i++;
for (String[] rle : rArray) {
role = RoleTestData.getRole(rle);
String methodName;
boolean result;
if (op == ASSIGN_OP.ASSIGN) {
result = delAccessMgr.canAssign(session, user, role);
methodName = ".canAssignUsers";
} else {
result = delAccessMgr.canDeassign(session, user, role);
methodName = ".canDeassignUsers";
}
List<UserAdminRole> aRoles = session.getAdminRoles();
assertNotNull(aRoles);
assertTrue(CLS_NM + methodName + " Admin User invalid number of roles", aRoles.size() == 1);
// since this user should only have one admin role, get the first one from list:
UserAdminRole aRole = aRoles.get(0);
URA sourceUra = new URA(aRole.getName(), user.getOu(), role.getName(), result);
URA targetUra = uraTestResults.get(sourceUra);
assertTrue(CLS_NM + methodName + " cannot find target URA admin role [" + sourceUra.getArole() + " uou [" + sourceUra.getUou() + "] role [" + sourceUra.getUrole() + "] Result [" + sourceUra.isCanAssign() + "] actual result [" + result + "]", targetUra != null);
LOG.debug(methodName + " User [" + user.getUserId() + "] success URA using admin role [" + targetUra.getArole() + " uou [" + targetUra.getUou() + "] role [" + targetUra.getUrole() + "] target result [" + targetUra.isCanAssign() + "] actual result [" + result + "]");
}
}
}
} catch (SecurityException ex) {
LOG.error("canAssignUsers op [" + op + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class DelegatedMgrImplTest method canGrantPerms.
/**
* @param msg
* @param op
* @param uraArray
* @param uaArray
* @param pArray
* @param rArray
*/
public static void canGrantPerms(String msg, GRANT_OP op, String[][] uraArray, String[][] uaArray, String[][] pArray, String[][] rArray) {
LogUtil.logIt(msg);
Role role;
Map<PRA, PRA> praTestResults = PRATestData.getPRAs(uraArray);
try {
DelAccessMgr delAccessMgr = DelAccessMgrFactory.createInstance(TestUtils.getContext());
AccessMgr accessMgr = (AccessMgr) delAccessMgr;
int i = 0;
for (String[] aUsr : uaArray) {
User aUser = UserTestData.getUser(aUsr);
Session session = accessMgr.createSession(aUser, false);
assertNotNull(session);
for (String[] prm : pArray) {
PermObj pObj = PermTestData.getObj(prm);
i++;
for (String[] rle : rArray) {
role = RoleTestData.getRole(rle);
String methodName;
boolean result;
if (op == GRANT_OP.GRANT) {
result = delAccessMgr.canGrant(session, role, new Permission(pObj.getObjName(), ""));
methodName = ".canGrantPerms";
} else {
result = delAccessMgr.canRevoke(session, role, new Permission(pObj.getObjName(), ""));
methodName = ".canRevokePerms";
}
List<UserAdminRole> aRoles = session.getAdminRoles();
assertNotNull(aRoles);
assertTrue(CLS_NM + methodName + " Admin User invalid number of roles", aRoles.size() == 1);
UserAdminRole aRole = aRoles.get(0);
PRA sourceUra = new PRA(aRole.getName(), pObj.getOu(), role.getName(), result);
PRA targetUra = praTestResults.get(sourceUra);
assertTrue(CLS_NM + methodName + " cannot find target PRA admin role [" + sourceUra.getArole() + " pou [" + sourceUra.getPou() + "] role [" + sourceUra.getUrole() + "] Result [" + sourceUra.isCanAssign() + "] actual result [" + result + "]", targetUra != null);
LOG.debug(methodName + " failed target PRA admin role [" + targetUra.getArole() + " pou [" + targetUra.getPou() + "] role [" + targetUra.getUrole() + "] target result [" + targetUra.isCanAssign() + "] actual result [" + result + "]");
}
}
}
} catch (SecurityException ex) {
LOG.error("canGrantPerms op [" + op + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class DelegatedMgrImplTest method createAdminSession.
/**
*/
public static Session createAdminSession() {
Session adminSess = null;
try {
AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
User admin = UserTestData.getUser(UserTestData.USERS_TU0[0]);
adminSess = accessMgr.createSession(admin, false);
} catch (SecurityException ex) {
String error = " static initializer caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage();
LOG.error(error);
}
return adminSess;
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class DelegatedAccessMgrConsole method createSession.
/**
*/
void createSession() {
try {
ReaderUtil.clearScreen();
System.out.println("Enter userId:");
String userId = ReaderUtil.readLn();
System.out.println("Enter password:");
String password = ReaderUtil.readLn();
session = new Session();
// ((AccessMgr)dAmgr).createSession(session, userId, password);
((AccessMgr) dAmgr).createSession(new User(userId, password), false);
System.out.println("Session created successfully for userId [" + userId + "]");
System.out.println("session [" + session + "]");
System.out.println("ENTER to continue");
} catch (SecurityException e) {
LOG.error("createSession caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
}
ReaderUtil.readChar();
}
use of org.apache.directory.fortress.core.model.Session in project directory-fortress-core by apache.
the class CreateSessionSample method createSessionsWithRolesTrusted.
/**
* Create RBAC Session and activated supplied Roles. This scenario perform authentication in trusted manner
* which does not require User password.
*
* @param userId Case insensitive userId.
* @param roles array of Role names to activate into RBAC Session.
* @param expectedRoles integer contains the expected number of Roles in the Session.
*/
public static void createSessionsWithRolesTrusted(String userId, String[] roles, int expectedRoles) {
String szLocation = ".createSessionsWithRolesTrusted";
try {
AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
// The User entity is used to pass data into the createSession API.
User user = new User(userId);
// iterate over array of input Role names.
for (String roleName : roles) {
// Add the Role name to list of Roles to be activated on Session.
user.setRoleName(roleName);
}
// The API will verify User is good and perform Role activations. Request will fail if User is locked out of ldap for any reason.
Session session = accessMgr.createSession(user, true);
// createSession will throw SecurityException if fails thus the Session should never be null.
assertNotNull(session);
// Get the User's activated Roles.
List<UserRole> sessRoles = session.getRoles();
// do some validations
assertEquals(szLocation + " user role check failed list size user [" + user.getUserId() + "]", expectedRoles, sessRoles.size());
for (String roleName : roles) {
assertTrue(szLocation + " userId [" + userId + "] with roles trusted failed role check", sessRoles.contains(new UserRole(roleName)));
}
LOG.info(szLocation + " userId [" + userId + "] successful");
} catch (SecurityException ex) {
LOG.error(szLocation + " caught userId [" + userId + "] SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations