use of org.apache.directory.fortress.core.model.RoleConstraint in project directory-fortress-core by apache.
the class AdminMgrImplTest method testRemoveUserRoleConstraint.
public void testRemoveUserRoleConstraint() throws SecurityException {
this.assertRoleConstraintSize(UserTestData.USERS_TU1[0][0], RoleTestData.ROLES_TR1[1][0], 1);
RoleConstraint rc1 = assignUserRoleConstraint("ASGN-URC-VALID TU1 TR1", UserTestData.USERS_TU1[0], RoleTestData.ROLES_TR1[1], URATestData.getRC(URATestData.URC_T2));
RoleConstraint rc2 = assignUserRoleConstraint("ASGN-URC-VALID TU1 TR1", UserTestData.USERS_TU1[0], RoleTestData.ROLES_TR1[1], URATestData.getRC(URATestData.URC_T3));
this.assertRoleConstraintSize(UserTestData.USERS_TU1[0][0], RoleTestData.ROLES_TR1[1][0], 3);
AdminMgr adminMgr = getManagedAdminMgr();
adminMgr.removeRoleConstraint(new UserRole(UserTestData.USERS_TU1[0][0], RoleTestData.ROLES_TR1[1][0]), rc1);
this.assertRoleConstraintSize(UserTestData.USERS_TU1[0][0], RoleTestData.ROLES_TR1[1][0], 2);
adminMgr.removeRoleConstraint(new UserRole(UserTestData.USERS_TU1[0][0], RoleTestData.ROLES_TR1[1][0]), rc2.getId());
this.assertRoleConstraintSize(UserTestData.USERS_TU1[0][0], RoleTestData.ROLES_TR1[1][0], 1);
}
use of org.apache.directory.fortress.core.model.RoleConstraint in project directory-fortress-core by apache.
the class ReviewMgrImplTest method findRoleConstraints.
public static void findRoleConstraints(String msg, String usr, Permission permission, RoleConstraint.RCType rcType) {
LogUtil.logIt(msg);
try {
ReviewMgr reviewMgr = getManagedReviewMgr();
List<RoleConstraint> rcs = reviewMgr.findRoleConstraints(new User(usr), permission, rcType);
assertTrue(rcs.size() > 0);
assertTrue(rcs.get(0).getType().equals(rcType));
LOG.debug("findRoleConstraints permission [" + permission.getObjName() + "." + permission.getOpName() + "] successful");
} catch (SecurityException ex) {
LOG.error("findRoleConstraints permission [" + permission.getObjName() + "." + permission.getOpName() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.RoleConstraint in project directory-fortress-core by apache.
the class URATestData method getRC.
public static RoleConstraint getRC(String[] rc) {
RoleConstraint urc = new RoleConstraint();
urc.setPaSetName(rc[0]);
urc.setType(RoleConstraint.RCType.valueOf(rc[1]));
urc.setValue(rc[2]);
return urc;
}
use of org.apache.directory.fortress.core.model.RoleConstraint in project directory-fortress-core by apache.
the class AdminMgrRestImpl method addRoleConstraint.
/**
* {@inheritDoc}
*/
@Override
public RoleConstraint addRoleConstraint(UserRole uRole, RoleConstraint roleConstraint) throws SecurityException {
VUtil.assertNotNull(uRole, GlobalErrIds.URLE_NULL, CLS_NM + ".addRoleConstraint");
VUtil.assertNotNull(roleConstraint, GlobalErrIds.RCON_NULL, CLS_NM + ".addRoleConstraint");
RoleConstraint retCnst;
FortRequest request = RestUtils.getRequest(this.contextId);
request.setEntity(uRole);
request.setEntity2(roleConstraint);
if (this.adminSess != null) {
request.setSession(adminSess);
}
String szRequest = RestUtils.marshal(request);
String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.ROLE_ADD_CONSTRAINT);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() == 0) {
retCnst = (RoleConstraint) response.getEntity();
} else {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
return retCnst;
}
use of org.apache.directory.fortress.core.model.RoleConstraint in project directory-fortress-core by apache.
the class UserP method findRoleConstraints.
List<RoleConstraint> findRoleConstraints(Set<String> roles, User user, RoleConstraint.RCType rcType, Set<String> paSets) throws SecurityException {
List<RoleConstraint> matchingConstraints = new ArrayList<RoleConstraint>();
// TODO: can we do this in a query?
List<UserRole> userRoles = uDao.getUser(user, true).getRoles();
for (UserRole ur : userRoles) {
// only get constraints for passed in roles
if (roles.contains(ur.getName())) {
for (RoleConstraint rc : ur.getRoleConstraints()) {
if (rc.getType().equals(rcType) && paSets.contains(rc.getPaSetName())) {
matchingConstraints.add(rc);
}
}
}
}
return matchingConstraints;
}
Aggregations