Java Code Examples for io.vertx.ext.auth.properties.PropertyFileAuthentication#create()
The following examples show how to use
io.vertx.ext.auth.properties.PropertyFileAuthentication#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChainAuthHandlerTest.java From vertx-web with Apache License 2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); AuthenticationHandler redirectAuthHandler = RedirectAuthHandler.create(authProvider); // create a chain chain = ChainAuthHandler.any() .add(JWTAuthHandler.create(null)) .add(BasicAuthHandler.create(authProvider)) .add(redirectAuthHandler); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(chain); router.route().handler(ctx -> ctx.response().end()); }
Example 2
Source File: ChainAuthHandlerAndTest.java From vertx-web with Apache License 2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); AuthenticationHandler redirectAuthHandler = RedirectAuthHandler.create(authProvider); // create a chain chain = ChainAuthHandler.all() .add(JWTAuthHandler.create(null)) .add(BasicAuthHandler.create(authProvider)) .add(redirectAuthHandler); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(chain); router.route().handler(ctx -> ctx.response().end()); }
Example 3
Source File: SecuredServerConnectionTest.java From vertx-stomp with Apache License 2.0 | 5 votes |
@Before public void setUp(TestContext context) { vertx = rule.vertx(); AuthenticationProvider provider = PropertyFileAuthentication.create(vertx, "test-auth.properties"); server = StompServer.create(vertx, new StompServerOptions().setSecured(true)) .handler(StompServerHandler.create(vertx).authProvider(provider)) .listen(context.asyncAssertSuccess()); }
Example 4
Source File: RedirectAuthHandlerTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); usernameParam = FormLoginHandler.DEFAULT_USERNAME_PARAM; passwordParam = FormLoginHandler.DEFAULT_PASSWORD_PARAM; }
Example 5
Source File: AuthHandlerTestBase.java From vertx-web with Apache License 2.0 | 5 votes |
protected void testAuthorization(String username, boolean fail, Authorization authority) throws Exception { if (requiresSession()) { router.route().handler(BodyHandler.create()); SessionStore store = getSessionStore(); router.route().handler(SessionHandler.create(store)); } AuthenticationProvider authNProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); AuthorizationProvider authZProvider = PropertyFileAuthorization.create(vertx, "login/loginusers.properties"); AuthenticationHandler authNHandler = createAuthHandler(authNProvider); router.route().handler(rc -> { // we need to be logged in if (rc.user() == null) { JsonObject authInfo = new JsonObject().put("username", username).put("password", "delicious:sausages"); authNProvider.authenticate(authInfo, res -> { if (res.succeeded()) { rc.setUser(res.result()); rc.next(); } else { rc.fail(res.cause()); } }); } }); router.route().handler(authNHandler); if (authority != null) { router.route().handler(AuthorizationHandler.create(authority).addAuthorizationProvider(authZProvider)); } router.route().handler(rc -> rc.response().end()); testRequest(HttpMethod.GET, "/", fail ? 403: 200, fail? "Forbidden": "OK"); }
Example 6
Source File: BasicAuthHandlerTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void testSecurityBypass() throws Exception { Handler<RoutingContext> handler = rc -> { fail("should not get here"); rc.response().end("Welcome to the protected resource!"); }; AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); router.route().pathRegex("/api/.*").handler(BasicAuthHandler.create(authProvider)); router.route("/api/v1/standard-job-profiles").handler(handler); testRequest(HttpMethod.GET, "//api/v1/standard-job-profiles", 401, "Unauthorized"); }
Example 7
Source File: EventbusBridgeTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void testSendRequiresAuthorityHasAuthority() throws Exception { sockJSHandler.bridge(PropertyFileAuthorization.create(vertx, "login/loginusers.properties"), defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks")), null); router.clear(); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); addLoginHandler(router, authProvider); router.route("/eventbus/*").handler(sockJSHandler); testSend("foo"); }
Example 8
Source File: EventbusBridgeTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void testSendRequiresAuthorityHasnotAuthority() throws Exception { sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("pick_nose"))); router.clear(); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); addLoginHandler(router, authProvider); router.route("/eventbus/*").handler(sockJSHandler); testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied"); }