use of net.phonefactor.pfsdk.PFAuthParams in project cas by apereo.
the class AzureAuthenticatorAuthenticationHandler method doAuthentication.
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException {
try {
final AzureAuthenticatorTokenCredential c = (AzureAuthenticatorTokenCredential) credential;
final Authentication authentication = WebUtils.getInProgressAuthentication();
if (authentication == null) {
throw new IllegalArgumentException("CAS has no reference to an authentication event to locate a principal");
}
final Principal principal = authentication.getPrincipal();
LOGGER.debug("Received principal id [{}]", principal.getId());
final PFAuthParams params = authenticationRequestBuilder.build(principal, c);
final PFAuthResult r = azureAuthenticatorInstance.authenticate(params);
if (r.getAuthenticated()) {
return createHandlerResult(c, principalFactory.createPrincipal(principal.getId()));
}
LOGGER.error("Authentication failed. Call status: [{}]-[{}]. Error: [{}]", r.getCallStatus(), r.getCallStatusString(), r.getMessageError());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
throw new FailedLoginException("Failed to authenticate user");
}
use of net.phonefactor.pfsdk.PFAuthParams in project cas by apereo.
the class AzureAuthenticatorAuthenticationRequestBuilder method build.
/**
* Build pf auth params.
*
* @param p the principal
* @param c the credential/token
* @return the pf auth params
*/
public PFAuthParams build(final Principal p, final AzureAuthenticatorTokenCredential c) {
if (!p.getAttributes().containsKey(this.phoneAttributeName)) {
throw new IllegalArgumentException(this.phoneAttributeName + " is not available as a principal attribute");
}
final PFAuthParams params = new PFAuthParams();
params.setPhoneNumber(p.getAttributes().get(this.phoneAttributeName).toString());
params.setCountryCode("1");
params.setUsername(p.getId());
switch(mode) {
case PIN:
params.setAuthInfo(new PlainTextPinInfo(c.getToken()));
break;
case POUND:
default:
params.setAuthInfo(new StandardPinInfo());
}
return params;
}
Aggregations