use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class RemoteAddressNonInteractiveCredentialsActionTests 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());
assertNotNull(remoteAddressCheck.execute(context));
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class BaseCasSimpleMultifactorSendTokenActionTests method buildRequestContextFor.
protected MockRequestContext buildRequestContextFor(final String user) {
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);
WebUtils.putServiceIntoFlashScope(context, RegisteredServiceTestUtils.getService());
val principal = RegisteredServiceTestUtils.getPrincipal(user, CollectionUtils.wrap("phone", List.of("123456789"), "mail", List.of("cas@example.org")));
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(principal), context);
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, casSimpleMultifactorAuthenticationProvider);
return context;
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class PrincipalFromRequestHeaderNonInteractiveCredentialsActionTests method verifyAdaptiveError.
@Test
public void verifyAdaptiveError() 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.setRemoteAddr("1.2.3.4");
request.setLocalAddr("1.2.3.4");
request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "FIREFOX");
request.addParameter("geolocation", "1000,1000,1000,1000");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
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 PrincipalFromRequestHeaderNonInteractiveCredentialsActionTests method verifyRemoteUserExists.
@Test
public void verifyRemoteUserExists() 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()));
val principal = mock(Principal.class);
when(principal.getName()).thenReturn("casuser");
request.setUserPrincipal(principal);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
request.setRemoteUser("test");
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
request.addHeader("principal", "casuser");
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
}
use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.
the class RadiusAuthenticationWebflowEventResolverTests method initialize.
@BeforeEach
public void initialize() {
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()));
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val authentication = CoreAuthenticationTestUtils.getAuthentication();
WebUtils.putAuthentication(authentication, context);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(authentication));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
}
Aggregations