Search in sources :

Example 11 with GroupsManagerBl

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

the class RegistrarBaseIntegrationTest method testRejectApplicationsAfterMemberRemoval.

@Test
public void testRejectApplicationsAfterMemberRemoval() throws PerunException {
    GroupsManagerBl groupsManager = perun.getGroupsManagerBl();
    MembersManagerBl membersManager = perun.getMembersManagerBl();
    // create group in VO, generate group application form
    Group group1 = new Group("GroupA", "Cool folks");
    groupsManager.createGroup(session, vo, group1);
    registrarManager.createApplicationFormInGroup(session, group1);
    // create user
    User user = new User(-1, "Jo", "Doe", "", "", "");
    user = perun.getUsersManagerBl().createUser(session, user);
    Member member = membersManager.createMember(session, vo, user);
    Application groupApplication = prepareApplicationToGroup(user, group1);
    List<ApplicationFormItemData> appItemsData = new ArrayList<>();
    registrarManager.submitApplication(session, groupApplication, appItemsData);
    membersManager.deleteMember(session, member);
    List<Application> group1Apps = registrarManager.getApplicationsForGroup(session, group1, List.of("REJECTED"));
    assertEquals(1, group1Apps.size());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) User(cz.metacentrum.perun.core.api.User) MembersManagerBl(cz.metacentrum.perun.core.bl.MembersManagerBl) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) Member(cz.metacentrum.perun.core.api.Member) Application(cz.metacentrum.perun.registrar.model.Application) RichApplication(cz.metacentrum.perun.registrar.model.RichApplication) Test(org.junit.Test)

Example 12 with GroupsManagerBl

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

the class GroupSynchronizer method synchronizeGroups.

public void synchronizeGroups() {
    PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
    boolean shouldWriteExceptionLog = true;
    try {
        log.debug("Group synchronization - getting list of VOs");
        List<Vo> vos = perun.getVosManagerBl().getVos(ldapcManager.getPerunSession());
        Set<Name> presentGroups = new HashSet<Name>();
        for (Vo vo : vos) {
            try {
                log.debug("Getting list of groups for VO {}", vo);
                List<Group> groups = perun.getGroupsManagerBl().getAllGroups(ldapcManager.getPerunSession(), vo);
                for (Group group : groups) {
                    presentGroups.add(perunGroup.getEntryDN(String.valueOf(vo.getId()), String.valueOf(group.getId())));
                    log.debug("Synchronizing group {}", group);
                    log.debug("Getting list of attributes for group {}", group.getId());
                    List<Attribute> attrs = new ArrayList<Attribute>();
                    List<String> attrNames = fillPerunAttributeNames(perunGroup.getPerunAttributeNames());
                    try {
                        attrs.addAll(perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), group, attrNames));
                    } catch (PerunRuntimeException e) {
                        log.warn("Couldn't get attributes {} for group {}: {}", attrNames, group.getId(), e.getMessage());
                        shouldWriteExceptionLog = false;
                        throw new InternalErrorException(e);
                    }
                    log.debug("Got attributes {}", attrNames.toString());
                    try {
                        log.debug("Getting list of members for group {}", group.getId());
                        // List<Member> members = ldapcManager.getRpcCaller().call("groupsManager",  "getGroupMembers", params).readList(Member.class);
                        List<Member> members = perun.getGroupsManagerBl().getActiveGroupMembers(ldapcManager.getPerunSession(), group, Status.VALID);
                        log.debug("Synchronizing {} members of group {}", members.size(), group.getId());
                        // perunGroup.synchronizeMembers(group, members);
                        log.debug("Getting list of resources assigned to group {}", group.getId());
                        // List<Resource> resources = Rpc.ResourcesManager.getAssignedResources(ldapcManager.getRpcCaller(), group);
                        List<Resource> resources = perun.getResourcesManagerBl().getAssignedResources(ldapcManager.getPerunSession(), group);
                        log.debug("Synchronizing {} resources assigned to group {}", resources.size(), group.getId());
                        // perunGroup.synchronizeResources(group, resources);
                        GroupsManagerBl groupsManager = perun.getGroupsManagerBl();
                        List<Group> admin_groups = groupsManager.getGroupsWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
                        List<Vo> admin_vos = groupsManager.getVosWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
                        List<Facility> admin_facilities = groupsManager.getFacilitiesWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
                        log.debug("Synchronizing group {} as admin of {} groups, {} VOs and {} facilities", group.getId(), admin_groups.size(), admin_vos.size(), admin_facilities.size());
                        perunGroup.synchronizeGroup(group, attrs, members, resources, admin_groups, admin_vos, admin_facilities);
                    } catch (PerunRuntimeException e) {
                        log.error("Error synchronizing group", e);
                        shouldWriteExceptionLog = false;
                        throw new InternalErrorException(e);
                    }
                }
            } catch (PerunRuntimeException e) {
                if (shouldWriteExceptionLog) {
                    log.error("Error synchronizing groups", e);
                }
                shouldWriteExceptionLog = false;
                throw new InternalErrorException(e);
            }
        }
        try {
            removeOldEntries(perunGroup, presentGroups, log);
        } catch (InternalErrorException e) {
            log.error("Error removing old group entries", e);
            shouldWriteExceptionLog = false;
            throw new InternalErrorException(e);
        }
    } catch (InternalErrorException e) {
        if (shouldWriteExceptionLog) {
            log.error("Error reading list of VOs", e);
        }
        throw new InternalErrorException(e);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PerunGroup(cz.metacentrum.perun.ldapc.model.PerunGroup) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Name(javax.naming.Name) Vo(cz.metacentrum.perun.core.api.Vo) PerunRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet)

Example 13 with GroupsManagerBl

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

the class urn_perun_user_attribute_def_virt_eduPersonScopedAffiliations method getAffiliationsFromGroups.

/**
 * Collect affiliations from perun Groups
 * @param sess Perun session
 * @param user User for whom the values should be collected
 * @return Set of collected affiliations
 * @throws InternalErrorException When some error occurs, see exception cause for details.
 */
private Set<String> getAffiliationsFromGroups(PerunSessionImpl sess, User user) {
    Set<String> result = new HashSet<>();
    List<Member> validVoMembers = sess.getPerunBl().getMembersManagerBl().getMembersByUserWithStatus(sess, user, Status.VALID);
    GroupsManagerBl groupsManagerBl = sess.getPerunBl().getGroupsManagerBl();
    Set<Group> groupsForAttrCheck = new HashSet<>();
    for (Member member : validVoMembers) {
        groupsForAttrCheck.addAll(groupsManagerBl.getGroupsWhereMemberIsActive(sess, member));
    }
    if (!groupsForAttrCheck.isEmpty()) {
        try {
            // check, if attribute exists
            sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, getTertiarySourceAttributeName());
        } catch (AttributeNotExistsException e) {
            log.debug("Attribute " + getTertiarySourceAttributeFriendlyName() + " does not exist", e);
            return result;
        }
    }
    for (Group group : groupsForAttrCheck) {
        try {
            Attribute groupAffiliations = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, getTertiarySourceAttributeName());
            if (groupAffiliations != null && groupAffiliations.valueAsList() != null) {
                result.addAll(groupAffiliations.valueAsList());
            }
        } catch (WrongAttributeAssignmentException e) {
            throw new InternalErrorException("Wrong assignment of " + getTertiarySourceAttributeFriendlyName() + " for user " + user.getId(), e);
        } catch (AttributeNotExistsException e) {
            log.debug("Attribute " + getTertiarySourceAttributeFriendlyName() + " of group " + group.getId() + " does not exist, values will be skipped", e);
        }
    }
    return result;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) AttributeRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroup) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) AllAttributesRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) AttributeSetForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroup) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) 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) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet)

Example 14 with GroupsManagerBl

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

the class urn_perun_group_attribute_def_virt_adDisplayName_o365muTest method setUp.

@Before
public void setUp() throws Exception {
    // prepare mocks
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    AttributesManagerBl am = mock(AttributesManagerBl.class);
    GroupsManagerBl gm = mock(GroupsManagerBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    when(perunBl.getAttributesManagerBl()).thenReturn(am);
    when(perunBl.getGroupsManagerBl()).thenReturn(gm);
    when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupB)).thenReturn(groupA);
    when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupC)).thenReturn(groupB);
    when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupD)).thenReturn(groupC);
    when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupE)).thenReturn(groupD);
    when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupF)).thenReturn(groupA);
    // group A is the main group with cispr 000000, it has no default display name
    setWhenClauseByParametersForGroup(sess, groupA, null, "000000", groupA.getName(), groupA.getDescription(), typeOfWorkplacesA);
    // group B is special group which should return null on display name
    setWhenClauseByParametersForGroup(sess, groupB, null, "000001", groupB.getName(), groupB.getDescription(), typeOfWorkplacesA);
    // group C is other part of university, it has no default display name
    setWhenClauseByParametersForGroup(sess, groupC, null, "110000", groupC.getName(), groupC.getDescription(), typeOfWorkplacesB);
    // group D is special group with predefined display name
    setWhenClauseByParametersForGroup(sess, groupD, predefinedDisplayName, null, null, null, null);
    // group E is other type of group, it has no default display name
    setWhenClauseByParametersForGroup(sess, groupE, null, "123456", groupE.getName(), groupE.getDescription(), typeOfWorkplacesC);
    // group E is other type of group, it has no default display name, but displayName is missing
    setWhenClauseByParametersForGroup(sess, groupF, null, "654321", groupF.getName(), groupF.getDescription(), typeOfWorkplacesB);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, groupWithoutAttributes, defaultAdDisplayNameAttrDef.getName())).thenThrow(AttributeNotExistsException.class);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, groupWithoutAttributes, inetCisprAttrDef.getName())).thenThrow(AttributeNotExistsException.class);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, groupWithoutAttributes, inetWorkplacesTypeCSAttrDef.getName())).thenThrow(AttributeNotExistsException.class);
}
Also used : GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) 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 15 with GroupsManagerBl

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

the class urn_perun_group_attribute_def_def_groupExtSourceTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_group_attribute_def_def_groupExtSource();
    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(perunBl.getGroupsManagerBl()).thenReturn(groupsManagerBl);
    Vo groupVo = mock(Vo.class);
    VosManagerBl vosManagerBl = mock(VosManagerBl.class);
    when(perunBl.getVosManagerBl()).thenReturn(vosManagerBl);
    when(sess.getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId())).thenReturn(groupVo);
    ExtSource extSource = new ExtSource(1, "my_example", "type");
    ExtSourcesManagerBl extSourcesManagerBl = mock(ExtSourcesManagerBl.class);
    when(sess.getPerunBl().getExtSourcesManagerBl()).thenReturn(extSourcesManagerBl);
    when(sess.getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, groupVo)).thenReturn(Collections.singletonList(extSource));
}
Also used : GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) VosManagerBl(cz.metacentrum.perun.core.bl.VosManagerBl) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Vo(cz.metacentrum.perun.core.api.Vo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourcesManagerBl(cz.metacentrum.perun.core.bl.ExtSourcesManagerBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) 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