Search in sources :

Example 6 with WsGetGroupsResult

use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult in project cas by apereo.

the class GrouperRegisteredServiceAccessStrategyTests method checkGrouperNoGroups.

@Test
public void checkGrouperNoGroups() {
    val strategy = new GrouperRegisteredServiceAccessStrategy() {

        private static final long serialVersionUID = 8533229193475808261L;

        @Override
        protected Collection<WsGetGroupsResult> fetchWsGetGroupsResults(final String principal) {
            return List.of();
        }
    };
    val attrs = (Map) RegisteredServiceTestUtils.getTestAttributes("banderson");
    assertFalse(strategy.doPrincipalAttributesAllowServiceAccess("banderson", attrs));
}
Also used : lombok.val(lombok.val) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 7 with WsGetGroupsResult

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

the class GrouperEntityGroupStore method findParentGroups.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#findParentGroups(org.apereo.portal.groups.IGroupMember)
     */
@Override
@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)

Example 8 with WsGetGroupsResult

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

the class GroupingAssignmentServiceImpl method getGroupPaths.

// returns the list of groups that the user is in
@Override
public List<String> getGroupPaths(String username) {
    logger.info("getGroupPaths; username: " + username + ";");
    WsStemLookup stemLookup = grouperFS.makeWsStemLookup(STEM);
    WsGetGroupsResults wsGetGroupsResults = grouperFS.makeWsGetGroupsResults(username, stemLookup, StemScope.ALL_IN_SUBTREE);
    WsGetGroupsResult groupResults = wsGetGroupsResults.getResults()[0];
    List<WsGroup> groups = new ArrayList<>();
    if (groupResults.getWsGroups() != null) {
        groups = new ArrayList<>(Arrays.asList(groupResults.getWsGroups()));
    }
    return extractGroupPaths(groups);
}
Also used : WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) WsStemLookup(edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup) WsGetGroupsResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResults) ArrayList(java.util.ArrayList) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup)

Example 9 with WsGetGroupsResult

use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult in project cas by apereo.

the class GrouperRegisteredServiceAccessStrategy method doPrincipalAttributesAllowServiceAccess.

@Override
public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) {
    val allAttributes = new HashMap<>(principalAttributes);
    val results = fetchWsGetGroupsResults(principal);
    if (results.isEmpty()) {
        LOGGER.warn("No groups could be found for [{}]", principal);
        return false;
    }
    val grouperGroups = new ArrayList<String>(results.size());
    results.stream().filter(groupsResult -> groupsResult.getWsGroups() != null && groupsResult.getWsGroups().length > 0).map(wsGetGroupsResult -> Arrays.stream(wsGetGroupsResult.getWsGroups()).collect(Collectors.toList())).flatMap(List::stream).forEach(group -> grouperGroups.add(GrouperFacade.getGrouperGroupAttribute(this.groupField, group)));
    LOGGER.debug("Adding [{}] under attribute name [{}] to collection of attributes", grouperGroups, GROUPER_GROUPS_ATTRIBUTE_NAME);
    allAttributes.put(GROUPER_GROUPS_ATTRIBUTE_NAME, grouperGroups);
    return RegisteredServiceAccessStrategyEvaluator.builder().requiredAttributes(this.requiredAttributes).build().evaluate(principal, allAttributes);
}
Also used : lombok.val(lombok.val) GrouperClientConfig(edu.internet2.middleware.grouperClient.util.GrouperClientConfig) Synchronized(lombok.Synchronized) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) Setter(lombok.Setter) Arrays(java.util.Arrays) Getter(lombok.Getter) GrouperGroupField(org.apereo.cas.grouper.GrouperGroupField) Collection(java.util.Collection) BaseRegisteredServiceAccessStrategy(org.apereo.cas.services.BaseRegisteredServiceAccessStrategy) lombok.val(lombok.val) Set(java.util.Set) HashMap(java.util.HashMap) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) DefaultGrouperFacade(org.apereo.cas.grouper.DefaultGrouperFacade) GrouperFacade(org.apereo.cas.grouper.GrouperFacade) RegisteredServiceAccessStrategyEvaluator(org.apereo.cas.services.util.RegisteredServiceAccessStrategyEvaluator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 10 with WsGetGroupsResult

use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult in project cas by apereo.

the class GrouperFacadeTests method verifyGroups.

@Test
public void verifyGroups() {
    val facade = new DefaultGrouperFacade() {

        @Override
        public WsGetGroupsResult[] fetchGroupsFor(final String subjectId) {
            val group = new WsGroup();
            group.setExtension("GroupExtension");
            group.setDisplayName("DisplayNameGroupExtension");
            group.setDisplayExtension("DisplaySampleGroupExtension");
            group.setDescription("Group Desc");
            group.setName("SampleGroup");
            group.setUuid(UUID.randomUUID().toString());
            val result = new WsGetGroupsResult();
            result.setWsGroups(new WsGroup[] { group });
            return new WsGetGroupsResult[] { result };
        }
    };
    assertFalse(facade.getGroupsForSubjectId("casuser").isEmpty());
}
Also used : lombok.val(lombok.val) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) Test(org.junit.jupiter.api.Test)

Aggregations

WsGetGroupsResult (edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult)11 lombok.val (lombok.val)7 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 WsGetGroupsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResults)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 GrouperFacade (org.apereo.cas.grouper.GrouperFacade)3 GrouperGroupField (org.apereo.cas.grouper.GrouperGroupField)3 GcGetGroups (edu.internet2.middleware.grouperClient.api.GcGetGroups)2 WsStemLookup (edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup)2 StringUtils (edu.internet2.middleware.grouperClientExt.org.apache.commons.lang3.StringUtils)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Stream (java.util.stream.Stream)2