Search in sources :

Example 1 with DuoSecurityDirectCredential

use of org.apereo.cas.adaptors.duo.authn.DuoSecurityDirectCredential in project cas by apereo.

the class DuoSecurityDirectAuthenticationAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val authentication = WebUtils.getAuthentication(requestContext);
    val c = new DuoSecurityDirectCredential(resolvePrincipal(authentication.getPrincipal()), provider.getId());
    WebUtils.putCredential(requestContext, c);
    return success();
}
Also used : lombok.val(lombok.val) DuoSecurityDirectCredential(org.apereo.cas.adaptors.duo.authn.DuoSecurityDirectCredential)

Example 2 with DuoSecurityDirectCredential

use of org.apereo.cas.adaptors.duo.authn.DuoSecurityDirectCredential in project cas by apereo.

the class DuoSecurityRestHttpRequestCredentialFactoryTests method verifyOperation.

@Test
public void verifyOperation() {
    val factory = new DuoSecurityRestHttpRequestCredentialFactory();
    val request = new MockHttpServletRequest();
    val body = new LinkedMultiValueMap<String, String>();
    assertTrue(factory.fromRequest(request, body).isEmpty());
    body.put(RestHttpRequestCredentialFactory.PARAMETER_USERNAME, List.of("user"));
    assertTrue(factory.fromRequest(request, body).isEmpty());
    body.put(DuoSecurityRestHttpRequestCredentialFactory.PARAMETER_NAME_PASSCODE, List.of("123456"));
    body.put(DuoSecurityRestHttpRequestCredentialFactory.PARAMETER_NAME_PROVIDER, List.of("custom-duo"));
    var credentials = factory.fromRequest(request, body);
    assertFalse(credentials.isEmpty());
    var credential = (DuoSecurityPasscodeCredential) credentials.get(0);
    assertEquals(credential.getProviderId(), "custom-duo");
    credentials = factory.fromAuthentication(request, body, CoreAuthenticationTestUtils.getAuthentication(), new TestMultifactorAuthenticationProvider());
    val directCredential = (DuoSecurityDirectCredential) credentials.get(0);
    assertEquals(TestMultifactorAuthenticationProvider.ID, directCredential.getProviderId());
    assertNotNull(directCredential.getPrincipal());
}
Also used : lombok.val(lombok.val) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DuoSecurityDirectCredential(org.apereo.cas.adaptors.duo.authn.DuoSecurityDirectCredential) DuoSecurityPasscodeCredential(org.apereo.cas.adaptors.duo.authn.DuoSecurityPasscodeCredential) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)2 DuoSecurityDirectCredential (org.apereo.cas.adaptors.duo.authn.DuoSecurityDirectCredential)2 DuoSecurityPasscodeCredential (org.apereo.cas.adaptors.duo.authn.DuoSecurityPasscodeCredential)1 TestMultifactorAuthenticationProvider (org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider)1 Test (org.junit.jupiter.api.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1