Search in sources :

Example 1 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method example46.

public void example46(Vertx vertx) {
    Router router = Router.router(vertx);
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    // Let through any messages sent to 'demo.orderMgr' from the client
    PermittedOptions inboundPermitted1 = new PermittedOptions().setAddress("demo.orderMgr");
    // Allow calls to the address 'demo.persistor' from the client as
    // long as the messages have an action field with value 'find'
    // and a collection field with value 'albums'
    PermittedOptions inboundPermitted2 = new PermittedOptions().setAddress("demo.persistor").setMatch(new JsonObject().put("action", "find").put("collection", "albums"));
    // Allow through any message with a field `wibble` with value `foo`.
    PermittedOptions inboundPermitted3 = new PermittedOptions().setMatch(new JsonObject().put("wibble", "foo"));
    // First let's define what we're going to allow from server -> client
    // Let through any messages coming from address 'ticker.mystock'
    PermittedOptions outboundPermitted1 = new PermittedOptions().setAddress("ticker.mystock");
    // Let through any messages from addresses starting with "news."
    // (e.g. news.europe, news.usa, etc)
    PermittedOptions outboundPermitted2 = new PermittedOptions().setAddressRegex("news\\..+");
    // Let's define what we're going to allow from client -> server
    SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted1).addInboundPermitted(inboundPermitted1).addInboundPermitted(inboundPermitted3).addOutboundPermitted(outboundPermitted1).addOutboundPermitted(outboundPermitted2);
    // mount the bridge on the router
    router.mountSubRouter("/eventbus", sockJSHandler.bridge(options));
}
Also used : SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) JsonObject(io.vertx.core.json.JsonObject) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 2 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method example45.

public void example45(Vertx vertx) {
    Router router = Router.router(vertx);
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    SockJSBridgeOptions options = new SockJSBridgeOptions();
    // mount the bridge on the router
    router.mountSubRouter("/eventbus", sockJSHandler.bridge(options));
}
Also used : SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 3 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method example47.

public void example47() {
    // Let through any messages sent to 'demo.orderService' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.orderService");
    // But only if the user is logged in and has the authority "place_orders"
    inboundPermitted.setRequiredAuthority("place_orders");
    SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted);
}
Also used : SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions)

Example 4 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method example48.

public void example48(Vertx vertx, AuthenticationProvider authProvider) {
    Router router = Router.router(vertx);
    // Let through any messages sent to 'demo.orderService' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.orderService");
    // But only if the user is logged in and has the authority "place_orders"
    inboundPermitted.setRequiredAuthority("place_orders");
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    // Now set up some basic auth handling:
    router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
    AuthenticationHandler basicAuthHandler = BasicAuthHandler.create(authProvider);
    router.route("/eventbus/*").handler(basicAuthHandler);
    // mount the bridge on the router
    router.mountSubRouter("/eventbus", sockJSHandler.bridge(new SockJSBridgeOptions().addInboundPermitted(inboundPermitted)));
}
Also used : SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 5 with SockJSBridgeOptions

use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.

the class WebExamples method handleSocketIdle.

public void handleSocketIdle(Vertx vertx, PermittedOptions inboundPermitted) {
    Router router = Router.router(vertx);
    // Initialize SockJS handler
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted).setPingTimeout(5000);
    // mount the bridge on the router
    router.mountSubRouter("/eventbus", sockJSHandler.bridge(options, be -> {
        if (be.type() == BridgeEventType.SOCKET_IDLE) {
        // Do some custom handling...
        }
        be.complete(true);
    }));
}
Also used : LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) OAuth2Options(io.vertx.ext.auth.oauth2.OAuth2Options) GithubAuth(io.vertx.ext.auth.oauth2.providers.GithubAuth) RoutingContextInternal(io.vertx.ext.web.impl.RoutingContextInternal) io.vertx.ext.auth.webauthn(io.vertx.ext.auth.webauthn) Function(java.util.function.Function) EventBus(io.vertx.core.eventbus.EventBus) RoleBasedAuthorization(io.vertx.ext.auth.authorization.RoleBasedAuthorization) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler) BridgeEventType(io.vertx.ext.bridge.BridgeEventType) JsonObject(io.vertx.core.json.JsonObject) SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) AuthorizationProvider(io.vertx.ext.auth.authorization.AuthorizationProvider) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) ClusteredSessionStore(io.vertx.ext.web.sstore.ClusteredSessionStore) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) AuthenticationProvider(io.vertx.ext.auth.authentication.AuthenticationProvider) JWTAuthOptions(io.vertx.ext.auth.jwt.JWTAuthOptions) OAuth2FlowType(io.vertx.ext.auth.oauth2.OAuth2FlowType) Future(io.vertx.core.Future) io.vertx.core.http(io.vertx.core.http) KeyStoreOptions(io.vertx.ext.auth.KeyStoreOptions) JsonArray(io.vertx.core.json.JsonArray) JWTOptions(io.vertx.ext.auth.JWTOptions) io.vertx.ext.web(io.vertx.ext.web) io.vertx.ext.web.handler(io.vertx.ext.web.handler) List(java.util.List) User(io.vertx.ext.auth.User) Buffer(io.vertx.core.buffer.Buffer) SessionStore(io.vertx.ext.web.sstore.SessionStore) TotpAuth(io.vertx.ext.auth.otp.totp.TotpAuth) DataObject(io.vertx.codegen.annotations.DataObject) PermissionBasedAuthorization(io.vertx.ext.auth.authorization.PermissionBasedAuthorization) OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth) Handler(io.vertx.core.Handler) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) JWTAuth(io.vertx.ext.auth.jwt.JWTAuth) SockJSBridgeOptions(io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Aggregations

SockJSBridgeOptions (io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions)7 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)6 SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)6 JsonObject (io.vertx.core.json.JsonObject)4 DataObject (io.vertx.codegen.annotations.DataObject)3 Future (io.vertx.core.Future)3 Handler (io.vertx.core.Handler)3 Vertx (io.vertx.core.Vertx)3 VertxOptions (io.vertx.core.VertxOptions)3 Buffer (io.vertx.core.buffer.Buffer)3 EventBus (io.vertx.core.eventbus.EventBus)3 io.vertx.core.http (io.vertx.core.http)3 JsonArray (io.vertx.core.json.JsonArray)3 JWTOptions (io.vertx.ext.auth.JWTOptions)3 KeyStoreOptions (io.vertx.ext.auth.KeyStoreOptions)3 User (io.vertx.ext.auth.User)3 AuthenticationProvider (io.vertx.ext.auth.authentication.AuthenticationProvider)3 AuthorizationProvider (io.vertx.ext.auth.authorization.AuthorizationProvider)3 PermissionBasedAuthorization (io.vertx.ext.auth.authorization.PermissionBasedAuthorization)3 RoleBasedAuthorization (io.vertx.ext.auth.authorization.RoleBasedAuthorization)3