Search in sources :

Example 6 with WsSubject

use of edu.internet2.middleware.grouperClient.ws.beans.WsSubject in project uhgroupings by uhawaii-system-its-ti-iam.

the class GrouperFactoryServiceImplLocal method makeWsGetMembersResults.

@Override
public WsGetMembersResults makeWsGetMembersResults(String subjectAttributeName, WsSubjectLookup lookup, String groupName) {
    WsGetMembersResults wsGetMembersResults = new WsGetMembersResults();
    String[] attributeNames = new String[] { UID_KEY, UUID_KEY, LAST_NAME_KEY, COMPOSITE_NAME_KEY, FIRST_NAME_KEY };
    wsGetMembersResults.setSubjectAttributeNames(attributeNames);
    WsGetMembersResult wsGetMembersResult = new WsGetMembersResult();
    WsSubject[] subjects;
    Group group = groupRepository.findByPath(groupName);
    List<Person> members = group.getMembers();
    List<WsSubject> subjectList = new ArrayList<>();
    for (Person person : members) {
        WsSubject subject = new WsSubject();
        subject.setId(person.getUuid());
        subject.setName(person.getName());
        // has to be the same order as attributeNames array
        subject.setAttributeValues(new String[] { person.getUsername(), person.getUuid(), person.getLastName(), person.getName(), person.getFirstName() });
        subjectList.add(subject);
    }
    subjects = subjectList.toArray(new WsSubject[subjectList.size()]);
    wsGetMembersResult.setWsSubjects(subjects);
    wsGetMembersResults.setResults(new WsGetMembersResult[] { wsGetMembersResult });
    return wsGetMembersResults;
}
Also used : WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) Group(edu.hawaii.its.api.type.Group) WsGetMembersResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResult) ArrayList(java.util.ArrayList) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject) WsGetMembersResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults) Person(edu.hawaii.its.api.type.Person)

Example 7 with WsSubject

use of edu.internet2.middleware.grouperClient.ws.beans.WsSubject in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingAssignmentServiceImpl method makeGroup.

// makes a group filled with members from membersResults
@Override
public Group makeGroup(WsGetMembersResults membersResults) {
    Group group = new Group();
    try {
        WsSubject[] subjects = membersResults.getResults()[0].getWsSubjects();
        String[] attributeNames = membersResults.getSubjectAttributeNames();
        if (subjects.length > 0) {
            for (WsSubject subject : subjects) {
                if (subject != null) {
                    group.addMember(makePerson(subject, attributeNames));
                }
            }
        }
    } catch (NullPointerException npe) {
        return new Group();
    }
    return group;
}
Also used : WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) Group(edu.hawaii.its.api.type.Group) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject)

Example 8 with WsSubject

use of edu.internet2.middleware.grouperClient.ws.beans.WsSubject in project uPortal by Jasig.

the class GrouperEntityGroupStore method findEntitiesForGroup.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#findEntitiesForGroup(org.apereo.portal.groups.IEntityGroup)
     */
@Override
@SuppressWarnings("unchecked")
public Iterator findEntitiesForGroup(IEntityGroup group) throws GroupsException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching Grouper for members of the group with key: " + group.getKey());
    }
    try {
        // execute a search for members of the specified group
        GcGetMembers getGroupsMembers = new GcGetMembers();
        getGroupsMembers.addGroupName(group.getLocalKey());
        getGroupsMembers.assignIncludeSubjectDetail(true);
        WsGetMembersResults results = getGroupsMembers.execute();
        if (results == null || results.getResults() == null || results.getResults().length == 0 || results.getResults()[0].getWsSubjects() == null) {
            LOGGER.debug("No members found for Grouper group with key " + group.getLocalKey());
            return Collections.<IGroupMember>emptyList().iterator();
        }
        WsSubject[] gInfos = results.getResults()[0].getWsSubjects();
        final List<IGroupMember> members = new ArrayList<IGroupMember>(gInfos.length);
        // add each result to the member list
        for (WsSubject gInfo : gInfos) {
            // if the member is not a group (aka person)
            if (!StringUtils.equals(gInfo.getSourceId(), "g:gsa")) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("creating leaf member:" + gInfo.getId() + " and name: " + gInfo.getName() + " from group: " + group.getLocalKey());
                }
                // use the name instead of id as it shows better in the display
                IGroupMember member = new EntityImpl(gInfo.getName(), IPerson.class);
                members.add(member);
            }
        }
        // return an iterator for the assembled group
        return members.iterator();
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "member entities of group with key " + group.getKey() + " from Grouper web services: " + e.getMessage());
        return Collections.<IGroupMember>emptyList().iterator();
    }
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityImpl(org.apereo.portal.groups.EntityImpl) ArrayList(java.util.ArrayList) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject) GcGetMembers(edu.internet2.middleware.grouperClient.api.GcGetMembers) WsGetMembersResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults) GroupsException(org.apereo.portal.groups.GroupsException)

Example 9 with WsSubject

use of edu.internet2.middleware.grouperClient.ws.beans.WsSubject in project uPortal by Jasig.

the class GrouperEntityGroupStore method findMemberGroups.

@Override
@SuppressWarnings("unchecked")
public Iterator findMemberGroups(IEntityGroup group) throws GroupsException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching for group-type members of group with key: " + group.getKey());
    }
    try {
        if (!validKey(group.getLocalKey())) {
            return Collections.<IEntityGroup>emptyList().iterator();
        }
        GcGetMembers gcGetMembers = new GcGetMembers();
        gcGetMembers.addGroupName(group.getLocalKey());
        gcGetMembers.assignIncludeSubjectDetail(true);
        gcGetMembers.addSourceId("g:gsa");
        WsGetMembersResults results = gcGetMembers.execute();
        if (results == null || results.getResults() == null || results.getResults().length == 0 || results.getResults()[0].getWsSubjects() == null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("No group-type members found for group with key " + group.getKey());
            }
            return Collections.<IEntityGroup>emptyList().iterator();
        }
        final List<IEntityGroup> members = new ArrayList<IEntityGroup>();
        WsSubject[] subjects = results.getResults()[0].getWsSubjects();
        for (WsSubject wsSubject : subjects) {
            if (validKey(wsSubject.getName())) {
                WsGroup wsGroup = findGroupFromKey(wsSubject.getName());
                if (wsGroup != null) {
                    IEntityGroup member = createUportalGroupFromGrouperGroup(wsGroup);
                    members.add(member);
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("found IEntityGroup member: " + member);
                    }
                }
            }
        }
        return members.iterator();
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "member groups of group with key " + group.getKey() + " from Grouper web services: " + e.getMessage());
        return Collections.<IGroupMember>emptyList().iterator();
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) ArrayList(java.util.ArrayList) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject) GcGetMembers(edu.internet2.middleware.grouperClient.api.GcGetMembers) WsGetMembersResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults) GroupsException(org.apereo.portal.groups.GroupsException)

Aggregations

WsSubject (edu.internet2.middleware.grouperClient.ws.beans.WsSubject)9 WsGetMembersResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults)5 ArrayList (java.util.ArrayList)5 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)4 GroupsException (org.apereo.portal.groups.GroupsException)4 Group (edu.hawaii.its.api.type.Group)3 WsGetMembersResult (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResult)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Person (edu.hawaii.its.api.type.Person)2 GcGetMembers (edu.internet2.middleware.grouperClient.api.GcGetMembers)2 GcGetSubjects (edu.internet2.middleware.grouperClient.api.GcGetSubjects)2 WsGetSubjectsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetSubjectsResults)2 EntityIdentifier (org.apereo.portal.EntityIdentifier)2 IGroupMember (org.apereo.portal.groups.IGroupMember)2 EntityImpl (org.apereo.portal.groups.EntityImpl)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1