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());
}
}
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;
}
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();
}
}
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();
}
}
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());
}
}
Aggregations