use of com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException in project AuthGuard by AuthGuard.
the class OAuthServiceClient method processJsonResponse.
private void processJsonResponse(final HttpResponse<Buffer> httpResponse, final String url, final CompletableFuture<TokensResponse> future) {
final JsonObject jsonObject = httpResponse.bodyAsJsonObject();
final String error = jsonObject.getString("error");
if (error != null) {
LOG.warn("Call to {} returned an error {}", url, error);
future.completeExceptionally(new ServiceAuthorizationException(ErrorCode.GENERIC_AUTH_FAILURE, "Unsuccessful call to the identity provider"));
}
final TokensResponse tokens = new TokensResponse().setAccessToken(jsonObject.getString("access_token")).setIdToken(jsonObject.getString("id_token")).setRefreshToken(jsonObject.getString("refresh_token"));
future.complete(tokens);
}
use of com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException in project AuthGuard by AuthGuard.
the class JwtTokenVerifier method verify.
Either<Exception, DecodedJWT> verify(final String token) {
try {
final DecodedJWT decoded = JWT.decode(token);
final DecodedJWT verified = verifier.verify(decoded);
if (this.verifyJti(verified)) {
return Either.right(verified);
} else {
return Either.left(new ServiceAuthorizationException(ErrorCode.INVALID_TOKEN, "Invalid JTI", EntityType.ACCOUNT, verified.getSubject()));
}
} catch (final JWTVerificationException e) {
return Either.left(new ServiceAuthorizationException(ErrorCode.GENERIC_AUTH_FAILURE, "Invalid JWT"));
}
}
use of com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException in project AuthGuard by AuthGuard.
the class BasicAuthProvider method verifyCredentialsAndGetAccount.
private Either<Exception, AccountBO> verifyCredentialsAndGetAccount(final String username, final String password, final String domain) {
final Optional<CredentialsBO> credentialsOpt = credentialsService.getByUsernameUnsafe(username, domain);
// TODO replace this with Either mapping
if (credentialsOpt.isPresent()) {
final CredentialsBO credentials = credentialsOpt.get();
final Optional<Exception> validationError = checkIdentifier(credentials, username);
if (validationError.isPresent()) {
return Either.left(validationError.get());
}
return checkIfExpired(credentials).flatMap(valid -> checkPasswordsMatch(valid, password)).flatMap(valid -> getAccountById(valid.getAccountId()));
} else {
return Either.left(new ServiceAuthorizationException(ErrorCode.CREDENTIALS_DOES_NOT_EXIST, "Identifier " + username + " does not exist"));
}
}
Aggregations