Search in sources :

Example 1 with QRAuthenticationTokenCredential

use of org.apereo.cas.qr.authentication.QRAuthenticationTokenCredential in project cas by apereo.

the class QRAuthenticationValidateTokenActionTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    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());
    request.addParameter(TokenConstants.PARAMETER_NAME_TOKEN, "token");
    request.addParameter("deviceId", "abcdefgh987654321");
    val result = qrAuthenticationValidateWebSocketChannelAction.execute(context);
    assertEquals(result.getId(), CasWebflowConstants.TRANSITION_ID_FINALIZE);
    assertTrue(WebUtils.getCredential(context) instanceof QRAuthenticationTokenCredential);
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) QRAuthenticationTokenCredential(org.apereo.cas.qr.authentication.QRAuthenticationTokenCredential) MockRequestContext(org.springframework.webflow.test.MockRequestContext) 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 QRAuthenticationTokenCredential

use of org.apereo.cas.qr.authentication.QRAuthenticationTokenCredential in project cas by apereo.

the class QRAuthenticationValidateTokenAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    val token = request.getParameter(TokenConstants.PARAMETER_NAME_TOKEN);
    val deviceId = request.getParameter("deviceId");
    LOGGER.debug("Received QR token [{}] with device identifier [{}]", token, deviceId);
    val credential = new QRAuthenticationTokenCredential(token, deviceId);
    WebUtils.putCredential(requestContext, credential);
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_FINALIZE);
}
Also used : lombok.val(lombok.val) QRAuthenticationTokenCredential(org.apereo.cas.qr.authentication.QRAuthenticationTokenCredential) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Aggregations

lombok.val (lombok.val)2 QRAuthenticationTokenCredential (org.apereo.cas.qr.authentication.QRAuthenticationTokenCredential)2 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1