Search in sources :

Example 1 with RelationNotExistsException

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

the class UsersManagerBlImpl method unsetSpecificUser.

@Override
public User unsetSpecificUser(PerunSession sess, User specificUser, SpecificUserType specificUserType) {
    if (!specificUser.getMajorSpecificType().equals(specificUserType)) {
        throw new InternalErrorException("Can't unset " + specificUserType.getSpecificUserType() + " for " + specificUser + ", because he hasn't this flag yet.");
    }
    // remove all owners for this new specific user
    List<User> owners = getPerunBl().getUsersManagerBl().getUsersBySpecificUser(sess, specificUser);
    for (User owner : owners) {
        try {
            this.removeSpecificUserOwner(sess, owner, specificUser, true);
        } catch (RelationNotExistsException | SpecificUserOwnerAlreadyRemovedException ex) {
            throw new InternalErrorException("Can't remove ownership of user " + specificUser, ex);
        }
    }
    // Unset specific type for user
    specificUser = getUsersManagerImpl().unsetSpecificUserType(sess, specificUser, specificUserType);
    return specificUser;
}
Also used : RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) User(cz.metacentrum.perun.core.api.User) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) RichUser(cz.metacentrum.perun.core.api.RichUser) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) AllUserExtSourcesDeletedForUser(cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 2 with RelationNotExistsException

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

the class UsersManagerBlImpl method removeSpecificUserOwner.

@Override
public void removeSpecificUserOwner(PerunSession sess, User user, User specificUser, boolean forceDelete) throws RelationNotExistsException, SpecificUserOwnerAlreadyRemovedException {
    if (specificUser.isServiceUser() && specificUser.isSponsoredUser())
        throw new InternalErrorException("We don't support specific and sponsored users together yet.");
    if (specificUser.getMajorSpecificType().equals(SpecificUserType.NORMAL))
        throw new InternalErrorException("Incorrect type of specification for specific user!" + specificUser);
    if (user.getMajorSpecificType().equals(SpecificUserType.SERVICE))
        throw new InternalErrorException("Service user can`t own another account (service or guest)!" + user);
    List<User> specificUserOwners = this.getUsersBySpecificUser(sess, specificUser);
    if (!specificUserOwners.remove(user))
        throw new RelationNotExistsException("User is not the active owner of the specificUser.");
    if (!getUsersManagerImpl().specificUserOwnershipExists(sess, user, specificUser)) {
        throw new RelationNotExistsException("User has no relationship to specificUser.");
    }
    try {
        // refresh authz for sponsors
        if (specificUser.isSponsoredUser())
            AuthzResolverBlImpl.removeSpecificUserOwner(sess, specificUser, user);
        // refresh authz for service user owners
        if (specificUser.isServiceUser() && sess.getPerunPrincipal() != null) {
            if (user.getId() == sess.getPerunPrincipal().getUserId()) {
                AuthzResolverBlImpl.refreshAuthz(sess);
            }
        }
    } catch (UserNotAdminException ex) {
        throw new InternalErrorException("Can't remove role of sponsor for user " + user + " and sponsored user " + specificUser);
    }
    if (forceDelete) {
        // getPerunBl().getAuditer().log(sess, "{} ownership was removed for specificUser {}.", user, specificUser);
        getPerunBl().getAuditer().log(sess, new OwnershipRemovedForSpecificUser(user, specificUser));
        getUsersManagerImpl().removeSpecificUserOwner(sess, user, specificUser);
    } else {
        getPerunBl().getAuditer().log(sess, new OwnershipDisabledForSpecificUser(user, specificUser));
        getUsersManagerImpl().disableOwnership(sess, user, specificUser);
    }
}
Also used : UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) User(cz.metacentrum.perun.core.api.User) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) RichUser(cz.metacentrum.perun.core.api.RichUser) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) AllUserExtSourcesDeletedForUser(cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser) OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

AllUserExtSourcesDeletedForUser (cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser)2 OwnershipDisabledForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser)2 OwnershipEnabledForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser)2 OwnershipRemovedForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser)2 UserAddedToOwnersOfSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser)2 UserExtSourceAddedToUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser)2 UserExtSourceRemovedFromUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser)2 RichUser (cz.metacentrum.perun.core.api.RichUser)2 User (cz.metacentrum.perun.core.api.User)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 RelationNotExistsException (cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException)2 SpecificUserOwnerAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException)1 UserNotAdminException (cz.metacentrum.perun.core.api.exceptions.UserNotAdminException)1