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)


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

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

+ (Object) j_api_type



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

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



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

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

+ (Object) unwrap(obj)



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

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

+ (Object) wrap(obj)



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

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

Instance Method Details

- (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)


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

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

- (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)


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

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


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

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:



83
84
85
86
87
88
89
90
91
92
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-auth-common/user.rb', line 83

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