Class: VertxAuthJdbc::JDBCAuth

Inherits:
VertxAuthCommon::AuthProvider show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb

Overview

Factory interface for creating VertxAuthCommon::AuthProvider instances that use the Vert.x JDBC client. By default the hashing strategy is SHA-512. If you're already running in production this is backwards compatible, however for new deployments or security upgrades it is recommended to use the PBKDF2 strategy as it is the current OWASP recommendation for password storage.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


25
26
27
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 25

def @@j_api_type.accept?(obj)
  obj.class == JDBCAuth
end

+ (::VertxAuthJdbc::JDBCAuth) create(vertx = nil, client = nil)

Create a JDBC auth provider implementation

Parameters:

Returns:

Raises:

  • (ArgumentError)


68
69
70
71
72
73
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 68

def self.create(vertx=nil,client=nil)
  if vertx.class.method_defined?(:j_del) && client.class.method_defined?(:j_del) && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuthJdbc::JDBCAuth.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtJdbc::JDBCClient.java_class]).call(vertx.j_del,client.j_del),::VertxAuthJdbc::JDBCAuth)
  end
  raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{client})"
end

+ (Object) DEFAULT_AUTHENTICATE_QUERY

The default query to be used for authentication


159
160
161
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 159

def self.DEFAULT_AUTHENTICATE_QUERY
  Java::IoVertxExtAuthJdbc::JDBCAuth.DEFAULT_AUTHENTICATE_QUERY
end

+ (Object) DEFAULT_PERMISSIONS_QUERY

The default query to retrieve all permissions for the role


167
168
169
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 167

def self.DEFAULT_PERMISSIONS_QUERY
  Java::IoVertxExtAuthJdbc::JDBCAuth.DEFAULT_PERMISSIONS_QUERY
end

+ (Object) DEFAULT_ROLE_PREFIX

The default role prefix


171
172
173
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 171

def self.DEFAULT_ROLE_PREFIX
  Java::IoVertxExtAuthJdbc::JDBCAuth.DEFAULT_ROLE_PREFIX
end

+ (Object) DEFAULT_ROLES_QUERY

The default query to retrieve all roles for the user


163
164
165
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 163

def self.DEFAULT_ROLES_QUERY
  Java::IoVertxExtAuthJdbc::JDBCAuth.DEFAULT_ROLES_QUERY
end

+ (Object) j_api_type



34
35
36
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 34

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



37
38
39
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 37

def self.j_class
  Java::IoVertxExtAuthJdbc::JDBCAuth.java_class
end

+ (Object) unwrap(obj)



31
32
33
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 31

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



28
29
30
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 28

def @@j_api_type.wrap(obj)
  JDBCAuth.new(obj)
end

Instance Method Details

- (void) authenticate(authInfo = nil) { ... }

This method returns an undefined value.

Authenticate a user.

The first argument is a JSON object containing information for authenticating the user. What this actually contains depends on the specific implementation. In the case of a simple username/password based authentication it is likely to contain a JSON object with the following structure:


   {
     "username": "tim",
     "password": "mypassword"
   }
For other types of authentication it contain different information - for example a JWT token or OAuth bearer token.

If the user is successfully authenticated a object is passed to the handler in an AsyncResult. The user object can then be used for authorisation.

Parameters:

  • authInfo (Hash{String => Object}) (defaults to: nil)
    The auth information

Yields:

  • The result handler

Raises:

  • (ArgumentError)


58
59
60
61
62
63
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 58

def authenticate(authInfo=nil)
  if authInfo.class == Hash && block_given?
    return @j_del.java_method(:authenticate, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_json_object(authInfo),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxAuthCommon::User) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling authenticate(#{authInfo})"
end

- (String) compute_hash(password = nil, salt = nil, version = nil)

Compute the hashed password given the unhashed password and the salt The implementation relays to the JDBCHashStrategy provided.

Parameters:

  • password (String) (defaults to: nil)
    the unhashed password
  • salt (String) (defaults to: nil)
    the salt
  • version (Fixnum) (defaults to: nil)
    the nonce version to use

Returns:

  • (String)
    the hashed password

Raises:

  • (ArgumentError)


121
122
123
124
125
126
127
128
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 121

def compute_hash(password=nil,salt=nil,version=nil)
  if password.class == String && salt.class == String && !block_given? && version == nil
    return @j_del.java_method(:computeHash, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(password,salt)
  elsif password.class == String && salt.class == String && version.class == Fixnum && !block_given?
    return @j_del.java_method(:computeHash, [Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::int.java_class]).call(password,salt,version)
  end
  raise ArgumentError, "Invalid arguments when calling compute_hash(#{password},#{salt},#{version})"
end

- (String) generate_salt

Compute a salt string. The implementation relays to the JDBCHashStrategy provided.

Returns:

  • (String)
    a non null salt value

Raises:

  • (ArgumentError)


133
134
135
136
137
138
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 133

def generate_salt
  if !block_given?
    return @j_del.java_method(:generateSalt, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling generate_salt()"
end

- (self) set_authentication_query(authenticationQuery = nil)

Set the authentication query to use. Use this if you want to override the default authentication query.

Parameters:

  • authenticationQuery (String) (defaults to: nil)
    the authentication query

Returns:

  • (self)

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 77

def set_authentication_query(authenticationQuery=nil)
  if authenticationQuery.class == String && !block_given?
    @j_del.java_method(:setAuthenticationQuery, [Java::java.lang.String.java_class]).call(authenticationQuery)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_authentication_query(#{authenticationQuery})"
end

- (self) set_nonces(nonces = nil)

Provide a application configuration level on hash nonce's as a ordered list of nonces where each position corresponds to a version. The nonces are supposed not to be stored in the underlying jdbc storage but to be provided as a application configuration. The idea is to add one extra variable to the hash function in order to make breaking the passwords using rainbow tables or precomputed hashes harder. Leaving the attacker only with the brute force approach. The implementation relays to the JDBCHashStrategy provided.

Parameters:

  • nonces (Array<String,Object>) (defaults to: nil)
    a List of non null Strings.

Returns:

  • (self)

Raises:

  • (ArgumentError)


151
152
153
154
155
156
157
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 151

def set_nonces(nonces=nil)
  if nonces.class == Array && !block_given?
    @j_del.java_method(:setNonces, [Java::IoVertxCoreJson::JsonArray.java_class]).call(::Vertx::Util::Utils.to_json_array(nonces))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_nonces(#{nonces})"
end

- (self) set_permissions_query(permissionsQuery = nil)

Set the permissions query to use. Use this if you want to override the default permissions query.

Parameters:

  • permissionsQuery (String) (defaults to: nil)
    the permissions query

Returns:

  • (self)

Raises:

  • (ArgumentError)


97
98
99
100
101
102
103
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 97

def set_permissions_query(permissionsQuery=nil)
  if permissionsQuery.class == String && !block_given?
    @j_del.java_method(:setPermissionsQuery, [Java::java.lang.String.java_class]).call(permissionsQuery)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_permissions_query(#{permissionsQuery})"
end

- (self) set_role_prefix(rolePrefix = nil)

Set the role prefix to distinguish from permissions when checking for isPermitted requests.

Parameters:

  • rolePrefix (String) (defaults to: nil)
    a Prefix e.g.: "role:"

Returns:

  • (self)

Raises:

  • (ArgumentError)


107
108
109
110
111
112
113
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 107

def set_role_prefix(rolePrefix=nil)
  if rolePrefix.class == String && !block_given?
    @j_del.java_method(:setRolePrefix, [Java::java.lang.String.java_class]).call(rolePrefix)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_role_prefix(#{rolePrefix})"
end

- (self) set_roles_query(rolesQuery = nil)

Set the roles query to use. Use this if you want to override the default roles query.

Parameters:

  • rolesQuery (String) (defaults to: nil)
    the roles query

Returns:

  • (self)

Raises:

  • (ArgumentError)


87
88
89
90
91
92
93
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-jdbc/jdbc_auth.rb', line 87

def set_roles_query(rolesQuery=nil)
  if rolesQuery.class == String && !block_given?
    @j_del.java_method(:setRolesQuery, [Java::java.lang.String.java_class]).call(rolesQuery)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_roles_query(#{rolesQuery})"
end