stormpath-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/README.md +24 -0
- data/Rakefile +16 -0
- data/lib/stormpath-sdk.rb +49 -0
- data/lib/stormpath-sdk/auth/authentication_result.rb +17 -0
- data/lib/stormpath-sdk/auth/basic_authenticator.rb +42 -0
- data/lib/stormpath-sdk/auth/basic_login_attempt.rb +30 -0
- data/lib/stormpath-sdk/auth/username_password_request.rb +43 -0
- data/lib/stormpath-sdk/client/api_key.rb +18 -0
- data/lib/stormpath-sdk/client/client.rb +23 -0
- data/lib/stormpath-sdk/client/client_builder.rb +291 -0
- data/lib/stormpath-sdk/ds/data_store.rb +150 -0
- data/lib/stormpath-sdk/ds/resource_factory.rb +22 -0
- data/lib/stormpath-sdk/http/authc/sauthc1_signer.rb +216 -0
- data/lib/stormpath-sdk/http/http_client_request_executor.rb +69 -0
- data/lib/stormpath-sdk/http/request.rb +83 -0
- data/lib/stormpath-sdk/http/response.rb +35 -0
- data/lib/stormpath-sdk/resource/account.rb +110 -0
- data/lib/stormpath-sdk/resource/account_list.rb +17 -0
- data/lib/stormpath-sdk/resource/application.rb +95 -0
- data/lib/stormpath-sdk/resource/application_list.rb +17 -0
- data/lib/stormpath-sdk/resource/collection_resource.rb +76 -0
- data/lib/stormpath-sdk/resource/directory.rb +76 -0
- data/lib/stormpath-sdk/resource/directory_list.rb +15 -0
- data/lib/stormpath-sdk/resource/email_verification_token.rb +11 -0
- data/lib/stormpath-sdk/resource/error.rb +42 -0
- data/lib/stormpath-sdk/resource/group.rb +73 -0
- data/lib/stormpath-sdk/resource/group_list.rb +18 -0
- data/lib/stormpath-sdk/resource/group_membership.rb +55 -0
- data/lib/stormpath-sdk/resource/group_membership_list.rb +17 -0
- data/lib/stormpath-sdk/resource/instance_resource.rb +13 -0
- data/lib/stormpath-sdk/resource/password_reset_token.rb +27 -0
- data/lib/stormpath-sdk/resource/resource.rb +173 -0
- data/lib/stormpath-sdk/resource/resource_error.rb +32 -0
- data/lib/stormpath-sdk/resource/status.rb +19 -0
- data/lib/stormpath-sdk/resource/tenant.rb +55 -0
- data/lib/stormpath-sdk/resource/utils.rb +16 -0
- data/lib/stormpath-sdk/util/assert.rb +26 -0
- data/lib/stormpath-sdk/util/hash.rb +17 -0
- data/lib/stormpath-sdk/util/request_utils.rb +57 -0
- data/lib/stormpath-sdk/version.rb +4 -0
- data/stormpath-sdk.gemspec +29 -0
- data/test/client/client.yml +16 -0
- data/test/client/clientbuilder_spec.rb +176 -0
- data/test/client/read_spec.rb +243 -0
- data/test/client/write_spec.rb +315 -0
- metadata +226 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Http
|
4
|
+
|
5
|
+
class Request
|
6
|
+
|
7
|
+
include Stormpath::Util
|
8
|
+
|
9
|
+
attr_accessor :http_method, :href, :query_string, :http_headers, :body
|
10
|
+
|
11
|
+
def initialize(http_method, href, query_string, http_headers, body)
|
12
|
+
|
13
|
+
splitted = href.split '?'
|
14
|
+
|
15
|
+
if query_string.nil?
|
16
|
+
@query_string = Hash.new
|
17
|
+
else
|
18
|
+
@query_string = query_string
|
19
|
+
end
|
20
|
+
|
21
|
+
if !splitted.nil? and splitted.length > 1
|
22
|
+
@href = splitted[0]
|
23
|
+
query_string_str = splitted[1]
|
24
|
+
|
25
|
+
query_string_arr = query_string_str.split '&'
|
26
|
+
|
27
|
+
query_string_arr.each do |pair|
|
28
|
+
|
29
|
+
pair_arr = pair.split '='
|
30
|
+
|
31
|
+
@query_string.store pair_arr[0], pair_arr[1]
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
else
|
36
|
+
|
37
|
+
@href = href
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
@http_method = http_method.upcase
|
42
|
+
@http_headers = http_headers
|
43
|
+
@body = body
|
44
|
+
|
45
|
+
if !body.nil?
|
46
|
+
@http_headers.store 'Content-Length', @body.length
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def resource_uri
|
52
|
+
URI href
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s_query_string canonical
|
56
|
+
|
57
|
+
result = ''
|
58
|
+
|
59
|
+
if !@query_string.empty?
|
60
|
+
|
61
|
+
@query_string.each do |key, value|
|
62
|
+
|
63
|
+
enc_key = RequestUtils.encode_url key, false, canonical
|
64
|
+
enc_value = RequestUtils.encode_url value, false, canonical
|
65
|
+
|
66
|
+
if !result.empty?
|
67
|
+
result << '&'
|
68
|
+
end
|
69
|
+
|
70
|
+
result << enc_key << '='<< enc_value
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Http
|
4
|
+
|
5
|
+
class Response
|
6
|
+
|
7
|
+
attr_reader :http_status, :headers, :body
|
8
|
+
attr_writer :headers
|
9
|
+
|
10
|
+
def initialize http_status, content_type, body, content_length
|
11
|
+
@http_status = http_status
|
12
|
+
@headers = HTTP::Message::Headers.new
|
13
|
+
@body = body
|
14
|
+
@headers.content_type = content_type
|
15
|
+
@headers.body_size = content_length
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def client_error?
|
20
|
+
http_status >= 400 and http_status < 500
|
21
|
+
end
|
22
|
+
|
23
|
+
def server_error?
|
24
|
+
http_status >= 500 and http_status < 600
|
25
|
+
end
|
26
|
+
|
27
|
+
def error?
|
28
|
+
client_error? or server_error?
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class Account < InstanceResource
|
6
|
+
|
7
|
+
include Status
|
8
|
+
|
9
|
+
USERNAME = "username"
|
10
|
+
EMAIL = "email"
|
11
|
+
PASSWORD = "password"
|
12
|
+
GIVEN_NAME = "givenName"
|
13
|
+
MIDDLE_NAME = "middleName"
|
14
|
+
SURNAME = "surname"
|
15
|
+
STATUS = "status"
|
16
|
+
GROUPS = "groups"
|
17
|
+
DIRECTORY = "directory"
|
18
|
+
EMAIL_VERIFICATION_TOKEN = "emailVerificationToken"
|
19
|
+
GROUP_MEMBERSHIPS = "groupMemberships"
|
20
|
+
|
21
|
+
def get_username
|
22
|
+
get_property USERNAME
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_username username
|
26
|
+
set_property USERNAME, username
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_email
|
30
|
+
get_property EMAIL
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_email email
|
34
|
+
set_property EMAIL, email
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_password password
|
38
|
+
set_property PASSWORD, password
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_given_name
|
42
|
+
get_property GIVEN_NAME
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_given_name given_name
|
46
|
+
set_property GIVEN_NAME, given_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_middle_name
|
50
|
+
get_property MIDDLE_NAME
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_middle_name middle_name
|
54
|
+
set_property MIDDLE_NAME, middle_name
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_surname
|
58
|
+
get_property SURNAME
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_surname surname
|
62
|
+
set_property SURNAME, surname
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_status
|
66
|
+
value = get_property STATUS
|
67
|
+
|
68
|
+
if !value.nil?
|
69
|
+
value = value.upcase
|
70
|
+
end
|
71
|
+
|
72
|
+
value
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_status status
|
76
|
+
|
77
|
+
if get_status_hash.has_key? status
|
78
|
+
set_property STATUS, get_status_hash[status]
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_groups
|
84
|
+
get_resource_property GROUPS, GroupList
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_directory
|
88
|
+
get_resource_property DIRECTORY, Directory
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_email_verification_token
|
92
|
+
get_resource_property EMAIL_VERIFICATION_TOKEN, EmailVerificationToken
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_group group
|
96
|
+
|
97
|
+
group_membership = data_store.instantiate GroupMembership, nil
|
98
|
+
group_membership.create self, group
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_group_memberships
|
103
|
+
get_resource_property GROUP_MEMBERSHIPS, GroupMembershipList
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class Application < InstanceResource
|
6
|
+
|
7
|
+
include Status
|
8
|
+
|
9
|
+
NAME = "name"
|
10
|
+
DESCRIPTION = "description"
|
11
|
+
STATUS = "status"
|
12
|
+
TENANT = "tenant"
|
13
|
+
ACCOUNTS = "accounts"
|
14
|
+
PASSWORD_RESET_TOKENS = "passwordResetTokens"
|
15
|
+
|
16
|
+
def get_name
|
17
|
+
get_property NAME
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_name name
|
21
|
+
set_property NAME, name
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_description
|
25
|
+
get_property DESCRIPTION
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_description description
|
29
|
+
set_property DESCRIPTION, description
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_status
|
33
|
+
value = get_property STATUS
|
34
|
+
|
35
|
+
if !value.nil?
|
36
|
+
value = value.upcase
|
37
|
+
end
|
38
|
+
|
39
|
+
value
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_status status
|
43
|
+
|
44
|
+
if get_status_hash.has_key? status
|
45
|
+
set_property STATUS, get_status_hash[status]
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_tenant
|
51
|
+
get_resource_property TENANT, Tenant
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_accounts
|
55
|
+
|
56
|
+
get_resource_property ACCOUNTS, AccountList
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_password_reset_token
|
60
|
+
get_resource_property PASSWORD_RESET_TOKENS, PasswordResetToken
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_password_reset_token email
|
64
|
+
|
65
|
+
href = get_password_reset_token.get_href
|
66
|
+
|
67
|
+
password_reset_props = Hash.new
|
68
|
+
password_reset_props.store 'email', email
|
69
|
+
|
70
|
+
password_reset_token = data_store.instantiate PasswordResetToken, password_reset_props
|
71
|
+
|
72
|
+
data_store.create href, password_reset_token, PasswordResetToken
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def verify_password_reset_token token
|
77
|
+
|
78
|
+
href = get_password_reset_token.get_href
|
79
|
+
href += '/' + token
|
80
|
+
|
81
|
+
data_store.get_resource href, PasswordResetToken
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def authenticate request
|
86
|
+
response = Stormpath::Authentication::BasicAuthenticator.new data_store
|
87
|
+
response.authenticate get_href, request
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class CollectionResource < Resource
|
6
|
+
|
7
|
+
OFFSET = "offset"
|
8
|
+
LIMIT = "limit"
|
9
|
+
ITEMS = "items"
|
10
|
+
|
11
|
+
def each(&block)
|
12
|
+
get_current_page.items.each(&block)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def get_offset
|
18
|
+
get_property OFFSET
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_limit
|
22
|
+
get_property LIMIT
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_current_page
|
26
|
+
|
27
|
+
value = get_property ITEMS
|
28
|
+
items = to_resource_array value
|
29
|
+
|
30
|
+
Page.new get_offset, get_limit, items
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_resource clazz, properties
|
34
|
+
self.data_store.instantiate clazz, properties
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def to_resource_array vals
|
40
|
+
|
41
|
+
clazz = get_item_type
|
42
|
+
items = Array.new
|
43
|
+
|
44
|
+
if vals.is_a? Array
|
45
|
+
|
46
|
+
i = 0
|
47
|
+
vals.each { |val|
|
48
|
+
resource = to_resource clazz, val
|
49
|
+
items[i] = resource
|
50
|
+
i = i + 1
|
51
|
+
}
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
items
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
class Page
|
63
|
+
|
64
|
+
attr_reader :offset, :limit, :items
|
65
|
+
|
66
|
+
def initialize offset, limit, items
|
67
|
+
@offset = offset
|
68
|
+
@limit = limit
|
69
|
+
@items = items
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class Directory < InstanceResource
|
6
|
+
|
7
|
+
include Status
|
8
|
+
|
9
|
+
NAME = "name"
|
10
|
+
DESCRIPTION = "description"
|
11
|
+
STATUS = "status"
|
12
|
+
ACCOUNTS = "accounts"
|
13
|
+
GROUPS = "groups"
|
14
|
+
TENANT = "tenant"
|
15
|
+
|
16
|
+
def get_name
|
17
|
+
get_property NAME
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_name name
|
21
|
+
set_property NAME, name
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_description
|
25
|
+
get_property DESCRIPTION
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_description description
|
29
|
+
set_property DESCRIPTION, description
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_status
|
33
|
+
value = get_property STATUS
|
34
|
+
|
35
|
+
if !value.nil?
|
36
|
+
value = value.upcase
|
37
|
+
end
|
38
|
+
|
39
|
+
value
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_status status
|
43
|
+
|
44
|
+
if get_status_hash.has_key? status
|
45
|
+
set_property STATUS, get_status_hash[status]
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_account account, *registration_workflow_enabled
|
51
|
+
accounts = get_accounts
|
52
|
+
href = accounts.get_href
|
53
|
+
if !registration_workflow_enabled.nil? and !registration_workflow_enabled.empty?
|
54
|
+
href += '?registrationWorkflowEnabled=' + registration_workflow_enabled[0].to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
data_store.create href, account, Account
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_accounts
|
61
|
+
get_resource_property ACCOUNTS, AccountList
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_groups
|
65
|
+
get_resource_property GROUPS, GroupList
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_tenant
|
69
|
+
get_resource_property TENANT, Tenant
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|