Class: Thron::Gateway::AccessManager

Inherits:
Base
  • Object
show all
Defined in:
lib/thron/gateway/access_manager.rb

Constant Summary collapse

PACKAGE =
Package.new(:xsso, :resources, self.service_name)

Constants inherited from Base

Base::NO_ACTIVE_SESSION

Instance Attribute Summary

Attributes inherited from Base

#token_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#check_session, client_id, #client_id, service_name

Methods included from Routable

included, info, #route

Class Method Details

.routesObject



9
10
11
12
13
14
15
16
17
# File 'lib/thron/gateway/access_manager.rb', line 9

def self.routes
  @routes ||= {
    login: Route::factory(name: 'login', package: PACKAGE, params: [client_id]),
    logout: Route::factory(name: 'logout', package: PACKAGE, params: [client_id], type: Route::Types::PLAIN, accept: Route::Types::PLAIN),
    validate_capabilities: Route::factory(name: 'validateCapability', package: PACKAGE, params: [client_id], type: Route::Types::PLAIN, accept: Route::Types::PLAIN),
    validate_roles: Route::factory(name: 'validateRole', package: PACKAGE, params: [client_id], type: Route::Types::PLAIN, accept: Route::Types::PLAIN),
    validate_token: Route::factory(name: 'validateToken', package: PACKAGE, params: [client_id])
  }
end

Instance Method Details

#login(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/thron/gateway/access_manager.rb', line 19

def (options = {})
  query = {
    username: options[:username],
    password: options[:password]
  }
  route(to: __callee__, query: query, dash: false) do |response|
    response.body = Entity::Base::factory(response.body)
    @token_id = response.body.token_id
  end
end

#logoutObject



30
31
32
33
34
35
# File 'lib/thron/gateway/access_manager.rb', line 30

def logout
  check_session
  route(to: __callee__, token_id: token_id, dash: false) do |response|
    @token_id = nil
  end
end

#validate_capabilities(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/thron/gateway/access_manager.rb', line 37

def validate_capabilities(options = {})
  capabilities = options.fetch(:capabilities) { [] }
  check_session
  query = {
    capabilities: capabilities.join(',')
  }
  route(to: __callee__, query: query, token_id: @token_id, dash: false)
end

#validate_roles(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/thron/gateway/access_manager.rb', line 46

def validate_roles(options = {})
  roles = options.fetch(:roles) { [] }
  xor = options.fetch(:xor) { false }
  check_session
  separator = xor ? '|' : ','
  query = {
    role: roles.join(separator)
  }
  route(to: __callee__, query: query, token_id: @token_id, dash: false)
end

#validate_token(options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/thron/gateway/access_manager.rb', line 57

def validate_token(options = {})
  username = options[:username]
  check_session
  query = {
    username: username
  }
  route(to: __callee__, query: query, token_id: @token_id, dash: false) do |response|
    response.body = Entity::Base::factory(response.body)
  end
end