Search in sources :

Example 1 with GroupsManagerBl

use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.

the class VOOT method createVOOTGroups.

/**
	 * This method creates groups used by VOOT, that are represented to end-user. They are created from groups by provider.
	 *
	 * @param groups            groups from provider
	 * @return                  array of groups, that are represented to end-user
	 * @throws VOOTException    if can not read groups by provider
	 */
private VOOTGroup[] createVOOTGroups(List<Group> groups) throws VOOTException {
    GroupsManagerBl groupManager = perun.getGroupsManagerBl();
    VOOTGroup[] vootGroups = new VOOTGroup[groups.size()];
    int i = 0;
    for (Group group : groups) {
        String vootMembership;
        try {
            if (groupManager.getAdmins(session, group).contains(user)) {
                vootMembership = "admin";
            } else {
                vootMembership = "member";
            }
            vootGroups[i] = new VOOTGroup(group, groupManager.getVo(session, group).getShortName(), vootMembership);
            i++;
        } catch (InternalErrorException ex) {
            throw new VOOTException("internal_server_error");
        }
    }
    return vootGroups;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 2 with GroupsManagerBl

use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.

the class ResourcesManagerBlImpl method assignGroupsToResource.

@Override
public void assignGroupsToResource(PerunSession perunSession, Iterable<Group> groups, Resource resource, boolean async, boolean assignInactive, boolean autoAssignSubgroups) throws WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
    for (Group g : groups) {
        getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(perunSession, g, resource);
        // assign source group
        try {
            getResourcesManagerImpl().assignGroupToResource(perunSession, g, resource, autoAssignSubgroups);
            setAssignedGroupStatusAndActivate(perunSession, resource, async, assignInactive, g);
        } catch (GroupAlreadyAssignedException e) {
        // silently skip
        }
        if (autoAssignSubgroups) {
            GroupsManagerBl groupsManager = getPerunBl().getGroupsManagerBl();
            List<Group> subgroups;
            // If it is 'members' group, use all groups from corresponding VO (except for members, they've been assigned already)
            if (g.getName().equals(VosManager.MEMBERS_GROUP)) {
                subgroups = groupsManager.getAllGroups(perunSession, groupsManager.getVo(perunSession, g));
                subgroups.removeIf((group -> group.getName().equals(VosManager.MEMBERS_GROUP)));
            } else {
                subgroups = groupsManager.getAllSubGroups(perunSession, g);
            }
            for (Group subgroup : subgroups) {
                try {
                    assignAutomaticGroupToResource(perunSession, g, subgroup, resource);
                } catch (GroupAlreadyAssignedException e) {
                // silently skip
                }
            }
        }
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) Vo(cz.metacentrum.perun.core.api.Vo) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException) LoggerFactory(org.slf4j.LoggerFactory) GroupResourceAssignment(cz.metacentrum.perun.core.api.GroupResourceAssignment) ServicesPackage(cz.metacentrum.perun.core.api.ServicesPackage) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) Role(cz.metacentrum.perun.core.api.Role) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) ResourceTagAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagAlreadyAssignedException) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) ResourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ResourceAlreadyRemovedException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Objects(java.util.Objects) VosManager(cz.metacentrum.perun.core.api.VosManager) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) Optional(java.util.Optional) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) Service(cz.metacentrum.perun.core.api.Service) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Resource(cz.metacentrum.perun.core.api.Resource) ResourceDeleted(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted) Async(org.springframework.scheduling.annotation.Async) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) ObjectUtils.isEmpty(org.apache.commons.lang3.ObjectUtils.isEmpty) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) GroupResourceStatusException(cz.metacentrum.perun.core.api.exceptions.GroupResourceStatusException) ServiceRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) ResourceCreated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceCreated) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) ResourceTagNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotAssignedException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) ResourceUpdated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceUpdated) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) RichResource(cz.metacentrum.perun.core.api.RichResource) RichUser(cz.metacentrum.perun.core.api.RichUser) ServiceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceAlreadyAssignedException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) ResourceExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceExistsException) ResourcesManagerImplApi(cz.metacentrum.perun.core.implApi.ResourcesManagerImplApi) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) ResourceTagNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotExistsException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException)

Example 3 with GroupsManagerBl

use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.

the class urn_perun_user_facility_attribute_def_def_defaultUnixGIDTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_user_facility_attribute_def_def_defaultUnixGID();
    attributeToCheck = new Attribute();
    attributeToCheck.setValue(5);
    namespace = new Attribute();
    namespace.setValue("namespace");
    unixGroupNamespace = new Attribute();
    unixGroupNamespace.setValue("unixGroupNamespace");
    resourceGidAttribute = new Attribute();
    resourceGidAttribute.setValue("resourceGidAttribute");
    groupGidAttribute = new Attribute();
    groupGidAttribute.setValue("groupGidAttribute");
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace")).thenReturn(namespace);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGroupName-namespace")).thenReturn(unixGroupNamespace);
    when(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespace.valueAsString())).thenReturn(resourceGidAttribute);
    when(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + namespace.valueAsString())).thenReturn(groupGidAttribute);
    ResourcesManagerBl resourcesManagerBl = mock(ResourcesManagerBl.class);
    when(sess.getPerunBl().getResourcesManagerBl()).thenReturn(resourcesManagerBl);
    UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
    when(sess.getPerunBl().getUsersManagerBl()).thenReturn(usersManagerBl);
    GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
    when(sess.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl);
    when(sess.getPerunBl().getGroupsManagerBl().getGroupsByAttribute(sess, groupGidAttribute)).thenReturn(new ArrayList<>());
    FacilitiesManagerBl facilitiesManagerBl = mock(FacilitiesManagerBl.class);
    when(sess.getPerunBl().getFacilitiesManagerBl()).thenReturn(facilitiesManagerBl);
    when(sess.getPerunBl().getFacilitiesManagerBl().getAllowedGroups(sess, facility, null, null)).thenReturn(new ArrayList<>());
}
Also used : ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) FacilitiesManagerBl(cz.metacentrum.perun.core.bl.FacilitiesManagerBl) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 4 with GroupsManagerBl

use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.

the class urn_perun_group_attribute_def_def_groupStructureSynchronizationEnabledTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_group_attribute_def_def_groupStructureSynchronizationEnabled();
    reqAttribute = new Attribute(classInstance.getAttributeDefinition());
    attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
    when(sess.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl);
    when(sess.getPerunBl().getGroupsManagerBl().isGroupSynchronizedFromExternallSource(sess, group)).thenReturn(false);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPSYNCHROENABLED_ATTRNAME)).thenReturn(reqAttribute);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPSQUERY_ATTRNAME)).thenReturn(reqAttribute);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPMEMBERSQUERY_ATTRNAME)).thenReturn(reqAttribute);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME)).thenReturn(reqAttribute);
}
Also used : GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 5 with GroupsManagerBl

use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.

the class urn_perun_group_attribute_def_def_groupSynchronizationTimesTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_group_attribute_def_def_groupSynchronizationTimes();
    syncInterval = new Attribute(classInstance.getAttributeDefinition());
    attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
    when(sess.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl);
    when(sess.getPerunBl().getGroupsManagerBl().isGroupSynchronizedFromExternallSource(sess, group)).thenReturn(false);
    AttributesManagerBl attributesManagerBl;
    attributesManagerBl = mock(AttributesManagerBl.class);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPSYNCHROINTERVAL_ATTRNAME)).thenReturn(syncInterval);
}
Also used : GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Aggregations

GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)18 Attribute (cz.metacentrum.perun.core.api.Attribute)14 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)14 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)13 AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)12 Before (org.junit.Before)12 Group (cz.metacentrum.perun.core.api.Group)6 ResourcesManagerBl (cz.metacentrum.perun.core.bl.ResourcesManagerBl)6 Member (cz.metacentrum.perun.core.api.Member)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 ModulesUtilsBl (cz.metacentrum.perun.core.bl.ModulesUtilsBl)4 User (cz.metacentrum.perun.core.api.User)3 Vo (cz.metacentrum.perun.core.api.Vo)3 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)3 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)3 ArrayList (java.util.ArrayList)3 AttributesManager (cz.metacentrum.perun.core.api.AttributesManager)2 Facility (cz.metacentrum.perun.core.api.Facility)2 Resource (cz.metacentrum.perun.core.api.Resource)2 Status (cz.metacentrum.perun.core.api.Status)2