Search in sources :

Example 1 with PFAuthParams

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");
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) Authentication(org.apereo.cas.authentication.Authentication) PFAuthResult(net.phonefactor.pfsdk.PFAuthResult) PFAuthParams(net.phonefactor.pfsdk.PFAuthParams) Principal(org.apereo.cas.authentication.principal.Principal) GeneralSecurityException(java.security.GeneralSecurityException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Example 2 with PFAuthParams

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;
}
Also used : StandardPinInfo(net.phonefactor.pfsdk.StandardPinInfo) PFAuthParams(net.phonefactor.pfsdk.PFAuthParams) PlainTextPinInfo(net.phonefactor.pfsdk.PlainTextPinInfo)

Aggregations

PFAuthParams (net.phonefactor.pfsdk.PFAuthParams)2 GeneralSecurityException (java.security.GeneralSecurityException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 PFAuthResult (net.phonefactor.pfsdk.PFAuthResult)1 PlainTextPinInfo (net.phonefactor.pfsdk.PlainTextPinInfo)1 StandardPinInfo (net.phonefactor.pfsdk.StandardPinInfo)1 Authentication (org.apereo.cas.authentication.Authentication)1 Principal (org.apereo.cas.authentication.principal.Principal)1