Search in sources :

Example 1 with MembershipMismatchException

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

the class GroupsManagerEntry method addMember.

public void addMember(PerunSession sess, Group group, Member member) throws InternalErrorException, MemberNotExistsException, PrivilegeException, AlreadyMemberException, GroupNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException, NotMemberOfParentGroupException, WrongAttributeAssignmentException, AttributeNotExistsException, ExternallyManagedException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    getGroupsManagerBl().checkGroupExists(sess, group);
    getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, group) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, group)) {
        throw new PrivilegeException(sess, "addMember");
    }
    // Check if the member and group are from the same VO
    if (member.getVoId() != (group.getVoId())) {
        throw new MembershipMismatchException("Member and group are form the different VO");
    }
    // Check if the group is externally synchronized
    Attribute attrSynchronizeEnabled = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GROUPSYNCHROENABLED_ATTRNAME);
    if (Objects.equals("true", (String) attrSynchronizeEnabled.getValue())) {
        throw new ExternallyManagedException("Adding of member is not allowed. Group is externally managed.");
    }
    getGroupsManagerBl().addMember(sess, group, member);
}
Also used : MembershipMismatchException(cz.metacentrum.perun.core.api.exceptions.MembershipMismatchException) ExternallyManagedException(cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException) Attribute(cz.metacentrum.perun.core.api.Attribute) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1 ExternallyManagedException (cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException)1 MembershipMismatchException (cz.metacentrum.perun.core.api.exceptions.MembershipMismatchException)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1