stormpath-sdk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/stormpath-sdk/auth/authentication_result.rb +15 -0
  2. data/lib/stormpath-sdk/auth/basic_authenticator.rb +17 -2
  3. data/lib/stormpath-sdk/auth/basic_login_attempt.rb +15 -0
  4. data/lib/stormpath-sdk/auth/username_password_request.rb +15 -0
  5. data/lib/stormpath-sdk/client/api_key.rb +15 -0
  6. data/lib/stormpath-sdk/client/client.rb +15 -0
  7. data/lib/stormpath-sdk/client/client_builder.rb +17 -2
  8. data/lib/stormpath-sdk/ds/data_store.rb +26 -1
  9. data/lib/stormpath-sdk/ds/resource_factory.rb +15 -0
  10. data/lib/stormpath-sdk/http/authc/sauthc1_signer.rb +15 -0
  11. data/lib/stormpath-sdk/http/http_client_request_executor.rb +15 -0
  12. data/lib/stormpath-sdk/http/request.rb +15 -0
  13. data/lib/stormpath-sdk/http/response.rb +15 -0
  14. data/lib/stormpath-sdk/resource/account.rb +15 -0
  15. data/lib/stormpath-sdk/resource/account_list.rb +15 -0
  16. data/lib/stormpath-sdk/resource/application.rb +115 -11
  17. data/lib/stormpath-sdk/resource/application_list.rb +15 -0
  18. data/lib/stormpath-sdk/resource/collection_resource.rb +15 -0
  19. data/lib/stormpath-sdk/resource/directory.rb +15 -0
  20. data/lib/stormpath-sdk/resource/directory_list.rb +15 -0
  21. data/lib/stormpath-sdk/resource/email_verification_token.rb +15 -0
  22. data/lib/stormpath-sdk/resource/error.rb +15 -0
  23. data/lib/stormpath-sdk/resource/group.rb +15 -0
  24. data/lib/stormpath-sdk/resource/group_list.rb +15 -0
  25. data/lib/stormpath-sdk/resource/group_membership.rb +16 -1
  26. data/lib/stormpath-sdk/resource/group_membership_list.rb +15 -0
  27. data/lib/stormpath-sdk/resource/instance_resource.rb +15 -0
  28. data/lib/stormpath-sdk/resource/password_reset_token.rb +15 -0
  29. data/lib/stormpath-sdk/resource/resource.rb +15 -0
  30. data/lib/stormpath-sdk/resource/resource_error.rb +15 -0
  31. data/lib/stormpath-sdk/resource/status.rb +15 -0
  32. data/lib/stormpath-sdk/resource/tenant.rb +15 -0
  33. data/lib/stormpath-sdk/resource/utils.rb +15 -0
  34. data/lib/stormpath-sdk/util/assert.rb +15 -0
  35. data/lib/stormpath-sdk/util/hash.rb +15 -0
  36. data/lib/stormpath-sdk/util/request_utils.rb +15 -0
  37. data/lib/stormpath-sdk/version.rb +17 -2
  38. data/test/client/write_spec.rb +59 -11
  39. metadata +121 -123
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Authentication
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Authentication
@@ -30,8 +45,8 @@ module Stormpath
30
45
  attempt.set_value value
31
46
 
32
47
  href = parent_href + '/loginAttempts'
33
- result = @data_store.create href, attempt, AuthenticationResult
34
- result.get_account
48
+
49
+ @data_store.create href, attempt, AuthenticationResult
35
50
 
36
51
  end
37
52
 
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Authentication
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Authentication
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Client
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Client
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Client
@@ -11,7 +26,7 @@ module Stormpath
11
26
  # <p/>
12
27
  # Example usage:
13
28
  # <pre>
14
- # String location = "/home/jsmith/.stormpath/apiKey.yml";
29
+ # location = "/home/jsmith/.stormpath/apiKey.yml";
15
30
  #
16
31
  # client = ClientBuilder.new.set_api_key_file_location(location).build()
17
32
  # </pre>
@@ -85,7 +100,7 @@ module Stormpath
85
100
  # Assuming you were using these default property names, your {@code ClientBuilder} usage might look like the
86
101
  # following:
87
102
  # <pre>
88
- # String location = "/home/jsmith/.stormpath/apiKey.yml";
103
+ # location = "/home/jsmith/.stormpath/apiKey.yml";
89
104
  #
90
105
  # client = ClientBuilder.new.set_api_key_file_location(location).build()
91
106
  # </pre>
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module DataStore
@@ -40,7 +55,17 @@ module Stormpath
40
55
  end
41
56
 
42
57
  def create parent_href, resource, return_type
43
- save_resource parent_href, resource, return_type
58
+
59
+ returned_resource = save_resource parent_href, resource, return_type
60
+
61
+ if resource.kind_of? return_type
62
+
63
+ resource.set_properties returned_resource.properties
64
+
65
+ end
66
+
67
+ returned_resource
68
+
44
69
  end
45
70
 
46
71
  def save resource, *clazz
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module DataStore
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Http
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Http
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Http
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Http
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Resource
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Resource
@@ -1,3 +1,18 @@
1
+ #
2
+ # Copyright 2012 Stormpath, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
1
16
  module Stormpath
2
17
 
3
18
  module Resource
@@ -56,13 +71,101 @@ module Stormpath
56
71
  get_resource_property ACCOUNTS, AccountList
57
72
  end
58
73
 
59
- def get_password_reset_token
60
- get_resource_property PASSWORD_RESET_TOKENS, PasswordResetToken
74
+
75
+ #
76
+ # Sends a password reset email for the specified account username or email address. The email will contain
77
+ # a password reset link that the user can click or copy into their browser address bar.
78
+ # <p/>
79
+ # This method merely sends the password reset email that contains the link and nothing else. You will need to
80
+ # handle the link requests and then reset the account's password as described in the
81
+ # {@link #verify_password_reset_token} RDoc.
82
+ #
83
+ # @param account_username_or_email a username or email address of an Account that may login to the application.
84
+ # @return the account corresponding to the specified username or email address.
85
+ # @see #account_username_or_email
86
+ #
87
+ def send_password_reset_email account_username_or_email
88
+
89
+ password_reset_token = create_password_reset_token account_username_or_email;
90
+ password_reset_token.get_account
91
+
92
+ end
93
+
94
+ # Verifies a password reset token in a user-clicked link within an email.
95
+ # <p/>
96
+ # <h2>Base Link Configuration</h2>
97
+ # You need to define the <em>Base</em> link that will process HTTP requests when users click the link in the
98
+ # email as part of your Application's Workflow Configuration within the Stormpath UI Console. It must be a URL
99
+ # served by your application's web servers. For example:
100
+ # <pre>
101
+ # https://www.myApplication.com/passwordReset
102
+ # </pre>
103
+ # <h2>Runtime Link Processing</h2>
104
+ # When an application user clicks on the link in the email at runtime, your web server needs to process the request
105
+ # and look for an {@code spToken} request parameter. You can then verify the {@code spToken}, and then finally
106
+ # change the Account's password.
107
+ # <p/>
108
+ # Usage Example:
109
+ # <p/>
110
+ # Browser:
111
+ # {@code GET https://www.myApplication/passwordReset?spToken=someTokenValueHere}
112
+ # <p/>
113
+ # Your code:
114
+ # <pre>
115
+ # token = #get the spToken query parameter
116
+ #
117
+ # account = application.verify_password_reset_token token
118
+ #
119
+ # //token has been verified - now set the new password with what the end-user submits:
120
+ # account.set_password user_submitted_new_password
121
+ # account.save
122
+ # </pre>
123
+ #
124
+ # @param token the verification token, usually obtained as a request parameter by your application.
125
+ # @return the Account matching the specified token.
126
+ def verify_password_reset_token token
127
+
128
+ href = get_password_reset_token_href
129
+ href += '/' + token
130
+
131
+ password_reset_props = Hash.new
132
+ password_reset_props.store HREF_PROP_NAME, href
133
+
134
+ password_reset_token = data_store.instantiate PasswordResetToken, password_reset_props
135
+
136
+ password_reset_token.get_account
137
+
61
138
  end
62
139
 
140
+ #
141
+ # Authenticates an account's submitted principals and credentials (e.g. username and password). The account must
142
+ # be in one of the Application's
143
+ # <a href="http://www.stormpath.com/docs/managing-applications-login-sources">assigned Login Sources</a>. If not
144
+ # in an assigned login source, the authentication attempt will fail.
145
+ # <h2>Example</h2>
146
+ # Consider the following username/password-based example:
147
+ # <p/>
148
+ # <pre>
149
+ # request = UsernamePasswordRequest.new username, submittedRawPlaintextPassword, nil
150
+ # account = appToTest.authenticate_account(request).get_account
151
+ # </pre>
152
+ #
153
+ # @param request the authentication request representing an account's principals and credentials (e.g.
154
+ # username/password) used to verify their identity.
155
+ # @return the result of the authentication. The authenticated account can be obtained from
156
+ # {@code result.}{@link Stormpath::Authentication::AuthenticationResult#get_account}.
157
+ # @throws ResourceError if the authentication attempt fails.
158
+ #
159
+ def authenticate_account request
160
+ response = Stormpath::Authentication::BasicAuthenticator.new data_store
161
+ response.authenticate get_href, request
162
+ end
163
+
164
+ private
165
+
63
166
  def create_password_reset_token email
64
167
 
65
- href = get_password_reset_token.get_href
168
+ href = get_password_reset_token_href
66
169
 
67
170
  password_reset_props = Hash.new
68
171
  password_reset_props.store 'email', email
@@ -73,18 +176,19 @@ module Stormpath
73
176
 
74
177
  end
75
178
 
76
- def verify_password_reset_token token
179
+ def get_password_reset_token_href
77
180
 
78
- href = get_password_reset_token.get_href
79
- href += '/' + token
181
+ password_reset_tokens_href = get_property PASSWORD_RESET_TOKENS
80
182
 
81
- data_store.get_resource href, PasswordResetToken
183
+ if !password_reset_tokens_href.nil? and
184
+ password_reset_tokens_href.respond_to? 'empty?' and
185
+ !password_reset_tokens_href.empty?
82
186
 
83
- end
187
+ return password_reset_tokens_href[HREF_PROP_NAME]
188
+ end
189
+
190
+ nil
84
191
 
85
- def authenticate request
86
- response = Stormpath::Authentication::BasicAuthenticator.new data_store
87
- response.authenticate get_href, request
88
192
  end
89
193
 
90
194
  end