Search in sources :

Example 6 with DefaultMessageContext

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);
}
Also used : Locale(java.util.Locale) InweboAuthenticationDeviceMetadataPopulator(org.apereo.cas.support.inwebo.authentication.InweboAuthenticationDeviceMetadataPopulator) MockServletContext(org.springframework.mock.web.MockServletContext) DefaultAuthenticationManager(org.apereo.cas.authentication.DefaultAuthenticationManager) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) AbstractMessageSource(org.springframework.context.support.AbstractMessageSource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) lombok.val(lombok.val) InweboAuthenticationHandler(org.apereo.cas.support.inwebo.authentication.InweboAuthenticationHandler) InweboMultifactorAuthenticationWebflowEventResolver(org.apereo.cas.support.inwebo.web.flow.InweboMultifactorAuthenticationWebflowEventResolver) MessageFormat(java.text.MessageFormat) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) DefaultAuthenticationEventExecutionPlan(org.apereo.cas.authentication.DefaultAuthenticationEventExecutionPlan) DefaultAuthenticationResultBuilderFactory(org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) InweboMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.InweboMultifactorAuthenticationProperties) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) InweboService(org.apereo.cas.support.inwebo.service.InweboService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with DefaultMessageContext

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));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) GoogleAuthenticatorTokenCredential(org.apereo.cas.gauth.credential.GoogleAuthenticatorTokenCredential) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 8 with DefaultMessageContext

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;
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 9 with DefaultMessageContext

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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 10 with DefaultMessageContext

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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)12 DefaultMessageContext (org.springframework.binding.message.DefaultMessageContext)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)12 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 MockServletContext (org.springframework.mock.web.MockServletContext)12 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)12 MockRequestContext (org.springframework.webflow.test.MockRequestContext)12 MessageSource (org.springframework.context.MessageSource)11 Test (org.junit.jupiter.api.Test)8 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MessageFormat (java.text.MessageFormat)1 Locale (java.util.Locale)1 CasX509Certificate (org.apereo.cas.adaptors.x509.authentication.CasX509Certificate)1 Authentication (org.apereo.cas.authentication.Authentication)1 DefaultAuthenticationEventExecutionPlan (org.apereo.cas.authentication.DefaultAuthenticationEventExecutionPlan)1 DefaultAuthenticationManager (org.apereo.cas.authentication.DefaultAuthenticationManager)1 DefaultAuthenticationResultBuilderFactory (org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory)1 DefaultAuthenticationSystemSupport (org.apereo.cas.authentication.DefaultAuthenticationSystemSupport)1 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)1 DefaultAuthenticationTransactionManager (org.apereo.cas.authentication.DefaultAuthenticationTransactionManager)1