Search in sources :

Example 6 with RoleManagementRulesNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.RoleManagementRulesNotExistsException in project perun by CESNET.

the class AuthzResolver method setRole.

/**
 * Set role for user and <b>one</b> complementary object.
 *
 * If complementary object is wrong for the role, throw an exception.
 * For role "PERUNADMIN" ignore complementary object.
 *
 * @param sess perun session
 * @param user the user for setting role
 * @param role role of user in a session
 * @param complementaryObject object for which role will be set
 */
public static void setRole(PerunSession sess, User user, PerunBean complementaryObject, String role) throws PrivilegeException, UserNotExistsException, AlreadyAdminException, RoleCannotBeManagedException {
    Utils.notNull(role, "role");
    if (!roleExists(role)) {
        throw new InternalErrorException("Role: " + role + " does not exists.");
    }
    ((PerunBl) sess.getPerun()).getUsersManagerBl().checkUserExists(sess, user);
    try {
        if (!authorizedToManageRole(sess, complementaryObject, role)) {
            throw new PrivilegeException("You are not privileged to use the method setRole.");
        }
    } catch (RoleManagementRulesNotExistsException e) {
        throw new InternalErrorException("Management rules not exist for the role " + role, e);
    }
    AuthzResolverBlImpl.setRole(sess, user, complementaryObject, role);
}
Also used : RoleManagementRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.RoleManagementRulesNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)6 RoleManagementRulesNotExistsException (cz.metacentrum.perun.core.api.exceptions.RoleManagementRulesNotExistsException)6