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));
}
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();
}
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);
}
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);
}
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());
}
Aggregations