Search in sources :

Example 16 with RelationExistsException

use of cz.metacentrum.perun.core.api.exceptions.RelationExistsException 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)

Example 17 with RelationExistsException

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

the class UsersManagerBlImpl method createServiceUser.

@Override
public User createServiceUser(PerunSession sess, Candidate candidate, List<User> owners) throws WrongAttributeAssignmentException, UserExtSourceExistsException, WrongReferenceAttributeValueException, WrongAttributeValueException, AttributeNotExistsException {
    candidate.setServiceUser(true);
    User serviceUser = createUser(sess, candidate);
    for (User owner : owners) {
        try {
            getPerunBl().getUsersManagerBl().addSpecificUserOwner(sess, owner, serviceUser);
        } catch (RelationExistsException ex) {
            throw new InternalErrorException(ex);
        }
    }
    log.info("Created service user: {}", serviceUser);
    return serviceUser;
}
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)

Example 18 with RelationExistsException

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

the class MembersManagerBlImpl method createServiceMember.

@Override
public Member createServiceMember(PerunSession sess, Vo vo, Candidate candidate, List<User> specificUserOwners, List<Group> groups) throws WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException {
    candidate.setFirstName("(Service)");
    // Set organization only if user in sessione exists (in tests there is no user in sess)
    if (sess.getPerunPrincipal().getUser() != null) {
        String userOrganization = AttributesManager.NS_USER_ATTR_DEF + ":organization";
        String memberOrganization = AttributesManager.NS_MEMBER_ATTR_DEF + ":organization";
        Map<String, String> candidateAttributes = new HashMap<>();
        if (candidate.getAttributes() != null)
            candidateAttributes.putAll(candidate.getAttributes());
        if (candidateAttributes.get(memberOrganization) == null) {
            Attribute actorUserOrganization;
            String actorUserOrganizationValue;
            try {
                actorUserOrganization = perunBl.getAttributesManagerBl().getAttribute(sess, sess.getPerunPrincipal().getUser(), userOrganization);
                actorUserOrganizationValue = (String) actorUserOrganization.getValue();
            } catch (WrongAttributeAssignmentException | AttributeNotExistsException ex) {
                throw new InternalErrorException(ex);
            }
            if (actorUserOrganizationValue != null) {
                candidateAttributes.put(memberOrganization, actorUserOrganizationValue);
                candidate.setAttributes(candidateAttributes);
            }
        }
    }
    // create member for service user from candidate
    Member member = createMember(sess, vo, SpecificUserType.SERVICE, candidate, groups, null);
    // set specific user owners or sponsors
    User specificUser = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    for (User u : specificUserOwners) {
        try {
            getPerunBl().getUsersManagerBl().addSpecificUserOwner(sess, u, specificUser);
        } catch (RelationExistsException ex) {
            throw new InternalErrorException(ex);
        }
    }
    return member;
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)18 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)12 User (cz.metacentrum.perun.core.api.User)8 RichUser (cz.metacentrum.perun.core.api.RichUser)6 Group (cz.metacentrum.perun.core.api.Group)5 Member (cz.metacentrum.perun.core.api.Member)5 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 Facility (cz.metacentrum.perun.core.api.Facility)4 Resource (cz.metacentrum.perun.core.api.Resource)4 GroupNotAdminException (cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException)4 RoleCannotBeManagedException (cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)4 UserNotAdminException (cz.metacentrum.perun.core.api.exceptions.UserNotAdminException)4 AllUserExtSourcesDeletedForUser (cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser)3 Attribute (cz.metacentrum.perun.core.api.Attribute)3 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)3 RichGroup (cz.metacentrum.perun.core.api.RichGroup)3 RichMember (cz.metacentrum.perun.core.api.RichMember)3 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)3 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)3