Class: VertxAuthCommon::User

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb

Overview

Represents an authenticates User and contains operations to authorise the user.

Please consult the documentation for a detailed explanation.

Direct Known Subclasses

VertxAuthOauth2::AccessToken

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


23
24
25
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 23

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

+ (::VertxAuthCommon::User) create(principal) + (::VertxAuthCommon::User) create(principal, attributes)

Overloads:

  • + (::VertxAuthCommon::User) create(principal)

    Parameters:

    • principal (Hash{String => Object})
  • + (::VertxAuthCommon::User) create(principal, attributes)

    Parameters:

    • principal (Hash{String => Object})
    • attributes (Hash{String => Object})

Returns:



144
145
146
147
148
149
150
151
152
153
154
155
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 144

def self.create(*args)
  if args[0].class == Hash && !block_given? && args[1] == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuth::User.java_method(:create, [Java::IoVertxCoreJson::JsonObject.java_class]).call(::Vertx::Util::Utils.to_json_object(args[0])),::VertxAuthCommon::User)
  elsif args[0].class == Hash && args[1].class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuth::User.java_method(:create, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCoreJson::JsonObject.java_class]).call(::Vertx::Util::Utils.to_json_object(args[0]),::Vertx::Util::Utils.to_json_object(args[1])),::VertxAuthCommon::User)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling create(#{args[0]},#{args[1]})"
  end
end

+ (Object) j_api_type



32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 32

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



35
36
37
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 35

def self.j_class
  Java::IoVertxExtAuth::User.java_class
end

+ (Object) unwrap(obj)



29
30
31
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 29

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

+ (Object) wrap(obj)



26
27
28
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 26

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

Instance Method Details

- (Hash{String => Object}) attributes

Gets extra attributes of the user. Attributes contains any attributes related to the outcome of authenticating a user (e.g.: issued date, metadata, etc...)

Returns:

  • (Hash{String => Object})
    a json object with any relevant attribute.


160
161
162
163
164
165
166
167
168
169
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 160

def attributes
  if !block_given?
    return @j_del.java_method(:attributes, []).call() != nil ? JSON.parse(@j_del.java_method(:attributes, []).call().encode) : nil
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling attributes()"
  end
end

- (::VertxAuthCommon::Authorizations) authorizations

returns user's authorizations


128
129
130
131
132
133
134
135
136
137
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 128

def authorizations
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:authorizations, []).call(),::VertxAuthCommon::Authorizations)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling authorizations()"
  end
end

- (self) clearCache

The User object will cache any authorities that it knows it has to avoid hitting the underlying auth provider each time. Use this method if you want to clear this cache.

Returns:

  • (self)


174
175
176
177
178
179
180
181
182
183
184
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 174

def clear_cache
  if !block_given?
    @j_del.java_method(:clearCache, []).call()
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling clear_cache()"
  end
end

- (true, false) expired - (true, false) expired(leeway)

Flags this user object to be expired. Expiration takes 3 values in account:
  1. exp "expiration" timestamp in seconds.
  2. iat "issued at" in seconds.
  3. nbf "not before" in seconds.
A User is considered expired if it contains any of the above and the current clock time does not agree with the parameter value. If the #principal do not contain a key then #attributes are checked.

If all of the properties are not available the user will not expire.

Implementations of this interface might relax this rule to account for a leeway to safeguard against clock drifting.

Overloads:

  • - (true, false) expired(leeway)

    Parameters:

    • leeway (Fixnum)
      a greater than zero leeway value.

Returns:

  • (true, false)
    true if expired


98
99
100
101
102
103
104
105
106
107
108
109
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 98

def expired?(*args)
  if !block_given? && args[0] == nil
    return @j_del.java_method(:expired, []).call()
  elsif args[0].class == Fixnum && !block_given?
    return @j_del.java_method(:expired, [Java::int.java_class]).call(args[0])
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling expired?(#{args[0]})"
  end
end

- (self) isAuthorized(authority, resultHandler) { ... }

Is the user authorised to

Parameters:

  • authority (String)
    the authority - what this really means is determined by the specific implementation. It might represent a permission to access a resource e.g. `printers:printer34` or it might represent authority to a role in a roles based model, e.g. `role:admin`.

Yields:

  • handler that will be called with an AsyncResult containing the value `true` if the they has the authority or `false` otherwise.

Returns:

  • (self)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 62

def is_authorized(*args)
  if args[0].class == String && true
    if (block_given?)
      @j_del.java_method(:isAuthorized, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:isAuthorized, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling is_authorized(#{args[0]})"
  end
end

- (Hash{String => Object}) principal

Get the underlying principal for the User. What this actually returns depends on the implementation. For a simple user/password based auth, it's likely to contain a JSON object with the following structure:

   {
     "username", "tim"
   }
 

Returns:

  • (Hash{String => Object})
    JSON representation of the Principal


47
48
49
50
51
52
53
54
55
56
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 47

def principal
  if !block_given?
    return @j_del.java_method(:principal, []).call() != nil ? JSON.parse(@j_del.java_method(:principal, []).call().encode) : nil
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling principal()"
  end
end

- (void) setAuthProvider(authProvider)

This method returns an undefined value.

Set the auth provider for the User. This is typically used to reattach a detached User with an AuthProvider, e.g. after it has been deserialized.

Parameters:



115
116
117
118
119
120
121
122
123
124
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 115

def set_auth_provider(*args)
  if args[0].class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:setAuthProvider, [Java::IoVertxExtAuth::AuthProvider.java_class]).call(args[0].j_del)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_auth_provider(#{args[0]})"
  end
end