use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class RedirectUnauthorizedServiceUrlActionTests method verifyUrl.
@Test
public void verifyUrl() throws Exception {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
context.setCurrentEvent(new EventFactorySupport().success(this));
WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(context, new URI("https://github.com/apereo/cas"));
val action = new RedirectUnauthorizedServiceUrlAction(mock(ServicesManager.class), appCtx);
assertNull(action.doExecute(context));
assertEquals("https://github.com/apereo/cas", WebUtils.getUnauthorizedRedirectUrlFromFlowScope(context).toASCIIString());
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class RedirectUnauthorizedServiceUrlActionTests method verifyScript.
@Test
public void verifyScript() throws Exception {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
context.setCurrentEvent(new EventFactorySupport().success(this));
WebUtils.putRegisteredService(context, RegisteredServiceTestUtils.getRegisteredService());
WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(context, new URI("classpath:UnauthorizedServiceUrl.groovy"));
val action = new RedirectUnauthorizedServiceUrlAction(mock(ServicesManager.class), appCtx);
assertNull(action.doExecute(context));
assertEquals("https://apereo.org/cas", WebUtils.getUnauthorizedRedirectUrlFromFlowScope(context).toASCIIString());
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class DetermineMultifactorPasswordlessAuthenticationAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val user = WebUtils.getPasswordlessAuthenticationAccount(requestContext, PasswordlessUserAccount.class);
if (user == null) {
LOGGER.error("Unable to locate passwordless account in the flow");
return error();
}
if (multifactorTriggerSelectionStrategy.getMultifactorAuthenticationTriggers().isEmpty()) {
LOGGER.debug("No multifactor authentication triggers are available or defined");
return success();
}
if (!shouldActivateMultifactorAuthenticationFor(requestContext, user)) {
LOGGER.debug("User [{}] is not activated to use CAS-provided multifactor authentication providers. " + "You may wish to re-examine your CAS configuration to enable and allow for multifactor authentication to be " + "combined with passwordless authentication", user);
return success();
}
val attributes = CoreAuthenticationUtils.convertAttributeValuesToMultiValuedObjects((Map) user.getAttributes());
val principal = this.passwordlessPrincipalFactory.createPrincipal(user.getId(), attributes);
val auth = DefaultAuthenticationBuilder.newInstance().setPrincipal(principal).build();
val service = WebUtils.getService(requestContext);
val result = resolveMultifactorAuthenticationProvider(requestContext, auth, service);
if (result.isEmpty()) {
LOGGER.debug("No CAS-provided multifactor authentication trigger required user [{}] to proceed with MFA. " + "CAS will proceed with its normal passwordless authentication flow.", user);
return success();
}
populateContextWithAuthenticationResult(requestContext, auth, service);
LOGGER.debug("Proceed with multifactor authentication flow [{}] for user [{}]", result.get(), user);
return new EventFactorySupport().event(this, result.map(MultifactorAuthenticationProvider::getId).orElse(StringUtils.EMPTY));
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class DetermineDelegatedAuthenticationAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val user = WebUtils.getPasswordlessAuthenticationAccount(requestContext, PasswordlessUserAccount.class);
if (user == null) {
LOGGER.error("Unable to locate passwordless account in the flow");
return error();
}
val clients = providerConfigurationProducer.produce(requestContext);
if (clients.isEmpty()) {
LOGGER.debug("No delegated authentication providers are available or defined");
return success();
}
if (!isDelegatedAuthenticationActiveFor(requestContext, user)) {
LOGGER.debug("User [{}] is not activated to use CAS delegated authentication to external identity providers. " + "You may wish to re-examine your CAS configuration to enable and allow for delegated authentication to be " + "combined with passwordless authentication", user);
return success();
}
val providerResult = determineDelegatedIdentityProviderConfiguration(requestContext, user, clients);
if (providerResult.isPresent()) {
val resolvedId = providerResult.get();
requestContext.getFlashScope().put("delegatedClientIdentityProvider", resolvedId);
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_REDIRECT, "delegatedClientIdentityProvider", resolvedId);
}
LOGGER.trace("Delegated identity provider could not be determined for [{}] based on [{}]", user, clients);
return success();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class SpnegoCredentialsActionTests method verifyErrorWithBadCredential.
@Test
public void verifyErrorWithBadCredential() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addHeader(SpnegoConstants.HEADER_AUTHORIZATION, SpnegoConstants.NEGOTIATE + ' ' + EncodingUtils.encodeBase64("credential"));
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val stResolver = mock(CasWebflowEventResolver.class);
val err = new EventFactorySupport().error(this);
when(stResolver.resolveSingle(any())).thenReturn(err);
val action = new SpnegoCredentialsAction(mock(CasDelegatingWebflowEventResolver.class), stResolver, mock(AdaptiveAuthenticationPolicy.class), false, true);
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.execute(context).getId());
}
Aggregations