Search in sources :

Example 1 with OwnershipEnabledForSpecificUser

use of cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser in project perun by CESNET.

the class UsersManagerBlImpl method addSpecificUserOwner.

@Override
public void addSpecificUserOwner(PerunSession sess, User user, User specificUser) throws RelationExistsException {
    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 RelationExistsException("User is already the active owner of specific user.");
    if (getUsersManagerImpl().specificUserOwnershipExists(sess, user, specificUser)) {
        getUsersManagerImpl().enableOwnership(sess, user, specificUser);
        getPerunBl().getAuditer().log(sess, new OwnershipEnabledForSpecificUser(user, specificUser));
    } else {
        getPerunBl().getAuditer().log(sess, new UserAddedToOwnersOfSpecificUser(user, specificUser));
        getUsersManagerImpl().addSpecificUserOwner(sess, user, specificUser);
    }
    try {
        // refresh authz for sponsors
        if (specificUser.isSponsoredUser())
            AuthzResolverBlImpl.addSpecificUserOwner(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 (AlreadyAdminException ex) {
        throw new InternalErrorException("User " + user + " is already sponsor of sponsored user " + specificUser);
    }
}
Also used : 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) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Aggregations

AllUserExtSourcesDeletedForUser (cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser)1 OwnershipDisabledForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser)1 OwnershipEnabledForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser)1 OwnershipRemovedForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser)1 UserAddedToOwnersOfSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser)1 UserExtSourceAddedToUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser)1 UserExtSourceRemovedFromUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 User (cz.metacentrum.perun.core.api.User)1 AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)1