Class List Method List File List

# Class: VertxAuthCommon::User

Inherits:
  Object
  - Object
  - VertxAuthCommon::User
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/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

## Instance Method Summary (collapse)

- - (self) clear_cache
  The User object will cache any authorities that it knows it has to avoid hitting the underlying auth provider each time.
- - (self) is_authorised(authority = nil) { ... }
  Is the user authorised to.
- - (Hash{String => Object}) principal
  Get the underlying principal for the User.
- - (void) set_auth_provider(authProvider = nil)
  Set the auth provider for the User.

## Instance Method Details

### - (`self`) clear_cache

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

Raises:

- (`ArgumentError`)

    33
    34
    35
    36
    37
    38
    39
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/user.rb', line 33

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

### - (`self`) is_authorised(authority = nil) { ... }

Is the user authorised to

Parameters:

- authority (`String`) (defaults to: `nil`) —
  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`)

Raises:

- (`ArgumentError`)

    23
    24
    25
    26
    27
    28
    29
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/user.rb', line 23

    def is_authorised(authority=nil)
      if authority.class == String && block_given?
        @j_del.java_method(:isAuthorised, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(authority,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling is_authorised(authority)"
    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

Raises:

- (`ArgumentError`)

    48
    49
    50
    51
    52
    53
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/user.rb', line 48

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

### - (`void`) set_auth_provider(authProvider = nil)

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:

- authProvider (`::VertxAuthCommon::AuthProvider`) (defaults to: `nil`) —
  the AuthProvider - this must be the same type of AuthProvider that originally created the User

Raises:

- (`ArgumentError`)

    58
    59
    60
    61
    62
    63
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-common/user.rb', line 58

    def set_auth_provider(authProvider=nil)
      if authProvider.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:setAuthProvider, [Java::IoVertxExtAuth::AuthProvider.java_class]).call(authProvider.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling set_auth_provider(authProvider)"
    end