cfoundry 0.3.30 → 0.3.31

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,6 +31,20 @@ module CFoundry
31
31
  request(method, path, options)
32
32
  end
33
33
 
34
+ # grab the metadata from a token that looks like:
35
+ #
36
+ # bearer (base64 ...)
37
+ def token_data
38
+ tok = Base64.decode64(@token.sub(/^bearer\s+/, ""))
39
+ tok.sub!(/\{.+?\}/, "") # clear algo
40
+ MultiJson.load(tok[/\{.+?\}/], :symbolize_keys => true)
41
+
42
+ # normally i don't catch'em all, but can't expect all tokens to be the
43
+ # proper format, so just silently fail as this is not critical
44
+ rescue
45
+ {}
46
+ end
47
+
34
48
  private
35
49
 
36
50
  def parse_json(x)
@@ -35,6 +35,16 @@ module CFoundry
35
35
  get("Users", nil => :json)
36
36
  end
37
37
 
38
+ def change_password(guid, new, old)
39
+ put(
40
+ { :schemas => ["urn:scim:schemas:core:1.0"],
41
+ :password => new,
42
+ :oldPassword => old
43
+ },
44
+ "User", guid, "password",
45
+ :json => nil)
46
+ end
47
+
38
48
  private
39
49
 
40
50
  def handle_response(response, accept)
@@ -67,6 +67,19 @@ module CFoundry::V1
67
67
  manifest[:password] = str
68
68
  end
69
69
 
70
+ def guid
71
+ @guid ||= @client.base.token_data[:user_id]
72
+ end
73
+
74
+ def change_password!(new, old)
75
+ if @client.base.uaa
76
+ @client.base.uaa.change_password(guid, new, old)
77
+ else
78
+ self.password = new
79
+ update!
80
+ end
81
+ end
82
+
70
83
  private
71
84
 
72
85
  def manifest
@@ -68,9 +68,9 @@ module CFoundry::V2
68
68
 
69
69
  # The currently authenticated user.
70
70
  def current_user
71
- if guid = token_data[:user_id]
71
+ if guid = @base.token_data[:user_id]
72
72
  user = user(guid)
73
- user.emails = [{ :value => token_data[:email] }]
73
+ user.emails = [{ :value => @base.token_data[:email] }]
74
74
  user
75
75
  end
76
76
  end
@@ -194,21 +194,5 @@ module CFoundry::V2
194
194
  json)
195
195
  end
196
196
  end
197
-
198
- private
199
-
200
- # grab the metadata from a token that looks like:
201
- #
202
- # bearer (base64 ...)
203
- def token_data
204
- tok = Base64.decode64(@base.token.sub(/^bearer\s+/, ""))
205
- tok.sub!(/\{.+?\}/, "") # clear algo
206
- MultiJson.load(tok[/\{.+?\}/], :symbolize_keys => true)
207
-
208
- # normally i don't catch'em all, but can't expect all tokens to be the
209
- # proper format, so just silently fail as this is not critical
210
- rescue
211
- {}
212
- end
213
197
  end
214
198
  end
@@ -25,6 +25,10 @@ module CFoundry::V2
25
25
 
26
26
  alias :admin? :admin
27
27
 
28
+ def change_password!(new, old)
29
+ @client.base.uaa.change_password(@guid, new, old)
30
+ end
31
+
28
32
  # optional metadata from UAA
29
33
  attr_accessor :emails, :name
30
34
 
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.30"
3
+ VERSION = "0.3.31"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 47
4
+ hash: 45
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 30
10
- version: 0.3.30
9
+ - 31
10
+ version: 0.3.31
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-07 00:00:00 Z
18
+ date: 2012-09-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client