Search in sources :

Example 1 with User

use of com.authy.api.User in project cas by apereo.

the class AuthyAuthenticationHandler method doAuthentication.

@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final AuthyTokenCredential tokenCredential = (AuthyTokenCredential) credential;
    final RequestContext context = RequestContextHolder.getRequestContext();
    final Principal principal = WebUtils.getAuthentication(context).getPrincipal();
    final User user = instance.getOrCreateUser(principal);
    if (!user.isOk()) {
        throw new FailedLoginException(AuthyClientInstance.getErrorMessage(user.getError()));
    }
    final Map<String, String> options = new HashMap<>(1);
    options.put("force", this.forceVerification.toString());
    final Token verification = this.instance.getAuthyTokens().verify(user.getId(), tokenCredential.getToken(), options);
    if (!verification.isOk()) {
        throw new FailedLoginException(AuthyClientInstance.getErrorMessage(verification.getError()));
    }
    return createHandlerResult(tokenCredential, principal, new ArrayList<>());
}
Also used : User(com.authy.api.User) FailedLoginException(javax.security.auth.login.FailedLoginException) HashMap(java.util.HashMap) Token(com.authy.api.Token) RequestContext(org.springframework.webflow.execution.RequestContext) Principal(org.apereo.cas.authentication.principal.Principal)

Example 2 with User

use of com.authy.api.User in project cas by apereo.

the class AuthyAuthenticationRegistrationWebflowAction method doExecute.

@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final Principal principal = WebUtils.getAuthentication(context).getPrincipal();
    final User user = instance.getOrCreateUser(principal);
    if (!user.isOk()) {
        throw new IllegalArgumentException(AuthyClientInstance.getErrorMessage(user.getError()));
    }
    final Hash h = instance.getAuthyUsers().requestSms(user.getId());
    if (!h.isOk() || !h.isSuccess()) {
        throw new IllegalArgumentException(AuthyClientInstance.getErrorMessage(h.getError()).concat(h.getMessage()));
    }
    return success();
}
Also used : User(com.authy.api.User) Hash(com.authy.api.Hash) Principal(org.apereo.cas.authentication.principal.Principal)

Aggregations

User (com.authy.api.User)2 Principal (org.apereo.cas.authentication.principal.Principal)2 Hash (com.authy.api.Hash)1 Token (com.authy.api.Token)1 HashMap (java.util.HashMap)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 RequestContext (org.springframework.webflow.execution.RequestContext)1