Class: CFoundry::UAAClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cfoundry/uaaclient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, client_id = "cf", options = {}) ⇒ UAAClient

Returns a new instance of UAAClient.



8
9
10
11
12
13
14
# File 'lib/cfoundry/uaaclient.rb', line 8

def initialize(target, client_id = "cf", options = {})
  @target = target
  @client_id = client_id
  @http_proxy = options[:http_proxy]
  @https_proxy = options[:https_proxy]
  @uaa_info_client = uaa_info_client_for(target)
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def client_id
  @client_id
end

#http_proxyObject

Returns the value of attribute http_proxy.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def http_proxy
  @http_proxy
end

#https_proxyObject

Returns the value of attribute https_proxy.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def https_proxy
  @https_proxy
end

#targetObject

Returns the value of attribute target.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def target
  @target
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def token
  @token
end

#traceObject

Returns the value of attribute trace.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def trace
  @trace
end

Instance Method Details

#add_user(email, password, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cfoundry/uaaclient.rb', line 63

def add_user(email, password, options = {})
  wrap_uaa_errors do
    scim.add(
      :user,
      {:userName => email,
        :emails => [{:value => email}],
        :password => password,
        :name => {:givenName => options[:givenName] || email,
                  :familyName => options[:familyName] || email}
      }
    )
  end
end

#authorize(credentials) ⇒ Object



22
23
24
25
26
27
# File 'lib/cfoundry/uaaclient.rb', line 22

def authorize(credentials)
  wrap_uaa_errors do
    authenticate_with_password_grant(credentials) ||
      authenticate_with_implicit_grant(credentials)
  end
end

#change_password(guid, new, old) ⇒ Object



41
42
43
44
45
# File 'lib/cfoundry/uaaclient.rb', line 41

def change_password(guid, new, old)
  wrap_uaa_errors do
    scim.change_password(guid, new, old)
  end
end

#delete_user(guid) ⇒ Object



77
78
79
80
81
# File 'lib/cfoundry/uaaclient.rb', line 77

def delete_user(guid)
  wrap_uaa_errors do
    scim.delete(:user, guid)
  end
end

#password_score(password) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cfoundry/uaaclient.rb', line 47

def password_score(password)
  wrap_uaa_errors do
    response = uaa_info_client_for(uaa_url).password_strength(password)

    required_score = response[:requiredScore] || 0
    case (response[:score] || 0)
      when 10 then
        :strong
      when required_score..9 then
        :good
      else
        :weak
    end
  end
end

#promptsObject



16
17
18
19
20
# File 'lib/cfoundry/uaaclient.rb', line 16

def prompts
  wrap_uaa_errors do
    @uaa_info_client.server[:prompts]
  end
end

#try_to_refresh_token!Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/cfoundry/uaaclient.rb', line 83

def try_to_refresh_token!
  wrap_uaa_errors do
    begin
      token_info = token_issuer.refresh_token_grant(token.refresh_token)
      self.token = AuthToken.from_uaa_token_info(token_info)
    rescue CF::UAA::TargetError
      self.token
    end
  end
end

#user(guid) ⇒ Object



29
30
31
32
33
# File 'lib/cfoundry/uaaclient.rb', line 29

def user(guid)
  wrap_uaa_errors do
    scim.get(:user, guid)
  end
end

#usersObject



35
36
37
38
39
# File 'lib/cfoundry/uaaclient.rb', line 35

def users
  wrap_uaa_errors do
    scim.query(:user)
  end
end