use of org.apereo.cas.adaptors.duo.authn.DuoSecurityPasscodeCredential in project cas by apereo.
the class DuoSecurityRestHttpRequestCredentialFactory method fromRequest.
@Override
public List<Credential> fromRequest(final HttpServletRequest request, final MultiValueMap<String, String> requestBody) {
if (requestBody == null || requestBody.isEmpty()) {
LOGGER.debug("Skipping [{}] because the request body is null or empty", getClass().getSimpleName());
return new ArrayList<>(0);
}
if (!requestBody.containsKey(RestHttpRequestCredentialFactory.PARAMETER_USERNAME) || !requestBody.containsKey(PARAMETER_NAME_PASSCODE)) {
LOGGER.debug("No username or passcode provided");
return new ArrayList<>(0);
}
val username = FunctionUtils.throwIfBlank(requestBody.getFirst(RestHttpRequestCredentialFactory.PARAMETER_USERNAME));
val token = FunctionUtils.throwIfBlank(requestBody.getFirst(PARAMETER_NAME_PASSCODE));
val providerId = StringUtils.defaultString(requestBody.getFirst(PARAMETER_NAME_PROVIDER), DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
return CollectionUtils.wrap(new DuoSecurityPasscodeCredential(username, token, providerId));
}
use of org.apereo.cas.adaptors.duo.authn.DuoSecurityPasscodeCredential 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());
}
Aggregations