use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult 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 Collection<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 new ArrayList<>(0);
}
LOGGER.debug("Found [{}] groups for [{}]", results.length, subjectId);
return CollectionUtils.wrapList(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 new ArrayList<>(0);
}
use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult in project cas by apereo.
the class GrouperMultifactorAuthenticationPolicyEventResolver method resolveInternal.
@Override
public Set<Event> resolveInternal(final RequestContext context) {
final RegisteredService service = resolveRegisteredServiceInRequestContext(context);
final Authentication authentication = WebUtils.getAuthentication(context);
if (StringUtils.isBlank(grouperField)) {
LOGGER.debug("No group field is defined to process for Grouper multifactor trigger");
return null;
}
if (authentication == null || service == null) {
LOGGER.debug("No authentication or service is available to determine event for principal");
return null;
}
final Principal principal = authentication.getPrincipal();
final Collection<WsGetGroupsResult> results = GrouperFacade.getGroupsForSubjectId(principal.getId());
if (results.isEmpty()) {
LOGGER.debug("No groups could be found for [{}] to resolve events for MFA", principal);
return null;
}
final Map<String, MultifactorAuthenticationProvider> providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap == null || providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context");
throw new AuthenticationException();
}
final GrouperGroupField groupField = GrouperGroupField.valueOf(grouperField);
final Set<String> values = results.stream().map(wsGetGroupsResult -> Stream.of(wsGetGroupsResult.getWsGroups())).flatMap(Function.identity()).map(g -> GrouperFacade.getGrouperGroupAttribute(groupField, g)).collect(Collectors.toSet());
final Optional<MultifactorAuthenticationProvider> providerFound = resolveProvider(providerMap, values);
if (providerFound.isPresent()) {
final MultifactorAuthenticationProvider provider = providerFound.get();
if (provider.isAvailable(service)) {
LOGGER.debug("Attempting to build event based on the authentication provider [{}] and service [{}]", provider, service.getName());
final Event event = validateEventIdForMatchingTransitionInContext(provider.getId(), context, buildEventAttributeMap(authentication.getPrincipal(), service, provider));
return CollectionUtils.wrapSet(event);
}
LOGGER.warn("Located multifactor provider [{}], yet the provider cannot be reached or verified", providerFound.get());
return null;
}
LOGGER.debug("No multifactor provider could be found based on [{}]'s Grouper groups", principal.getId());
return null;
}
use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult in project uhgroupings by uhawaii-system-its-ti-iam.
the class GrouperFactoryServiceImplLocal method makeWsGetGroupsResults.
@Override
public WsGetGroupsResults makeWsGetGroupsResults(String username, WsStemLookup stemLookup, StemScope stemScope) {
WsGetGroupsResults wsGetGroupsResults = new WsGetGroupsResults();
WsGetGroupsResult wsGetGroupsResult = new WsGetGroupsResult();
WsGroup[] groups;
List<WsGroup> wsGroupList = new ArrayList<>();
List<Group> groupList = groupRepository.findByMembersUsername(username);
for (Group group : groupList) {
WsGroup g = new WsGroup();
g.setName(group.getPath());
wsGroupList.add(g);
}
groups = wsGroupList.toArray(new WsGroup[wsGroupList.size()]);
wsGetGroupsResult.setWsGroups(groups);
wsGetGroupsResults.setResults(new WsGetGroupsResult[] { wsGetGroupsResult });
return wsGetGroupsResults;
}
use of edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult in project cas by apereo.
the class GrouperMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest request, final HttpServletResponse response, final Service service) {
val grouperField = casProperties.getAuthn().getMfa().getTriggers().getGrouper().getGrouperGroupField();
if (StringUtils.isBlank(grouperField)) {
LOGGER.debug("No group field is defined to process for Grouper multifactor trigger");
return Optional.empty();
}
if (authentication == null || registeredService == null) {
LOGGER.debug("No authentication or service is available to determine event for principal");
return Optional.empty();
}
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context");
throw new AuthenticationException();
}
val principal = authentication.getPrincipal();
val results = grouperFacade.getGroupsForSubjectId(principal.getId());
if (results.isEmpty()) {
LOGGER.debug("No groups could be found for [{}] to resolve events for MFA", principal);
return Optional.empty();
}
val groupField = GrouperGroupField.valueOf(grouperField);
val values = results.stream().map(wsGetGroupsResult -> Stream.of(wsGetGroupsResult.getWsGroups())).flatMap(Function.identity()).map(g -> GrouperFacade.getGrouperGroupAttribute(groupField, g)).collect(Collectors.toSet());
return MultifactorAuthenticationUtils.resolveProvider(providerMap, values);
}
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));
}
Aggregations