use of org.springframework.webflow.execution.RequestContext 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 org.springframework.webflow.execution.RequestContext in project uPortal by Jasig.
the class PersonQueryValidator method validatePersonLookup.
/**
* Ensures all passed attributes are part of the valid query attribute set.
*/
public void validatePersonLookup(PersonQuery personQuery, MessageContext context) {
final RequestContext requestContext = RequestContextHolder.getRequestContext();
final ExternalContext externalContext = requestContext.getExternalContext();
final Set<String> queryAttributes = personLookupHelper.getQueryAttributes(externalContext);
final Map<String, Attribute> attributes = personQuery.getAttributes();
for (final String attribute : attributes.keySet()) {
if (!queryAttributes.contains(attribute)) {
final MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.error();
messageBuilder.source("attributes[" + attribute + "].value");
messageBuilder.code("personLookup.invalidQueryAttribute");
messageBuilder.arg(attribute);
final MessageResolver errorMessage = messageBuilder.build();
context.addMessage(errorMessage);
}
}
}
use of org.springframework.webflow.execution.RequestContext in project cas by apereo.
the class Pac4jWebflowConfigurer method createStopWebflowViewState.
private void createStopWebflowViewState(final Flow flow) {
final ViewState state = createViewState(flow, DelegatedClientAuthenticationAction.STOP_WEBFLOW, DelegatedClientAuthenticationAction.VIEW_ID_STOP_WEBFLOW);
state.getEntryActionList().add(new AbstractAction() {
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
final HttpServletResponse response = WebUtils.getHttpServletResponse(requestContext);
final Optional<ModelAndView> mv = DelegatedClientAuthenticationAction.hasDelegationRequestFailed(request, response.getStatus());
mv.ifPresent(modelAndView -> modelAndView.getModel().forEach((k, v) -> requestContext.getFlowScope().put(k, v)));
return null;
}
});
}
use of org.springframework.webflow.execution.RequestContext in project cas by apereo.
the class ServiceThemeResolver method resolveThemeName.
@Override
public String resolveThemeName(final HttpServletRequest request) {
if (this.servicesManager == null) {
return getDefaultThemeName();
}
// retrieve the user agent string from the request
final String userAgent = WebUtils.getHttpServletRequestUserAgent(request);
if (StringUtils.isBlank(userAgent)) {
return getDefaultThemeName();
}
overrides.entrySet().stream().filter(entry -> entry.getKey().matcher(userAgent).matches()).findFirst().ifPresent(entry -> {
request.setAttribute("isMobile", "true");
request.setAttribute("browserType", entry.getValue());
});
final RequestContext context = RequestContextHolder.getRequestContext();
final Service service = WebUtils.getService(context);
if (service != null) {
final RegisteredService rService = this.servicesManager.findServiceBy(service);
if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed() && StringUtils.isNotBlank(rService.getTheme())) {
LOGGER.debug("Service [{}] is configured to use a custom theme [{}]", rService, rService.getTheme());
final CasThemeResourceBundleMessageSource messageSource = new CasThemeResourceBundleMessageSource();
messageSource.setBasename(rService.getTheme());
if (messageSource.doGetBundle(rService.getTheme(), request.getLocale()) != null) {
LOGGER.debug("Found custom theme [{}] for service [{}]", rService.getTheme(), rService);
return rService.getTheme();
} else {
LOGGER.warn("Custom theme [{}] for service [{}] cannot be located. Falling back to default theme...", rService.getTheme(), rService);
}
}
}
return getDefaultThemeName();
}
use of org.springframework.webflow.execution.RequestContext in project cas by apereo.
the class CasWebflowContextConfigurationTests method verifyFlowExecutorByClient.
@Test
public void verifyFlowExecutorByClient() {
final RequestContext ctx = getMockRequestContext();
final LocalAttributeMap map = new LocalAttributeMap<>();
flowExecutorViaClientFlowExecution.launchExecution("login", map, ctx.getExternalContext());
}
Aggregations