use of io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication in project gravitee-access-management by gravitee-io.
the class UserAuthProviderImpl method authenticate.
@Override
public void authenticate(RoutingContext context, JsonObject authInfo, Handler<AsyncResult<User>> handler) {
String username = authInfo.getString(USERNAME_PARAMETER);
String password = authInfo.getString(PASSWORD_PARAMETER);
String clientId = authInfo.getString(Parameters.CLIENT_ID);
String ipAddress = authInfo.getString(Claims.ip_address);
String userAgent = authInfo.getString(Claims.user_agent);
parseClient(clientId, parseClientHandler -> {
if (parseClientHandler.failed()) {
logger.error("Authentication failure: unable to retrieve client " + clientId, parseClientHandler.cause());
handler.handle(Future.failedFuture(parseClientHandler.cause()));
return;
}
// retrieve the client (application)
final Client client = parseClientHandler.result();
// end user authentication
SimpleAuthenticationContext authenticationContext = new SimpleAuthenticationContext(new VertxHttpServerRequest(context.request().getDelegate()));
final Authentication authentication = new EndUserAuthentication(username, password, authenticationContext);
authenticationContext.set(Claims.ip_address, ipAddress);
authenticationContext.set(Claims.user_agent, userAgent);
authenticationContext.set(Claims.domain, client.getDomain());
userAuthenticationManager.authenticate(client, authentication).subscribe(user -> handler.handle(Future.succeededFuture(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(user))), error -> handler.handle(Future.failedFuture(error)));
});
}
use of io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication in project gravitee-access-management by gravitee-io.
the class WebAuthnResponseEndpoint method authenticateUser.
private void authenticateUser(AuthenticationContext authenticationContext, Client client, String username, Handler<AsyncResult<User>> handler) {
final Authentication authentication = new EndUserAuthentication(username, null, authenticationContext);
userAuthenticationManager.authenticate(client, authentication, true).subscribe(user -> handler.handle(Future.succeededFuture(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(user))), error -> handler.handle(Future.failedFuture(error)));
}
use of io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication in project gravitee-access-management by gravitee-io.
the class LogoutEndpoint method evaluateSingleSignOut.
/**
* Check if the single sign out feature is requested, if yes return the delegated OP end session endpoint URL
* @param routingContext the routing context
* @param handler handler holding the potential delegated OP end session endpoint URL
*/
private void evaluateSingleSignOut(RoutingContext routingContext, Handler<AsyncResult<String>> handler) {
final Client client = routingContext.get(ConstantKeys.CLIENT_CONTEXT_KEY);
final User endUser = routingContext.get(ConstantKeys.USER_CONTEXT_KEY) != null ? routingContext.get(ConstantKeys.USER_CONTEXT_KEY) : (routingContext.user() != null ? ((io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User) routingContext.user().getDelegate()).getUser() : null);
// if no client, continue
if (client == null) {
handler.handle(Future.succeededFuture());
return;
}
// if single sign out feature disabled, continue
if (!client.isSingleSignOut()) {
handler.handle(Future.succeededFuture());
return;
}
// if no user, continue
if (endUser == null) {
handler.handle(Future.succeededFuture());
return;
}
// generate the delegated OP logout request
final Authentication authentication = new EndUserAuthentication(endUser, null, new SimpleAuthenticationContext(new VertxHttpServerRequest(routingContext.request().getDelegate())));
identityProviderManager.get(endUser.getSource()).filter(provider -> provider instanceof SocialAuthenticationProvider).flatMap(provider -> ((SocialAuthenticationProvider) provider).signOutUrl(authentication)).flatMap(logoutRequest -> generateLogoutCallback(routingContext, endUser, logoutRequest)).subscribe(endpoint -> handler.handle(Future.succeededFuture(endpoint)), err -> {
LOGGER.warn("Unable to sign the end user out of the external OIDC '{}', only sign out of AM", client.getClientId(), err);
handler.handle(Future.succeededFuture());
}, () -> handler.handle(Future.succeededFuture()));
}
use of io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication in project gravitee-access-management by gravitee-io.
the class UserAuthenticationServiceImpl method loadPreAuthenticatedUser.
@Override
public Maybe<User> loadPreAuthenticatedUser(String subject, Request request) {
// find user by its technical id
return userService.findById(subject).switchIfEmpty(Maybe.error(new UserNotFoundException(subject))).flatMap(user -> isIndefinitelyLocked(user) ? Maybe.error(new AccountLockedException("User " + user.getUsername() + " is locked")) : Maybe.just(user)).flatMap(user -> identityProviderManager.get(user.getSource()).flatMap(authenticationProvider -> {
SimpleAuthenticationContext authenticationContext = new SimpleAuthenticationContext(request);
final Authentication authentication = new EndUserAuthentication(user, null, authenticationContext);
return authenticationProvider.loadPreAuthenticatedUser(authentication);
}).flatMap(idpUser -> {
// retrieve information from the idp user and update the user
Map<String, Object> additionalInformation = idpUser.getAdditionalInformation() == null ? new HashMap<>() : new HashMap<>(idpUser.getAdditionalInformation());
additionalInformation.put(SOURCE_FIELD, user.getSource());
additionalInformation.put(Parameters.CLIENT_ID, user.getClient());
((DefaultUser) idpUser).setAdditionalInformation(additionalInformation);
return update(user, idpUser, false).flatMap(userService::enhance).toMaybe();
}).switchIfEmpty(Maybe.defer(() -> userService.enhance(user).toMaybe())));
}
use of io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication in project gravitee-access-management by gravitee-io.
the class ResourceOwnerPasswordCredentialsTokenGranter method resolveResourceOwner.
@Override
protected Maybe<User> resolveResourceOwner(TokenRequest tokenRequest, Client client) {
String username = tokenRequest.getUsername();
String password = tokenRequest.getPassword();
return userAuthenticationManager.authenticate(client, new EndUserAuthentication(username, password, new SimpleAuthenticationContext(tokenRequest))).onErrorResumeNext(ex -> Single.error(new InvalidGrantException(ex.getMessage()))).toMaybe();
}
Aggregations