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 = "https://uaa.cloulu.com", client_id = "vmc") ⇒ UAAClient

Returns a new instance of UAAClient.



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

def initialize(target = "https://uaa.cloulu.com", client_id = "vmc")
  @target = target
  @client_id = client_id
  CF::UAA::Misc.symbolize_keys = true
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

#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) ⇒ Object



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

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

#authorize(username, password) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cfoundry/uaaclient.rb', line 20

def authorize(username, password)
  wrap_uaa_errors do
    begin
      token_issuer.owner_password_grant(username, password)
    rescue CF::UAA::BadResponse => e
      status_code = e.message[/\d+/] || 400
      raise CFoundry::Denied.new("Authorization failed", status_code)
    rescue CF::UAA::TargetError
      token_issuer.implicit_grant_with_creds(:username => username, :password => password)
    end
  end
end

#change_password(guid, new, old) ⇒ Object



39
40
41
42
43
# File 'lib/cfoundry/uaaclient.rb', line 39

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

#password_score(password) ⇒ Object



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

def password_score(password)
  wrap_uaa_errors do
    response = CF::UAA::Misc.password_strength(target, 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



14
15
16
17
18
# File 'lib/cfoundry/uaaclient.rb', line 14

def prompts
  wrap_uaa_errors do
    CF::UAA::Misc.server(target)[:prompts]
  end
end

#try_to_refresh_token!Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/cfoundry/uaaclient.rb', line 74

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

#usersObject



33
34
35
36
37
# File 'lib/cfoundry/uaaclient.rb', line 33

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