Search in sources :

Example 1 with User

use of org.apache.directory.fortress.core.model.User in project directory-fortress-core by apache.

the class AdminMgrImpl method removeRoleConstraint.

/**
 * {@inheritDoc}
 */
@Override
@AdminPermissionOperation
public void removeRoleConstraint(UserRole uRole, String roleConstraintId) throws SecurityException {
    String methodName = "assignUser";
    assertContext(CLS_NM, methodName, uRole, GlobalErrIds.URLE_NULL);
    AdminUtil.canDeassign(uRole.getAdminSession(), new User(uRole.getUserId()), new Role(uRole.getName()), contextId);
    // find role constraint that needs removed
    boolean found = false;
    List<UserRole> userRoles = userP.read(new User(uRole.getUserId()), true).getRoles();
    for (UserRole ur : userRoles) {
        // find matching name
        if (ur.getName().equals(uRole.getName())) {
            // find matching constraint
            List<RoleConstraint> rcs = ur.getRoleConstraints();
            for (RoleConstraint rc : rcs) {
                if (rc.getId().equals(roleConstraintId)) {
                    userP.deassign(uRole, rc);
                    found = true;
                    break;
                }
            }
        }
    }
    if (!found) {
        throw new FinderException(GlobalErrIds.RCON_NOT_FOUND, "Role constraint with id " + roleConstraintId + " not found");
    }
}
Also used : AdminRole(org.apache.directory.fortress.core.model.AdminRole) Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) FinderException(org.apache.directory.fortress.core.FinderException) User(org.apache.directory.fortress.core.model.User) UserRole(org.apache.directory.fortress.core.model.UserRole) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminPermissionOperation(org.apache.directory.fortress.annotation.AdminPermissionOperation)

Example 2 with User

use of org.apache.directory.fortress.core.model.User in project directory-fortress-core by apache.

the class AuditMgrImpl method searchAdminMods.

/**
 * {@inheritDoc}
 */
@Override
@AdminPermissionOperation
public List<Mod> searchAdminMods(UserAudit uAudit) throws SecurityException {
    String methodName = "searchAdminMods";
    assertContext(CLS_NM, methodName, uAudit, GlobalErrIds.AUDT_INPUT_NULL);
    checkAccess(CLS_NM, methodName);
    if (StringUtils.isNotEmpty(uAudit.getUserId())) {
        ReviewMgr rMgr = ReviewMgrFactory.createInstance(this.contextId);
        User user = rMgr.readUser(new User(uAudit.getUserId()));
        uAudit.setInternalUserId(user.getInternalId());
    }
    return auditP.searchAdminMods(uAudit);
}
Also used : User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) AdminPermissionOperation(org.apache.directory.fortress.annotation.AdminPermissionOperation)

Example 3 with User

use of org.apache.directory.fortress.core.model.User in project directory-fortress-core by apache.

the class DelAccessMgrImpl method checkUserRole.

/**
 * This helper function processes ARBAC URA "can assign".
 * @param session
 * @param user
 * @param role
 * @return boolean
 * @throws SecurityException
 */
private boolean checkUserRole(Session session, User user, Role role) throws SecurityException {
    boolean result = false;
    List<UserAdminRole> uaRoles = session.getAdminRoles();
    if (CollectionUtils.isNotEmpty(uaRoles)) {
        // validate user and retrieve user' ou:
        User ue = userP.read(user, false);
        for (UserAdminRole uaRole : uaRoles) {
            if (uaRole.getName().equalsIgnoreCase(SUPER_ADMIN)) {
                result = true;
                break;
            }
            Set<String> osUs = uaRole.getOsUSet();
            if (CollectionUtils.isNotEmpty(osUs)) {
                // create Set with case insensitive comparator:
                Set<String> osUsFinal = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                for (String osU : osUs) {
                    // Add osU children to the set:
                    osUsFinal.add(osU);
                    Set<String> children = UsoUtil.getInstance().getDescendants(osU, this.contextId);
                    osUsFinal.addAll(children);
                }
                // does the admin role have authority over the user object?
                if (osUsFinal.contains(ue.getOu())) {
                    // Get the Role range for admin role:
                    Set<String> range;
                    if (uaRole.getBeginRange() != null && uaRole.getEndRange() != null && !uaRole.getBeginRange().equalsIgnoreCase(uaRole.getEndRange())) {
                        range = RoleUtil.getInstance().getAscendants(uaRole.getBeginRange(), uaRole.getEndRange(), uaRole.isEndInclusive(), this.contextId);
                        if (uaRole.isBeginInclusive()) {
                            range.add(uaRole.getBeginRange());
                        }
                        if (CollectionUtils.isNotEmpty(range)) {
                            // Does admin role have authority over a role contained with the allowable role range?
                            if (range.contains(role.getName())) {
                                result = true;
                                break;
                            }
                        }
                    } else // Does admin role have authority over the role?
                    if (uaRole.getBeginRange() != null && uaRole.getBeginRange().equalsIgnoreCase(role.getName())) {
                        result = true;
                        break;
                    }
                }
            }
        }
    }
    return result;
}
Also used : User(org.apache.directory.fortress.core.model.User) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) TreeSet(java.util.TreeSet)

Example 4 with User

use of org.apache.directory.fortress.core.model.User in project directory-fortress-core by apache.

the class DelAccessMgrImpl method addActiveRole.

/**
 * {@inheritDoc}
 */
@Override
public void addActiveRole(Session session, UserAdminRole role) throws SecurityException {
    String methodName = "addActiveRole";
    assertContext(CLS_NM, methodName, session, GlobalErrIds.USER_SESS_NULL);
    assertContext(CLS_NM, methodName, role, GlobalErrIds.ARLE_NULL);
    role.setUserId(session.getUserId());
    List<UserAdminRole> sRoles = session.getAdminRoles();
    // If session already has admin role activated log an error and throw an exception:
    if (sRoles != null && sRoles.contains(role)) {
        String info = getFullMethodName(CLS_NM, methodName) + " User [" + session.getUserId() + "] Role [" + role.getName() + "] role already activated.";
        throw new SecurityException(GlobalErrIds.ARLE_ALREADY_ACTIVE, info);
    }
    User ue = userP.read(session.getUser(), true);
    List<UserAdminRole> uRoles = ue.getAdminRoles();
    int indx;
    // Is the admin role activation target valid for this user?
    if (!CollectionUtils.isNotEmpty(uRoles) || ((indx = uRoles.indexOf(role)) == -1)) {
        String info = getFullMethodName(CLS_NM, methodName) + " Admin Role [" + role.getName() + "] User [" + session.getUserId() + "] adminRole not authorized for user.";
        throw new SecurityException(GlobalErrIds.ARLE_ACTIVATE_FAILED, info);
    }
    SDUtil.getInstance().validateDSD(session, role);
    // now activate the role to the session:
    session.setRole(uRoles.get(indx));
}
Also used : User(org.apache.directory.fortress.core.model.User) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 5 with User

use of org.apache.directory.fortress.core.model.User in project directory-fortress-core by apache.

the class DelAdminMgrImpl method updateRole.

/**
 * {@inheritDoc}
 */
@Override
@AdminPermissionOperation
public AdminRole updateRole(AdminRole role) throws SecurityException {
    String methodName = "updateRole";
    assertContext(CLS_NM, methodName, role, GlobalErrIds.ARLE_NULL);
    setEntitySession(CLS_NM, methodName, role);
    AdminRole re = admRP.update(role);
    // search for all users assigned this role and update:
    List<User> users = userP.getAssignedUsers(role);
    if (CollectionUtils.isNotEmpty(users)) {
        final AdminMgr aMgr = AdminMgrFactory.createInstance(this.contextId);
        for (User ue : users) {
            User upUe = new User(ue.getUserId());
            setAdminData(CLS_NM, methodName, upUe);
            List<UserAdminRole> uaRoles = ue.getAdminRoles();
            UserAdminRole chgRole = new UserAdminRole();
            chgRole.setName(role.getName());
            chgRole.setUserId(ue.getUserId());
            chgRole.setOsPSet(role.getOsPSet());
            chgRole.setOsUSet(role.getOsUSet());
            uaRoles.remove(chgRole);
            ConstraintUtil.copy(re, chgRole);
            uaRoles.add(chgRole);
            upUe.setUserId(ue.getUserId());
            upUe.setAdminRole(chgRole);
            aMgr.updateUser(upUe);
        }
    }
    return re;
}
Also used : User(org.apache.directory.fortress.core.model.User) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) AdminRole(org.apache.directory.fortress.core.model.AdminRole) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) AdminMgr(org.apache.directory.fortress.core.AdminMgr) DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) AdminPermissionOperation(org.apache.directory.fortress.annotation.AdminPermissionOperation)

Aggregations

User (org.apache.directory.fortress.core.model.User)190 SecurityException (org.apache.directory.fortress.core.SecurityException)128 UserRole (org.apache.directory.fortress.core.model.UserRole)66 Session (org.apache.directory.fortress.core.model.Session)51 AdminMgr (org.apache.directory.fortress.core.AdminMgr)39 AccessMgr (org.apache.directory.fortress.core.AccessMgr)37 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)31 Role (org.apache.directory.fortress.core.model.Role)30 Permission (org.apache.directory.fortress.core.model.Permission)24 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)24 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)20 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)18 AdminRole (org.apache.directory.fortress.core.model.AdminRole)17 ArrayList (java.util.ArrayList)15 AccelMgr (org.apache.directory.fortress.core.AccelMgr)12 PwPolicyMgr (org.apache.directory.fortress.core.PwPolicyMgr)10 Constraint (org.apache.directory.fortress.core.model.Constraint)9 FinderException (org.apache.directory.fortress.core.FinderException)8 FortRequest (org.apache.directory.fortress.core.model.FortRequest)8 FortResponse (org.apache.directory.fortress.core.model.FortResponse)8