Search in sources :

Example 6 with ExternallyManagedException

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

the class GroupsManagerEntry method createGroup.

@Override
public Group createGroup(PerunSession sess, Group parentGroup, Group group) throws GroupNotExistsException, GroupExistsException, PrivilegeException, GroupRelationNotAllowed, GroupRelationAlreadyExists, ExternallyManagedException {
    Utils.checkPerunSession(sess);
    getGroupsManagerBl().checkGroupExists(sess, parentGroup);
    Utils.notNull(group, "group");
    Utils.notNull(group.getName(), "group.name");
    Utils.validateGroupName(group.getName());
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "createGroup_Group_Group_policy", parentGroup)) {
        throw new PrivilegeException(sess, "createGroup - subGroup");
    }
    if (getGroupsManagerBl().isGroupInStructureSynchronizationTree(sess, parentGroup)) {
        throw new ExternallyManagedException("Parent group " + parentGroup + " is externally managed");
    }
    Group createdGroup = getGroupsManagerBl().createGroup(sess, parentGroup, group);
    // Refresh authz
    AuthzResolver.refreshAuthz(sess);
    return createdGroup;
}
Also used : ExternallyManagedException(cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException) Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Example 7 with ExternallyManagedException

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

the class GroupsManagerEntry method deleteGroups.

@Override
public void deleteGroups(PerunSession perunSession, List<Group> groups, boolean forceDelete) throws GroupNotExistsException, PrivilegeException, GroupAlreadyRemovedException, RelationExistsException, GroupAlreadyRemovedFromResourceException, GroupRelationDoesNotExist, GroupRelationCannotBeRemoved, ExternallyManagedException {
    Utils.checkPerunSession(perunSession);
    Utils.notNull(groups, "groups");
    // Test if all groups exists and user has right to delete all of them
    for (Group group : groups) {
        getGroupsManagerBl().checkGroupExists(perunSession, group);
        if (getGroupsManagerBl().isGroupInStructureSynchronizationTree(perunSession, group) || getGroupsManagerBl().hasGroupSynchronizedChild(perunSession, group)) {
            throw new ExternallyManagedException("Group " + group + " or some of the subGroups are externally managed!");
        }
    }
    // Authorization
    for (Group group : groups) {
        if (!AuthzResolver.authorizedInternal(perunSession, "deleteGroups_List<Group>_boolean_policy", group)) {
            throw new PrivilegeException(perunSession, "deleteGroups");
        }
    }
    getGroupsManagerBl().deleteGroups(perunSession, groups, forceDelete);
}
Also used : ExternallyManagedException(cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException) Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Example 8 with ExternallyManagedException

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

the class GroupsManagerEntry method addMember.

@Override
public void addMember(PerunSession sess, List<Group> groups, Member member) throws MemberNotExistsException, PrivilegeException, AlreadyMemberException, GroupNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException, AttributeNotExistsException, ExternallyManagedException {
    Utils.checkPerunSession(sess);
    getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
    for (Group group : groups) {
        getGroupsManagerBl().checkGroupExists(sess, group);
        // 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 ("true".equals(attrSynchronizeEnabled.getValue()) || getGroupsManagerBl().isGroupInStructureSynchronizationTree(sess, group)) {
            throw new ExternallyManagedException("Adding of member is not allowed. Group is externally managed.");
        }
    }
    List<Group> groupsMemberIsNotDirect = new ArrayList<>();
    for (Group group : groups) {
        // Authorization
        if (!AuthzResolver.authorizedInternal(sess, "addMember_List<Group>_Member_policy", group, member)) {
            throw new PrivilegeException(sess, "addMember");
        }
        // Filter groups where member is direct member
        if (!isDirectGroupMember(sess, group, member)) {
            groupsMemberIsNotDirect.add(group);
        }
    }
    getGroupsManagerBl().addMember(sess, groupsMemberIsNotDirect, member);
}
Also used : MembershipMismatchException(cz.metacentrum.perun.core.api.exceptions.MembershipMismatchException) ExternallyManagedException(cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException) Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Aggregations

ExternallyManagedException (cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException)8 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)8 Attribute (cz.metacentrum.perun.core.api.Attribute)6 Group (cz.metacentrum.perun.core.api.Group)4 RichGroup (cz.metacentrum.perun.core.api.RichGroup)4 MembershipMismatchException (cz.metacentrum.perun.core.api.exceptions.MembershipMismatchException)3 Member (cz.metacentrum.perun.core.api.Member)2 RichMember (cz.metacentrum.perun.core.api.RichMember)2 ArrayList (java.util.ArrayList)1