Search in sources :

Example 1 with BasicAuthorization

use of com.disney.http.auth.BasicAuthorization in project groovity by disney.

the class BasicVerifierImpl method doVerifyInternal.

@Override
protected VerifierResult doVerifyInternal(ServerAuthorizationRequest request) {
    VerifierResult result = new VerifierResult();
    List<String> basicAuth = request.getHeaders(AUTHORIZATION_HEADER);
    if (basicAuth == null || basicAuth.isEmpty()) {
        challenge(result, ERROR_MISSING_CREDENTIALS);
        return result;
    }
    BasicAuthorization auth;
    try {
        auth = new BasicAuthorization(basicAuth.get(0));
    } catch (Exception e) {
        challenge(result, e.getMessage());
        return result;
    }
    for (int i = 0; i < passwordCheckers.size(); i++) {
        PasswordChecker checker = passwordCheckers.get(i);
        if (checker.check(auth.getUsername(), auth.getPassword())) {
            result.setAuthenticated(true);
            result.setPrincipal(new AuthenticatedPrincipal(auth.getUsername()));
            return result;
        }
    }
    challenge(result, ERROR_UNKNOWN_CREDENTIALS);
    return result;
}
Also used : VerifierResult(com.disney.http.auth.server.VerifierResult) BasicAuthorization(com.disney.http.auth.BasicAuthorization) AuthenticatedPrincipal(com.disney.http.auth.server.AuthenticatedPrincipal)

Aggregations

BasicAuthorization (com.disney.http.auth.BasicAuthorization)1 AuthenticatedPrincipal (com.disney.http.auth.server.AuthenticatedPrincipal)1 VerifierResult (com.disney.http.auth.server.VerifierResult)1