AuthProvider authProvider = ShiroAuth.create(vertx, ShiroAuthRealmType.PROPERTIES, new JsonObject());
AuthProvider authProvider = ShiroAuth.create(vertx, ShiroAuthRealmType.PROPERTIES, new JsonObject());
@Override public void setUp() throws Exception { super.setUp(); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); usernameParam = FormLoginHandler.DEFAULT_USERNAME_PARAM; passwordParam = FormLoginHandler.DEFAULT_PASSWORD_PARAM; }
@Test public void testSendRequiresAuthorityHasnotAuthority() throws Exception { sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("pick_nose"))); router.clear(); router.route().handler(CookieHandler.create()); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); addLoginHandler(router, authProvider); router.route("/eventbus/*").handler(sockJSHandler); testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied"); }
@Test public void testSecurityBypass() throws Exception { Handler<RoutingContext> handler = rc -> { fail("should not get here"); rc.response().end("Welcome to the protected resource!"); }; JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); 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"); } }
AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); AuthHandler authHandler = createAuthHandler(authProvider); if (authorities != null) {
@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()); }
private void doLogin(String realm) throws Exception { Handler<RoutingContext> handler = rc -> { assertNotNull(rc.user()); assertEquals("tim", rc.user().principal().getString("username")); rc.response().end("Welcome to the protected resource!"); }; JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); router.route("/protected/*").handler(BasicAuthHandler.create(authProvider, realm)); router.route("/protected/somepage").handler(handler); testRequest(HttpMethod.GET, "/protected/somepage", null, resp -> { String wwwAuth = resp.headers().get("WWW-Authenticate"); assertNotNull(wwwAuth); assertEquals("Basic realm=\"" + realm + "\"", wwwAuth); }, 401, "Unauthorized", null); // Now try again with credentials testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Basic dGltOmRlbGljaW91czpzYXVzYWdlcw=="), resp -> { String wwwAuth = resp.headers().get("WWW-Authenticate"); assertNull(wwwAuth); }, 200, "OK", "Welcome to the protected resource!"); }
@Test public void testSendRequiresAuthorityHasAuthority() throws Exception { sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks"))); router.clear(); router.route().handler(CookieHandler.create()); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); addLoginHandler(router, authProvider); router.route("/eventbus/*").handler(sockJSHandler); testSend("foo"); }
@Test public void testLoginFail() throws Exception { String realm = "vertx-web"; Handler<RoutingContext> handler = rc -> { fail("should not get here"); rc.response().end("Welcome to the protected resource!"); }; JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); router.route("/protected/*").handler(BasicAuthHandler.create(authProvider)); router.route("/protected/somepage").handler(handler); testRequest(HttpMethod.GET, "/protected/somepage", null, resp -> { String wwwAuth = resp.headers().get("WWW-Authenticate"); assertNotNull(wwwAuth); assertEquals("Basic realm=\"" + realm + "\"", wwwAuth); }, 401, "Unauthorized", null); // Now try again with bad credentials testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Basic dGltOn5hdXdhZ2Vz"), resp -> { String wwwAuth = resp.headers().get("WWW-Authenticate"); assertNotNull(wwwAuth); assertEquals("Basic realm=\"" + realm + "\"", wwwAuth); }, 401, "Unauthorized", null); }
/** * Create a Shiro auth provider * @param vertx the Vert.x instance * @param realmType the Shiro realm type * @param config the config * @return the auth provider */ @Deprecated() public static io.vertx.rxjava.ext.auth.shiro.ShiroAuth create(io.vertx.rxjava.core.Vertx vertx, ShiroAuthRealmType realmType, JsonObject config) { io.vertx.rxjava.ext.auth.shiro.ShiroAuth ret = io.vertx.rxjava.ext.auth.shiro.ShiroAuth.newInstance(io.vertx.ext.auth.shiro.ShiroAuth.create(vertx.getDelegate(), realmType, config)); return ret; }
/** * Create a Shiro auth provider * @param vertx the Vert.x instance * @param realmType the Shiro realm type * @param config the config * @return the auth provider */ @Deprecated() public static io.vertx.rxjava.ext.auth.shiro.ShiroAuth create(io.vertx.rxjava.core.Vertx vertx, ShiroAuthRealmType realmType, JsonObject config) { io.vertx.rxjava.ext.auth.shiro.ShiroAuth ret = io.vertx.rxjava.ext.auth.shiro.ShiroAuth.newInstance(io.vertx.ext.auth.shiro.ShiroAuth.create(vertx.getDelegate(), realmType, config)); return ret; }
/** * Create a Shiro auth provider * @param vertx the Vert.x instance * @param options the Shiro configuration options * @return the auth provider */ public static io.vertx.rxjava.ext.auth.shiro.ShiroAuth create(io.vertx.rxjava.core.Vertx vertx, ShiroAuthOptions options) { io.vertx.rxjava.ext.auth.shiro.ShiroAuth ret = io.vertx.rxjava.ext.auth.shiro.ShiroAuth.newInstance(io.vertx.ext.auth.shiro.ShiroAuth.create(vertx.getDelegate(), options)); return ret; }
public static io.vertx.ext.auth.shiro.ShiroAuth create(io.vertx.ext.auth.shiro.ShiroAuth j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.auth.shiro.ShiroAuthRealmType realmType, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.shiro.ShiroAuth.create(vertx, realmType, config != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(config) : null)); } public static io.vertx.ext.auth.shiro.ShiroAuth create(io.vertx.ext.auth.shiro.ShiroAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
public static io.vertx.ext.auth.shiro.ShiroAuth create(io.vertx.ext.auth.shiro.ShiroAuth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.shiro.ShiroAuth.create(vertx, options != null ? new io.vertx.ext.auth.shiro.ShiroAuthOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } }
AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); router.route().handler(UserSessionHandler.create(authProvider)); router.route("/protected/*").handler(BasicAuthHandler.create(authProvider));
@Override public void setUp() throws Exception { super.setUp(); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); usernameParam = FormLoginHandler.DEFAULT_USERNAME_PARAM; passwordParam = FormLoginHandler.DEFAULT_PASSWORD_PARAM; }
@Test public void testCreateWithRealm() { Realm realm = new MyShiroRealm(); AuthProvider authProvider = ShiroAuth.create(vertx, realm); JsonObject authInfo = new JsonObject().put("username", "tim").put("password", "sausages"); authProvider.authenticate(authInfo, onSuccess(user -> { assertNotNull(user); testComplete(); })); await(); }
@Override public void setUp() throws Exception { super.setUp(); authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(getConfig())); }
@Test public void testSendRequiresAuthorityHasAuthority() throws Exception { sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks"))); router.clear(); router.route().handler(CookieHandler.create()); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties"); AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig)); addLoginHandler(router, authProvider); router.route("/eventbus/*").handler(sockJSHandler); testSend("foo"); }