Search in sources :

Example 1 with SwivelTokenCredential

use of org.apereo.cas.adaptors.swivel.SwivelTokenCredential in project cas by apereo.

the class SwivelAuthenticationWebflowActionTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val authn = RegisteredServiceTestUtils.getAuthentication("casuser");
    val builder = mock(AuthenticationResultBuilder.class);
    when(builder.getInitialAuthentication()).thenReturn(Optional.of(authn));
    when(builder.collect(any(Authentication.class))).thenReturn(builder);
    WebUtils.putAuthenticationResultBuilder(builder, context);
    WebUtils.putAuthentication(authn, context);
    WebUtils.putCredential(context, new SwivelTokenCredential("token"));
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, swivelAuthenticationWebflowAction.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Authentication(org.apereo.cas.authentication.Authentication) SwivelTokenCredential(org.apereo.cas.adaptors.swivel.SwivelTokenCredential) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SwivelTokenCredential

use of org.apereo.cas.adaptors.swivel.SwivelTokenCredential in project cas by apereo.

the class SwivelAuthenticationWebflowEventResolverTests method verifyResolver.

@Test
public void verifyResolver() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val authn = RegisteredServiceTestUtils.getAuthentication("casuser");
    val builder = mock(AuthenticationResultBuilder.class);
    when(builder.getInitialAuthentication()).thenReturn(Optional.of(authn));
    when(builder.collect(any(Authentication.class))).thenReturn(builder);
    WebUtils.putAuthenticationResultBuilder(builder, context);
    WebUtils.putAuthentication(authn, context);
    WebUtils.putCredential(context, new SwivelTokenCredential("token"));
    val event = resolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, event.getId());
    val support = new EventFactorySupport();
    assertTrue(event.getAttributes().contains(support.getExceptionAttributeName()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Authentication(org.apereo.cas.authentication.Authentication) SwivelTokenCredential(org.apereo.cas.adaptors.swivel.SwivelTokenCredential) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)2 SwivelTokenCredential (org.apereo.cas.adaptors.swivel.SwivelTokenCredential)2 Authentication (org.apereo.cas.authentication.Authentication)2 Test (org.junit.jupiter.api.Test)2 MessageContext (org.springframework.binding.message.MessageContext)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockParameterMap (org.springframework.webflow.test.MockParameterMap)2 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1