@Override public void setUp() throws Exception { super.setUp(); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); // create a chain chain = ChainAuthHandler.create(); chain .append(JWTAuthHandler.create(null)) .append(BasicAuthHandler.create(authProvider)) .append(RedirectAuthHandler.create(authProvider)); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(chain); router.route().handler(ctx -> ctx.response().end()); }
public static void parseCredentials(io.vertx.ext.web.handler.ChainAuthHandler j_receiver, io.vertx.ext.web.RoutingContext context, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> handler) { j_receiver.parseCredentials(context, handler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.json.JsonObject>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.core.json.JsonObject> ar) { handler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromJsonObject(event))); } } : null); } }
/** * Add a set of required authorities for this auth handler * @param authorities the set of authorities * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.AuthHandler addAuthorities(Set<String> authorities) { delegate.addAuthorities(authorities); return this; }
public static io.vertx.rxjava.ext.web.handler.ChainAuthHandler create() { io.vertx.rxjava.ext.web.handler.ChainAuthHandler ret = io.vertx.rxjava.ext.web.handler.ChainAuthHandler.newInstance(io.vertx.ext.web.handler.ChainAuthHandler.create()); return ret; }
/** * Appends a auth provider to the chain. * @param authHandler auth handler * @return self */ public io.vertx.rxjava.ext.web.handler.ChainAuthHandler append(io.vertx.rxjava.ext.web.handler.AuthHandler authHandler) { delegate.append(authHandler.getDelegate()); return this; }
/** * Clears the chain. */ public void clear() { delegate.clear(); }
/** * Authorizes the given user against all added authorities. * @param user a user. * @param handler the handler for the result. */ public void authorize(io.vertx.rxjava.ext.auth.User user, Handler<AsyncResult<Void>> handler) { delegate.authorize(user.getDelegate(), handler); }
/** * Add a required authority for this auth handler * @param authority the authority * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.AuthHandler addAuthority(String authority) { delegate.addAuthority(authority); return this; }
public static io.vertx.rxjava.ext.web.handler.ChainAuthHandler create() { io.vertx.rxjava.ext.web.handler.ChainAuthHandler ret = io.vertx.rxjava.ext.web.handler.ChainAuthHandler.newInstance(io.vertx.ext.web.handler.ChainAuthHandler.create()); return ret; }
/** * Appends a auth provider to the chain. * @param authHandler auth handler * @return self */ public io.vertx.rxjava.ext.web.handler.ChainAuthHandler append(io.vertx.rxjava.ext.web.handler.AuthHandler authHandler) { delegate.append(authHandler.getDelegate()); return this; }
/** * Clears the chain. */ public void clear() { delegate.clear(); }
/** * Authorizes the given user against all added authorities. * @param user a user. * @param handler the handler for the result. */ public void authorize(io.vertx.rxjava.ext.auth.User user, Handler<AsyncResult<Void>> handler) { delegate.authorize(user.getDelegate(), handler); }
/** * Add a required authority for this auth handler * @param authority the authority * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.AuthHandler addAuthority(String authority) { delegate.addAuthority(authority); return this; }
@Override protected void addRoutes(final Router router) { if (getConfig().isAuthenticationRequired()) { final ChainAuthHandler authHandler = ChainAuthHandler.create(); authHandler.append(new X509AuthHandler( new TenantServiceBasedX509Authentication(getTenantServiceClient(), tracer), Optional.ofNullable(clientCertAuthProvider).orElse( new X509AuthProvider(getCredentialsServiceClient(), getConfig(), tracer)))); authHandler.append(new HonoBasicAuthHandler( Optional.ofNullable(usernamePasswordAuthProvider).orElse( new UsernamePasswordAuthProvider(getCredentialsServiceClient(), getConfig(), tracer)), getConfig().getRealm(), tracer)); addTelemetryApiRoutes(router, authHandler); addEventApiRoutes(router, authHandler); addCommandResponseRoutes(router, authHandler); } else { LOG.warn("device authentication has been disabled"); LOG.warn("any device may publish data on behalf of all other devices"); addTelemetryApiRoutes(router, null); addEventApiRoutes(router, null); addCommandResponseRoutes(router, null); } }
/** * Two mode for handler supported. * * @param cliffes Cliff in zero system. * @return Auth Handler that will be mount to vertx router. */ private AuthHandler create(final Vertx vertx, final Set<Cliff> cliffes) { AuthHandler resultHandler = null; if (Values.ONE < cliffes.size()) { // 1 < handler final ChainAuthHandler chain = ChainAuthHandler.create(); Observable.fromIterable(cliffes) .map(item -> this.bolt.mount(vertx, item)) .subscribe(chain::append).dispose(); resultHandler = chain; } else { // 1 = handler if (!cliffes.isEmpty()) { final Cliff cliff = cliffes.iterator().next(); resultHandler = this.bolt.mount(vertx, cliff); } } return resultHandler; } }
@Override protected void addRoutes(final Router router) { if (getConfig().isAuthenticationRequired()) { final ChainAuthHandler authHandler = new HonoChainAuthHandler(); authHandler.append(new X509AuthHandler( Optional.ofNullable(clientCertAuthProvider).orElse( new X509AuthProvider(getCredentialsServiceClient(), getConfig())), getTenantServiceClient(), tracer)); authHandler.append(new HonoBasicAuthHandler( Optional.ofNullable(usernamePasswordAuthProvider).orElse( new UsernamePasswordAuthProvider(getCredentialsServiceClient(), getConfig())), getConfig().getRealm())); addTelemetryApiRoutes(router, authHandler); addEventApiRoutes(router, authHandler); addCommandResponseRoutes(router, authHandler); } else { LOG.warn("device authentication has been disabled"); LOG.warn("any device may publish data on behalf of all other devices"); addTelemetryApiRoutes(router, null); addEventApiRoutes(router, null); addCommandResponseRoutes(router, null); } }
/** * Parses the credentials from the request into a JsonObject. The implementation should * be able to extract the required info for the auth provider in the format the provider * expects. * @param context the routing context * @param handler the handler to be called once the information is available. */ public void parseCredentials(io.vertx.rxjava.ext.web.RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { delegate.parseCredentials(context.getDelegate(), handler); }
/** * Add a set of required authorities for this auth handler * @param authorities the set of authorities * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.AuthHandler addAuthorities(Set<String> authorities) { delegate.addAuthorities(authorities); return this; }
@Override public void setUp() throws Exception { super.setUp(); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); // create a chain chain = ChainAuthHandler.create(); chain .append(JWTAuthHandler.create(null)) .append(BasicAuthHandler.create(authProvider)) .append(RedirectAuthHandler.create(authProvider)); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(chain); router.route().handler(ctx -> ctx.response().end()); }
/** * Two mode for handler supported. * * @param cliffes Cliff in zero system. * @return Auth Handler that will be mount to vertx router. */ private AuthHandler create(final Vertx vertx, final Set<Cliff> cliffes) { AuthHandler resultHandler = null; if (Values.ONE < cliffes.size()) { // 1 < handler final ChainAuthHandler chain = ChainAuthHandler.create(); Observable.fromIterable(cliffes) .map(item -> this.bolt.mount(vertx, item)) .subscribe(chain::append).dispose(); resultHandler = chain; } else { // 1 = handler if (!cliffes.isEmpty()) { final Cliff cliff = cliffes.iterator().next(); resultHandler = this.bolt.mount(vertx, cliff); } } return resultHandler; } }