io.vertx.ext.auth.shiro.ShiroAuthOptions Java Examples
The following examples show how to use
io.vertx.ext.auth.shiro.ShiroAuthOptions.
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: PropertiesShiroAuthProviderTest.java From vertx-auth with Apache License 2.0 | 6 votes |
@Test public void testResolve() throws Exception { ClassLoader loader = PropertiesShiroAuthProviderTest.class.getClassLoader(); File res = new File(loader.getResource("test-auth.properties").toURI()); try { ShiroAuth.create(vertx, new ShiroAuthOptions().setType( ShiroAuthRealmType.PROPERTIES ).setConfig( new JsonObject().put(PropertiesProviderConstants.PROPERTIES_PROPS_PATH_FIELD, res.getName()) )); fail(); } catch (Exception ignore) { } assertResolve(res.getParentFile(), res.getName()); assertResolve(res.getParentFile(), "file:" + res.getName()); assertResolve(res.getParentFile().getParentFile(), "file:" + res.getParentFile().getName() + File.separatorChar + res.getName()); assertResolve(res.getParentFile().getParentFile(), "classpath:" + res.getName()); assertResolve(res.getParentFile().getParentFile(), "url:" + res.toURI().toURL()); }
Example #2
Source File: AuthConfig.java From festival with Apache License 2.0 | 5 votes |
@Singleton @Named public AuthProvider authProvider(Vertx vertx) { JsonObject config = new JsonObject().put("properties_path", "classpath:vertx-users.properties"); ShiroAuthOptions options = new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(config); return ShiroAuth.create(vertx, options); }
Example #3
Source File: AuthConfig.java From festival with Apache License 2.0 | 5 votes |
@Singleton @Named public AuthProvider authProvider(Vertx vertx) { JsonObject config = new JsonObject().put("properties_path", "classpath:vertx-users.properties"); ShiroAuthOptions options = new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(config); return ShiroAuth.create(vertx, options); }
Example #4
Source File: WikiServer.java From redpipe with Apache License 2.0 | 5 votes |
@Override protected AuthProvider setupAuthenticationRoutes() { AppGlobals globals = AppGlobals.get(); AuthProvider auth = ShiroAuth.create(globals.getVertx(), new ShiroAuthOptions() .setType(ShiroAuthRealmType.PROPERTIES) .setConfig(new JsonObject() .put("properties_path", globals.getConfig().getString("security_definitions")))); globals.getRouter().route().handler(UserSessionHandler.create(auth)); JsonObject keyStoreOptions = new JsonObject().put("keyStore", globals.getConfig().getJsonObject("keystore")); // attempt to load a Key file JWTAuth jwtAuth = JWTAuth.create(globals.getVertx(), new JWTAuthOptions(keyStoreOptions)); JWTAuthHandler jwtAuthHandler = JWTAuthHandler.create(jwtAuth); globals.setGlobal(JWTAuth.class, jwtAuth); globals.getRouter().route().handler(context -> { // only filter if we have a header, otherwise it will try to force auth, regardless if whether // we want auth if(context.request().getHeader(HttpHeaders.AUTHORIZATION) != null) jwtAuthHandler.handle(context); else context.next(); }); return auth; }
Example #5
Source File: Config.java From nubes with Apache License 2.0 | 5 votes |
private void createAuthHandlers() { String auth = json.getString("auth-type"); JsonObject authProperties = json.getJsonObject("auth-properties"); // TODO : discuss it. I'm really not convinced about all the boilerplate needed in config (dbName only for JDBC, etc.) if (authProperties != null) { // For now, only JWT,Shiro and JDBC supported (same as for Vert.x web) switch (auth) { case "JWT":// For now only allow properties realm this.authProvider = JWTAuth.create(vertx, authProperties); break; case "Shiro": ShiroAuth.create(vertx, new ShiroAuthOptions(authProperties)); break; case "JDBC": String dbName = json.getString("db-name"); Objects.requireNonNull(dbName); JDBCClient client = JDBCClient.createShared(vertx, authProperties, dbName); this.authProvider = JDBCAuth.create(vertx, client); break; default: LOG.warn("Unknown type of auth : " + auth + " . Ignoring."); } } else if (auth != null) { LOG.warn("You have defined " + auth + " as auth type, but didn't provide any configuration, can't create authProvider"); } }
Example #6
Source File: ShiroAuthProviderImpl.java From vertx-auth with Apache License 2.0 | 5 votes |
public static ShiroAuth create(Vertx vertx, ShiroAuthOptions options) { Realm realm; switch (options.getType()) { case PROPERTIES: realm = PropertiesAuthProvider.createRealm(options.getConfig()); break; case LDAP: realm = LDAPAuthProvider.createRealm(options.getConfig()); break; default: throw new IllegalArgumentException("Invalid shiro auth realm type: " + options.getType()); } return new ShiroAuthProviderImpl(vertx, realm); }
Example #7
Source File: PropertiesShiroAuthProviderTest.java From vertx-auth with Apache License 2.0 | 5 votes |
private void assertResolve(File cwd, String path) { try { System.setProperty("vertx.cwd", cwd.getAbsolutePath()); ShiroAuth.create(vertx, new ShiroAuthOptions().setType( ShiroAuthRealmType.PROPERTIES ).setConfig( new JsonObject().put(PropertiesProviderConstants.PROPERTIES_PROPS_PATH_FIELD, path) ) ); } finally { System.clearProperty("vertx.cwd"); } }
Example #8
Source File: LDAPShiroAuthProviderTest.java From vertx-auth with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); ldapServer = new EmbeddedADS(ldapWorkingDirectory.newFolder()); ldapServer.startServer(); insertTestUsers(); authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.LDAP).setConfig(getConfig())); }
Example #9
Source File: AuthOptionsTest.java From vertx-auth with Apache License 2.0 | 5 votes |
@Test public void testSomething() { ShiroAuthOptions options = new ShiroAuthOptions( new JsonObject().put("provider", "shiro"). put("type", "PROPERTIES"). put("config", new JsonObject().put("foo", "bar"))); assertEquals(ShiroAuthRealmType.PROPERTIES, options.getType()); assertEquals(new JsonObject().put("foo", "bar"), options.getConfig()); }
Example #10
Source File: ApiTest.java From redpipe with Apache License 2.0 | 4 votes |
@Before public void prepare(TestContext context) throws IOException { Async async = context.async(); server = new Server() { @Override protected AuthProvider setupAuthenticationRoutes() { AppGlobals globals = AppGlobals.get(); AuthProvider auth = ShiroAuth.create(globals.getVertx(), new ShiroAuthOptions() .setType(ShiroAuthRealmType.PROPERTIES) .setConfig(new JsonObject())); globals.getRouter().route().handler(UserSessionHandler.create(auth)); AuthHandler authHandler = BasicAuthHandler.create(auth); globals.getRouter().route().handler(context -> { // only filter if we have a header, otherwise it will try to force auth, regardless if whether // we want auth if(context.request().getHeader(HttpHeaders.AUTHORIZATION) != null) { // make sure we pause until we're ready to read context.request().pause(); authHandler.handle(context); }else context.next(); }); globals.getRouter().route().handler(context -> { // unpause now that we have auth if(context.request().getHeader(HttpHeaders.AUTHORIZATION) != null) { context.request().resume(); } context.next(); }); return auth; } }; server.start(TestResource.class, TestResourceRxJava1.class) .subscribe(() -> { webClient = WebClient.create(server.getVertx(), new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000)); async.complete(); }, x -> { x.printStackTrace(); context.fail(x); async.complete(); }); }
Example #11
Source File: ShiroShellAuth.java From vertx-shell with Apache License 2.0 | 4 votes |
@Override public AuthProvider create(Vertx vertx, JsonObject config) { final ShiroAuthOptions options = new ShiroAuthOptions(config); return ShiroAuth.create(vertx, options); }
Example #12
Source File: PropertiesShiroAuthProviderTest.java From vertx-auth with Apache License 2.0 | 4 votes |
@Override public void setUp() throws Exception { super.setUp(); authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(getConfig())); }
Example #13
Source File: AuthShiroExamples.java From vertx-auth with Apache License 2.0 | 3 votes |
public void example3(Vertx vertx) { JsonObject config = new JsonObject().put("properties_path", "classpath:test-auth.properties"); AuthProvider provider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(config)); }