use of io.vertx.ext.auth.JWTOptions in project vertx-web by vert-x3.
the class MultiAuthorizationHandlerTest method testJWTAuthenticationWithAuthorization4.
@Test
public void testJWTAuthenticationWithAuthorization4() throws Exception {
// we are testing the following:
// authentication via jwt
// 3 authorization providers are registered
// an authorization is required on the path
// => the test should fail since no authorization providers provide the correct authorization
router.route("/protected/*").handler(JWTAuthHandler.create(authProvider));
router.route("/protected/*").handler(AuthorizationHandler.create(RoleBasedAuthorization.create("role4")).addAuthorizationProvider(createProvider("authzProvider1", RoleBasedAuthorization.create("role1"))).addAuthorizationProvider(createProvider("authzProvider2", RoleBasedAuthorization.create("role2"))).addAuthorizationProvider(createProvider("authzProvider3", RoleBasedAuthorization.create("role3"))));
router.route("/protected/page1").handler(rc -> {
assertNotNull(rc.user());
assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub"));
rc.response().end("Welcome");
});
// login with correct credentials
testRequest(HttpMethod.GET, "/protected/page1", req -> req.putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions())), 403, "Forbidden", "Forbidden");
}
Aggregations