Search in sources :

Example 1 with GcGetGroups

use of edu.internet2.middleware.grouperClient.api.GcGetGroups in project cas by apereo.

the class GrouperFacade method getGroupsForSubjectId.

/**
     * Gets groups for subject id.
     *
     * @param subjectId the principal
     * @return the groups for subject id
     */
public static List<WsGetGroupsResult> getGroupsForSubjectId(final String subjectId) {
    try {
        final GcGetGroups groupsClient = new GcGetGroups().addSubjectId(subjectId);
        final WsGetGroupsResult[] results = groupsClient.execute().getResults();
        if (results == null || results.length == 0) {
            LOGGER.warn("Subject id [{}] could not be located.", subjectId);
            return Collections.emptyList();
        }
        LOGGER.debug("Found [{}] groups for [{}]", results.length, subjectId);
        return Arrays.asList(results);
    } catch (final Exception e) {
        LOGGER.warn("Grouper WS did not respond successfully. Ensure your credentials are correct " + ", the url endpoint for Grouper WS is correctly configured and the subject [{}]" + "  exists in Grouper.", subjectId, e);
    }
    return Collections.emptyList();
}
Also used : WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) GcGetGroups(edu.internet2.middleware.grouperClient.api.GcGetGroups)

Example 2 with GcGetGroups

use of edu.internet2.middleware.grouperClient.api.GcGetGroups in project uPortal by Jasig.

the class GrouperEntityGroupStore method findParentGroups.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#findParentGroups(org.apereo.portal.groups.IGroupMember)
     */
@SuppressWarnings("unchecked")
public Iterator findParentGroups(IGroupMember gm) throws GroupsException {
    final List<IEntityGroup> parents = new LinkedList<IEntityGroup>();
    GcGetGroups getGroups = new GcGetGroups();
    String uportalStem = getStemPrefix();
    // if only searching in a specific stem
    if (!StringUtils.isBlank(uportalStem)) {
        getGroups.assignStemScope(StemScope.ALL_IN_SUBTREE);
        getGroups.assignWsStemLookup(new WsStemLookup(uportalStem, null));
    }
    String key = null;
    String subjectSourceId = null;
    if (gm.isGroup()) {
        key = ((IEntityGroup) gm).getLocalKey();
        if (!validKey(key)) {
            return parents.iterator();
        }
        subjectSourceId = "g:gsa";
    } else {
        // Determine the key to use for this entity. If the entity is a
        // group, we should use the group's local key (excluding the
        // "grouper." portion of the full key. If the entity is not a
        // group type, just use the key.
        key = gm.getKey();
    }
    getGroups.addSubjectLookup(new WsSubjectLookup(null, subjectSourceId, key));
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching Grouper for parent groups of the entity with key: " + key);
    }
    try {
        WsGetGroupsResults results = getGroups.execute();
        if (results == null || results.getResults() == null || results.getResults().length != 1) {
            LOGGER.debug("Grouper service returned no matches for key " + key);
            return parents.iterator();
        }
        WsGetGroupsResult wsg = results.getResults()[0];
        if (wsg.getWsGroups() != null) {
            for (WsGroup g : wsg.getWsGroups()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.trace("Retrieved group: " + g.getName());
                }
                IEntityGroup parent = createUportalGroupFromGrouperGroup(g);
                parents.add(parent);
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Retrieved " + parents.size() + " parent groups of entity with key " + key);
        }
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "parents for entity with key " + key + " from Grouper web services: " + e.getMessage());
        return Collections.<IEntityGroup>emptyList().iterator();
    }
    return parents.iterator();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) WsSubjectLookup(edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) WsStemLookup(edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup) GcGetGroups(edu.internet2.middleware.grouperClient.api.GcGetGroups) WsGetGroupsResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResults) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) LinkedList(java.util.LinkedList) GroupsException(org.apereo.portal.groups.GroupsException)

Aggregations

GcGetGroups (edu.internet2.middleware.grouperClient.api.GcGetGroups)2 WsGetGroupsResult (edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult)2 WsGetGroupsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResults)1 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)1 WsStemLookup (edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup)1 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)1 LinkedList (java.util.LinkedList)1 GroupsException (org.apereo.portal.groups.GroupsException)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1