Java源码示例:io.vertx.ext.auth.jdbc.JDBCAuth

示例1
@Override
public AuthProvider create(Vertx vertx, JsonObject config) {
  final JDBCAuthOptions options = new JDBCAuthOptions(config);
  final JDBCClient client;

  if (options.isShared()) {
    String datasourceName = options.getDatasourceName();
    if (datasourceName != null) {
      client = JDBCClient.createShared(vertx, options.getConfig(), datasourceName);
    } else {
      client = JDBCClient.createShared(vertx, options.getConfig());
    }
  } else {
    client = JDBCClient.create(vertx, options.getConfig());
  }

  final JDBCAuth auth = JDBCAuth.create(vertx, client);

  if (options.getAuthenticationQuery() != null) {
    auth.setAuthenticationQuery(options.getAuthenticationQuery());
  }
  if (options.getRolesQuery() != null) {
    auth.setRolesQuery(options.getRolesQuery());
  }
  if (options.getPermissionsQuery() != null) {
    auth.setPermissionsQuery(options.getPermissionsQuery());
  }
  if (options.getRolesPrefix() != null) {
    auth.setRolePrefix(options.getRolesPrefix());
  }
  return auth;
}
 
示例2
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");
  }

}
 
示例3
@Override
public JDBCAuth setHashStrategy(JDBCHashStrategy strategy) {
  this.hashStrategy = Objects.requireNonNull(strategy);
  // we've got to recreate the authenticationProvider provider to pick-up the new hash strategy
  this.authenticationProvider = JDBCAuthentication.create(client, strategy, authenticationOptions);
  return this;
}
 
示例4
@Override
public JDBCAuth setAuthenticationQuery(String authenticationQuery) {
  this.authenticationOptions.setAuthenticationQuery(authenticationQuery);
  return this;
}
 
示例5
@Override
public JDBCAuth setRolesQuery(String rolesQuery) {
  this.authorizationOptions.setRolesQuery(rolesQuery);
  return this;
}
 
示例6
@Override
public JDBCAuth setPermissionsQuery(String permissionsQuery) {
  this.authorizationOptions.setPermissionsQuery(permissionsQuery);
  return this;
}
 
示例7
@Override
public JDBCAuth setRolePrefix(String rolePrefix) {
  return this;
}
 
示例8
@Override
public JDBCAuth setNonces(JsonArray nonces) {
  hashStrategy.setNonces(nonces);
  return this;
}
 
示例9
protected JDBCAuth createProvider() {
  JDBCClient client = JDBCClient.create(vertx, config());
  return JDBCAuth.create(vertx, client);
}