Search in sources :

Example 1 with ScopedAuthentication

use of io.vertx.ext.web.handler.impl.ScopedAuthentication in project vertx-web by vert-x3.

the class AuthenticationHandlersStore method resolveHandlers.

private List<AuthenticationHandler> resolveHandlers(Map.Entry<String, Object> e, boolean failOnNotFound) {
    List<AuthenticationHandler> authenticationHandlers;
    if (failOnNotFound) {
        authenticationHandlers = Optional.ofNullable(this.securityHandlers.get(e.getKey())).orElseThrow(() -> RouterBuilderException.createMissingSecurityHandler(e.getKey()));
    } else {
        authenticationHandlers = Optional.ofNullable(this.securityHandlers.get(e.getKey())).orElse(Collections.emptyList());
    }
    // Some scopes are defines, we need to configure them in OAuth2Handlers
    if (e.getValue() instanceof JsonArray && ((JsonArray) e.getValue()).size() != 0) {
        List<String> scopes = ((JsonArray) e.getValue()).stream().map(v -> (String) v).collect(Collectors.toList());
        for (int i = 0; i < authenticationHandlers.size(); i++) {
            if (authenticationHandlers.get(i) instanceof ScopedAuthentication<?>) {
                ScopedAuthentication<?> scopedHandler = (ScopedAuthentication<?>) authenticationHandlers.get(i);
                // this mutates the state, so we replace the list with an updated handler
                AuthenticationHandler updatedHandler = scopedHandler.withScopes(scopes);
                authenticationHandlers.set(i, updatedHandler);
            }
        }
    }
    return authenticationHandlers;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonArray(io.vertx.core.json.JsonArray) RouterBuilderException(io.vertx.ext.web.openapi.RouterBuilderException) java.util(java.util) User(io.vertx.ext.auth.User) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) ChainAuthHandler(io.vertx.ext.web.handler.ChainAuthHandler) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler) JsonObject(io.vertx.core.json.JsonObject) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) ScopedAuthentication(io.vertx.ext.web.handler.impl.ScopedAuthentication) ScopedAuthentication(io.vertx.ext.web.handler.impl.ScopedAuthentication) SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler) AuthenticationHandler(io.vertx.ext.web.handler.AuthenticationHandler)

Aggregations

Future (io.vertx.core.Future)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 User (io.vertx.ext.auth.User)1 AuthenticationHandler (io.vertx.ext.web.handler.AuthenticationHandler)1 ChainAuthHandler (io.vertx.ext.web.handler.ChainAuthHandler)1 SimpleAuthenticationHandler (io.vertx.ext.web.handler.SimpleAuthenticationHandler)1 ScopedAuthentication (io.vertx.ext.web.handler.impl.ScopedAuthentication)1 RouterBuilderException (io.vertx.ext.web.openapi.RouterBuilderException)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1