Class: Soar::Authorization::AccessManager::Provider::Stub

Inherits:
Object
  • Object
show all
Includes:
Jsender
Defined in:
lib/soar/authorization/access_manager/provider/stub.rb

Instance Method Summary collapse

Constructor Details

#initialize(meta: {}, policies: {}) ⇒ Stub

Returns a new instance of Stub.

Parameters:

  • meta (Hash) (defaults to: {})

    mapping service identifiers to policy identifiers

  • policies, (Hash)

    policy identifiers map to resource identifiers, that map to an array of authentication_identifiers that are allowed access



15
16
17
18
# File 'lib/soar/authorization/access_manager/provider/stub.rb', line 15

def initialize(meta: {}, policies: {})
  @meta = meta
  @policies = policies
end

Instance Method Details

#authorized?(service_identifier, resource_identifier, request) ⇒ Hash

Returns a jsend hash.

Parameters:

  • service_identifier (String)
  • resource_identifier (String)
  • request (Hash)

Returns:

  • (Hash)

    a jsend hash



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/soar/authorization/access_manager/provider/stub.rb', line 26

def authorized?(service_identifier, resource_identifier, request)
  notifications = []
  decision = false

  begin
    if ENV['RACK_ENV'] == 'development'
      notifications << 'Authorized in development environment'
      decision = true
    end

    meta = get_meta(service_identifier)
    policy = meta['policy'] if meta and meta.is_a?(Hash) and meta['policy']

    if policy.nil?
      decision = true
      notifications << 'No policy associated with service'
    else
      decision, detail = ask_policy(policy, request[:authentication_identifier], service_identifier, resource_identifier, request)
      notifications.concat(detail) if not detail.empty?
      notifications << 'Policy rejected authorization request' if not decision
      notifications << 'Policy approved authorization request' if decision
    end
  rescue SoarSr::ValidationError => ex
    notifications << "AccessManager error authorizing #{service_identifier} for #{resource_identifier}: #{ex.message}"
    decision = false
  rescue Exception => ex
    notifications << "AccessManager error authorizing #{service_identifier} for #{resource_identifier}: #{ex.message}"
    decision = false
  end
  success(notifications, { 'approved' => decision } )
end