Class: Bosh::Director::Api::UAAIdentityProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/api/uaa_identity_provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, director_uuid_provider) ⇒ UAAIdentityProvider

Returns a new instance of UAAIdentityProvider.



7
8
9
10
11
12
# File 'lib/bosh/director/api/uaa_identity_provider.rb', line 7

def initialize(options, director_uuid_provider)
  @url = options.fetch('url')
  Config.logger.debug "Initializing UAA Identity provider with url #{@url}"
  @director_uuid = director_uuid_provider.uuid
  @token_coder = CF::UAA::TokenCoder.new(skey: options.fetch('symmetric_key', nil), pkey: options.fetch('public_key', nil), scope: [])
end

Instance Method Details

#client_infoObject



18
19
20
21
22
23
24
25
# File 'lib/bosh/director/api/uaa_identity_provider.rb', line 18

def client_info
  {
    'type' => 'uaa',
    'options' => {
      'url' => @url
    }
  }
end

#get_user(request_env) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/bosh/director/api/uaa_identity_provider.rb', line 27

def get_user(request_env)
  auth_header = request_env['HTTP_AUTHORIZATION']
  token = @token_coder.decode(auth_header)
  UaaUser.new(token)
rescue CF::UAA::DecodeError, CF::UAA::AuthError => e
  raise AuthenticationError, e.message
end

#required_scopes(requested_access) ⇒ Object



44
45
46
# File 'lib/bosh/director/api/uaa_identity_provider.rb', line 44

def required_scopes(requested_access)
  permissions[requested_access]
end

#supports_api_update?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/bosh/director/api/uaa_identity_provider.rb', line 14

def supports_api_update?
  false
end

#valid_access?(user, requested_access) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/bosh/director/api/uaa_identity_provider.rb', line 35

def valid_access?(user, requested_access)
  if user.scopes
    required_scopes = required_scopes(requested_access)
    return has_admin_scope?(user.scopes) || contains_requested_scope?(required_scopes, user.scopes)
  end

  false
end