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

The following examples show how to use io.vertx.ext.auth.shiro.ShiroAuth. 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: Config.java    From nubes with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: ShiroAuthProviderImpl.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
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 #6
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 #7
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 #8
Source File: CreateShiroAuthProviderTest.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #9
Source File: ShiroShellAuth.java    From vertx-shell with Apache License 2.0 4 votes vote down vote up
@Override
public AuthProvider create(Vertx vertx, JsonObject config) {
  final ShiroAuthOptions options = new ShiroAuthOptions(config);
  return ShiroAuth.create(vertx, options);
}
 
Example #10
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 #11
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));

  }
 
Example #12
Source File: AuthShiroExamples.java    From vertx-auth with Apache License 2.0 2 votes vote down vote up
public void example8(Vertx vertx, Realm realm) {

    AuthProvider provider = ShiroAuth.create(vertx, realm);

  }