use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class BaseActionTests method setUp.
@BeforeEach
public void setUp() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, CoreAuthenticationTestUtils.getAuthenticationSystemSupport(), AuthenticationSystemSupport.BEAN_NAME);
requestContext = new MockRequestContext();
request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
requestContext.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(requestContext);
setExternalContext(requestContext.getExternalContext());
((DefaultMessageContext) requestContext.getMessageContext()).setMessageSource(new AbstractMessageSource() {
@Override
protected MessageFormat resolveCode(final String code, final Locale locale) {
return new MessageFormat(StringUtils.EMPTY);
}
});
service = mock(InweboService.class);
val authenticationEventExecutionPlan = new DefaultAuthenticationEventExecutionPlan();
authenticationEventExecutionPlan.registerAuthenticationHandler(new InweboAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), new InweboMultifactorAuthenticationProperties(), service));
authenticationEventExecutionPlan.registerAuthenticationMetadataPopulator(new InweboAuthenticationDeviceMetadataPopulator());
val authenticationManager = new DefaultAuthenticationManager(authenticationEventExecutionPlan, true, applicationContext);
val authenticationTransactionManager = new DefaultAuthenticationTransactionManager(applicationContext, authenticationManager);
val authenticationSystemSupport = new DefaultAuthenticationSystemSupport(authenticationTransactionManager, new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory());
val context = CasWebflowEventResolutionConfigurationContext.builder().authenticationSystemSupport(authenticationSystemSupport).build();
resolver = new InweboMultifactorAuthenticationWebflowEventResolver(context);
setAuthenticationInContext(LOGIN);
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class GoogleAuthenticatorValidateSelectedRegistrationActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val messageContext = (DefaultMessageContext) context.getMessageContext();
messageContext.setMessageSource(mock(MessageSource.class));
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val action = new GoogleAuthenticatorValidateSelectedRegistrationAction();
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.execute(context).getId());
val acct = OneTimeTokenAccount.builder().username("casuser").name(UUID.randomUUID().toString()).secretKey("secret").validationCode(123456).scratchCodes(List.of()).build();
WebUtils.putOneTimeTokenAccount(context, acct);
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.execute(context).getId());
WebUtils.putCredential(context, new GoogleAuthenticatorTokenCredential("token", 987655L));
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.execute(context).getId());
WebUtils.putCredential(context, new GoogleAuthenticatorTokenCredential("token", acct.getId()));
assertNull(action.execute(context));
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class WebAuthnAuthenticationWebflowActionTests method getRequestContext.
private static RequestContext getRequestContext() {
val context = new MockRequestContext();
val messageContext = (DefaultMessageContext) context.getMessageContext();
messageContext.setMessageSource(mock(MessageSource.class));
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
return context;
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class PrincipalFromRequestHeaderNonInteractiveCredentialsActionTests method verifyError.
@Test
public void verifyError() throws Exception {
val context = new MockRequestContext();
val messageContext = (DefaultMessageContext) context.getMessageContext();
messageContext.setMessageSource(mock(MessageSource.class));
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
request.setRemoteUser("xyz");
request.addParameter(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestParameter(), "mfa-whatever");
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class X509CertificateCredentialsRequestHeaderActionTests method verifyCredentialsResultsInAuthnFailure.
@Test
public void verifyCredentialsResultsInAuthnFailure() throws Exception {
val context = new MockRequestContext();
val messageContext = (DefaultMessageContext) context.getMessageContext();
messageContext.setMessageSource(mock(MessageSource.class));
val request = new MockHttpServletRequest();
request.addHeader("ssl_client_cert", VALID_CERTIFICATE.getContent());
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, action.execute(context).getId());
}
Aggregations