Search in sources :

Example 6 with RoleConstraint

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);
}
Also used : UserRole(org.apache.directory.fortress.core.model.UserRole) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 7 with RoleConstraint

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());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 8 with RoleConstraint

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;
}
Also used : RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 9 with RoleConstraint

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;
}
Also used : FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 10 with RoleConstraint

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;
}
Also used : UserRole(org.apache.directory.fortress.core.model.UserRole) ArrayList(java.util.ArrayList) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Aggregations

RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)10 UserRole (org.apache.directory.fortress.core.model.UserRole)6 SecurityException (org.apache.directory.fortress.core.SecurityException)4 User (org.apache.directory.fortress.core.model.User)4 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)3 Role (org.apache.directory.fortress.core.model.Role)3 ArrayList (java.util.ArrayList)2 AdminMgr (org.apache.directory.fortress.core.AdminMgr)2 FinderException (org.apache.directory.fortress.core.FinderException)2 FortRequest (org.apache.directory.fortress.core.model.FortRequest)2 FortResponse (org.apache.directory.fortress.core.model.FortResponse)2 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)1 Modification (org.apache.directory.api.ldap.model.entry.Modification)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)1 UpdateException (org.apache.directory.fortress.core.UpdateException)1 AdminRole (org.apache.directory.fortress.core.model.AdminRole)1 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)1