Search in sources :

Example 1 with Group

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

the class GroupsManagerEntry method createGroup.

public Group createGroup(PerunSession sess, Vo vo, Group group) throws GroupExistsException, PrivilegeException, InternalErrorException, VoNotExistsException {
    Utils.checkPerunSession(sess);
    Utils.notNull(group, "group");
    Utils.notNull(group.getName(), "group.name");
    if (!group.getName().matches(GroupsManager.GROUP_SHORT_NAME_REGEXP)) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong group name, group name must matches " + GroupsManager.GROUP_SHORT_NAME_REGEXP));
    }
    if (group.getParentGroupId() != null)
        throw new InternalErrorException("Top-level groups can't have parentGroupId set!");
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.TOPGROUPCREATOR, vo)) {
        throw new PrivilegeException(sess, "createGroup");
    }
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    Group createdGroup = getGroupsManagerBl().createGroup(sess, vo, group);
    //Refresh authz
    AuthzResolver.refreshAuthz(sess);
    return createdGroup;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)

Example 2 with Group

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

the class MembersManagerEntry method createMember.

public Member createMember(PerunSession sess, Vo vo, Candidate candidate, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, VoNotExistsException, PrivilegeException, ExtendMembershipException, GroupNotExistsException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    // if any group is not from the vo, throw an exception
    if (groups != null) {
        for (Group group : groups) {
            perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
            if (group.getVoId() != vo.getId())
                throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where candidate " + candidate + " should be added.");
        }
    }
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
        throw new PrivilegeException(sess, "createMember - from candidate");
    }
    Utils.notNull(candidate, "candidate");
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    return getMembersManagerBl().createMember(sess, vo, candidate, groups);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 3 with Group

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

the class MembersManagerEntry method createMember.

public Member createMember(PerunSession sess, Vo vo, ExtSource extSource, String login, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, VoNotExistsException, ExtSourceNotExistsException, PrivilegeException, GroupNotExistsException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    getPerunBl().getExtSourcesManagerBl().checkExtSourceExists(sess, extSource);
    // if any group is not from the vo, throw an exception
    if (groups != null) {
        for (Group group : groups) {
            perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
            if (group.getVoId() != vo.getId())
                throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where user with login " + login + " from ExtSource " + extSource + " should be added.");
        }
    }
    // Authorization for vo admin and perun admin automatic
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
        //also group admin of all affected groups is ok
        if (groups != null && !groups.isEmpty()) {
            boolean groupAdminOfAllGroups = true;
            boolean authorizedToExtSource = false;
            for (Group group : groups) {
                //User in session has to be GroupAdmin of all affected groups
                if (!AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, group)) {
                    groupAdminOfAllGroups = false;
                    break;
                }
                //User in session has to have at least one right to work with the ExtSource
                List<ExtSource> groupExtSources = getPerunBl().getExtSourcesManagerBl().getGroupExtSources(sess, group);
                if (groupExtSources.contains(extSource))
                    authorizedToExtSource = true;
            }
            if (!groupAdminOfAllGroups || !authorizedToExtSource) {
                throw new PrivilegeException(sess, "createMember - from login and extSource -- authorized to extSource=" + authorizedToExtSource + " and groupAdmin in all groups=" + groupAdminOfAllGroups);
            }
        } else {
            throw new PrivilegeException(sess, "createMember - from login and extSource");
        }
    }
    // we run async validation
    Member member = getMembersManagerBl().createMember(sess, vo, extSource, login, groups);
    getMembersManagerBl().validateMemberAsync(sess, member);
    return member;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 4 with Group

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

the class MembersManagerEntry method createSpecificMember.

public Member createSpecificMember(PerunSession sess, Vo vo, Candidate candidate, List<User> specificUserOwners, SpecificUserType specificUserType, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, VoNotExistsException, PrivilegeException, UserNotExistsException, ExtendMembershipException, GroupNotExistsException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    Utils.notNull(specificUserType, "specificUserType");
    //normal type is not allowed when creating specific member
    if (specificUserType.equals(SpecificUserType.NORMAL))
        throw new InternalErrorException("Type of specific user must be defined.");
    // if any group is not from the vo, throw an exception
    if (groups != null) {
        for (Group group : groups) {
            perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
            if (group.getVoId() != vo.getId())
                throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where candidate " + candidate + " should be added.");
        }
    }
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
        throw new PrivilegeException(sess, "createSpecificMember (Specific User) - from candidate");
    }
    Utils.notNull(candidate, "candidate");
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    if (specificUserOwners.isEmpty())
        throw new InternalErrorException("List of specificUserOwners of " + candidate + " can't be empty.");
    for (User u : specificUserOwners) {
        getPerunBl().getUsersManagerBl().checkUserExists(sess, u);
    }
    return getMembersManagerBl().createSpecificMember(sess, vo, candidate, specificUserOwners, specificUserType, groups);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 5 with Group

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

the class MembersManagerEntry method createMember.

public Member createMember(PerunSession sess, Vo vo, User user, List<Group> groups) throws InternalErrorException, AlreadyMemberException, WrongAttributeValueException, WrongReferenceAttributeValueException, VoNotExistsException, UserNotExistsException, PrivilegeException, ExtendMembershipException, GroupNotExistsException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
        throw new PrivilegeException(sess, "createMember - from user");
    }
    // if any group is not from the vo, throw an exception
    if (groups != null) {
        for (Group group : groups) {
            perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
            if (group.getVoId() != vo.getId())
                throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where user " + user + " should be added.");
        }
    }
    return getMembersManagerBl().createMember(sess, vo, user, groups);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

Group (cz.metacentrum.perun.core.api.Group)209 Test (org.junit.Test)128 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)124 RichGroup (cz.metacentrum.perun.core.api.RichGroup)56 Member (cz.metacentrum.perun.core.api.Member)55 Resource (cz.metacentrum.perun.core.api.Resource)49 Vo (cz.metacentrum.perun.core.api.Vo)48 User (cz.metacentrum.perun.core.api.User)46 ArrayList (java.util.ArrayList)42 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)36 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)35 Attribute (cz.metacentrum.perun.core.api.Attribute)34 RichUser (cz.metacentrum.perun.core.api.RichUser)26 Facility (cz.metacentrum.perun.core.api.Facility)24 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)18 RichResource (cz.metacentrum.perun.core.api.RichResource)17 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)15 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)13 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)11 ExtSource (cz.metacentrum.perun.core.api.ExtSource)11