@Test public void testRegisterPermittedAllowAddressRe() throws Exception { String addr = "allo.+"; sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(addr))); testReceive("allow1", "foobar"); testReceive("allow2", "foobar"); testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testSendPermittedAllowAddressRe() throws Exception { String addr = "allo.+"; sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(addr))); testSend("allow1", "foobar"); testSend("allow2", "foobar"); testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testSendPermittedMixedAddressRe() throws Exception { String addr1 = "allow1"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr1)). addInboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testSend("allow1", "foobar"); testSend("ballow1", "foobar"); testSend("ballow2", "foobar"); testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"), "access_denied"); testError(new JsonObject().put("type", "send").put("address", "allow2").put("body", "blah"), "access_denied"); }
@Test public void testRegisterPermittedMixedAddressRe() throws Exception { String addr1 = "allow1"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr1)). addOutboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testReceive("allow1", "foobar"); testReceive("ballow1", "foobar"); testReceive("ballow2", "foobar"); testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"), "access_denied"); testError(new JsonObject().put("type", "register").put("address", "allow2").put("body", "blah"), "access_denied"); }
@Test public void testSendPermittedMultipleAddressRe() throws Exception { String addr1 = "allo.+"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(addr1)). addInboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testSend("allow1", "foobar"); testSend("allow2", "foobar"); testSend("ballow1", "foobar"); testSend("ballow2", "foobar"); testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testRegisterPermittedMultipleAddressRe() throws Exception { String addr1 = "allo.+"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(addr1)). addOutboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testReceive("allow1", "foobar"); testReceive("allow2", "foobar"); testReceive("ballow1", "foobar"); testReceive("ballow2", "foobar"); testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"), "access_denied"); }
JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10)); assertSame(options, options.setAddress(address)); assertSame(options, options.setAddressRegex(addressRegex)); assertSame(options, options.setRequiredAuthority(requiredAuthority)); assertSame(options, options.setMatch(match)); assertEquals(match, copy.getMatch()); assertSame(copy, copy.setAddress(TestUtils.randomAlphaString(10))); assertSame(copy, copy.setAddressRegex(TestUtils.randomAlphaString(10))); assertSame(copy, copy.setRequiredAuthority(TestUtils.randomAlphaString(10))); assertSame(copy, copy.setMatch(new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10)))); assertSame(options, options.setAddress(address)); assertSame(options, options.setAddressRegex(addressRegex)); assertSame(options, options.setRequiredAuthority(requiredAuthority)); assertSame(options, options.setMatch(match));
@Bean public SockJSHandler sockJSHandler() { EventBusBridgeEvents eventBusBridgeEvents = eventBusBridgeEvents(); SockJSHandler sockJSHandler = SockJSHandler.create(vertx); BridgeOptions options = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddressRegex(eventBusBridgeEvents.toIncomingEventName(".*"))) .addOutboundPermitted(new PermittedOptions().setAddressRegex(eventBusBridgeEvents.toOutgoingEventName(".*"))); sockJSHandler.bridge(options, event -> { if (event.type() == BridgeEventType.SOCKET_CREATED) { if (log.isDebugEnabled()) { log.debug("Socket connection created {}", event.socket().remoteAddress().host()); } } event.complete(true); }); return sockJSHandler; } }
@Test public void testRegisterPermittedAllowAddressRe() throws Exception { String addr = "allo.+"; sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(addr))); testReceive("allow1", "foobar"); testReceive("allow2", "foobar"); testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testSendPermittedAllowAddressRe() throws Exception { String addr = "allo.+"; sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(addr))); testSend("allow1", "foobar"); testSend("allow2", "foobar"); testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testSendPermittedMultipleAddressRe() throws Exception { String addr1 = "allo.+"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(addr1)). addInboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testSend("allow1", "foobar"); testSend("allow2", "foobar"); testSend("ballow1", "foobar"); testSend("ballow2", "foobar"); testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testRegisterPermittedMultipleAddressRe() throws Exception { String addr1 = "allo.+"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(addr1)). addOutboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testReceive("allow1", "foobar"); testReceive("allow2", "foobar"); testReceive("ballow1", "foobar"); testReceive("ballow2", "foobar"); testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"), "access_denied"); }
@Test public void testSendPermittedMixedAddressRe() throws Exception { String addr1 = "allow1"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr1)). addInboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testSend("allow1", "foobar"); testSend("ballow1", "foobar"); testSend("ballow2", "foobar"); testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"), "access_denied"); testError(new JsonObject().put("type", "send").put("address", "allow2").put("body", "blah"), "access_denied"); }
@Test public void testRegisterPermittedMixedAddressRe() throws Exception { String addr1 = "allow1"; String addr2 = "ballo.+"; sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr1)). addOutboundPermitted(new PermittedOptions().setAddressRegex(addr2))); testReceive("allow1", "foobar"); testReceive("ballow1", "foobar"); testReceive("ballow2", "foobar"); testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"), "access_denied"); testError(new JsonObject().put("type", "register").put("address", "allow2").put("body", "blah"), "access_denied"); }
JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10)); assertSame(options, options.setAddress(address)); assertSame(options, options.setAddressRegex(addressRegex)); assertSame(options, options.setRequiredAuthority(requiredAuthority)); assertSame(options, options.setMatch(match)); assertEquals(match, copy.getMatch()); assertSame(copy, copy.setAddress(TestUtils.randomAlphaString(10))); assertSame(copy, copy.setAddressRegex(TestUtils.randomAlphaString(10))); assertSame(copy, copy.setRequiredAuthority(TestUtils.randomAlphaString(10))); assertSame(copy, copy.setMatch(new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10)))); assertSame(options, options.setAddress(address)); assertSame(options, options.setAddressRegex(addressRegex)); assertSame(options, options.setRequiredAuthority(requiredAuthority)); assertSame(options, options.setMatch(match));
.addOutboundPermitted(new PermittedOptions().setAddressRegex("album\\.\\d+\\.comments\\.new"))); router.route("/eventbus/*").handler(sockJSHandler);