io.vertx.ext.auth.shiro.ShiroAuthRealmType Java Examples

The following examples show how to use io.vertx.ext.auth.shiro.ShiroAuthRealmType. 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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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: PropertiesShiroAuthProviderTest.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: LDAPShiroAuthProviderTest.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: AuthOptionsTest.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: ApiTest.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@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 #9
Source File: PropertiesShiroAuthProviderTest.java    From vertx-auth with Apache License 2.0 4 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(getConfig()));
}
 
Example #10
Source File: AuthShiroExamples.java    From vertx-auth with Apache License 2.0 3 votes vote down vote up
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));

  }