stormpath-sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,42 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class Error < Resource
|
6
|
+
|
7
|
+
STATUS = "status"
|
8
|
+
CODE = "code"
|
9
|
+
MESSAGE = "message"
|
10
|
+
DEV_MESSAGE = "developerMessage"
|
11
|
+
MORE_INFO = "moreInfo"
|
12
|
+
|
13
|
+
def initialize body
|
14
|
+
super nil, body
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_status
|
18
|
+
get_property STATUS
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_code
|
22
|
+
get_property CODE
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_message
|
26
|
+
get_property MESSAGE
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_developer_message
|
30
|
+
get_property DEV_MESSAGE
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_more_info
|
34
|
+
get_property MORE_INFO
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class Group < InstanceResource
|
6
|
+
|
7
|
+
include Status
|
8
|
+
|
9
|
+
NAME = "name"
|
10
|
+
DESCRIPTION = "description"
|
11
|
+
STATUS = "status"
|
12
|
+
TENANT = "tenant"
|
13
|
+
DIRECTORY = "directory"
|
14
|
+
ACCOUNTS = "accounts"
|
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_directory
|
55
|
+
get_resource_property DIRECTORY, Directory
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_accounts
|
59
|
+
get_resource_property ACCOUNTS, AccountList
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_account account
|
63
|
+
|
64
|
+
group_membership = data_store.instantiate GroupMembership, nil
|
65
|
+
group_membership.create account, self
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class GroupMembership < InstanceResource
|
6
|
+
|
7
|
+
ACCOUNT = "account"
|
8
|
+
GROUP = "group"
|
9
|
+
|
10
|
+
def get_account
|
11
|
+
get_resource_property ACCOUNT, Account
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_account account
|
15
|
+
set_property ACCOUNT, account
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_group
|
19
|
+
get_resource_property GROUP, Group
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_group group
|
23
|
+
set_property GROUP, group
|
24
|
+
end
|
25
|
+
|
26
|
+
def create account, group
|
27
|
+
|
28
|
+
#TODO: enable auto discovery
|
29
|
+
String href = "/groupMemberships"
|
30
|
+
|
31
|
+
account_props = Hash.new
|
32
|
+
account_props.store HREF_PROP_NAME, account.get_href
|
33
|
+
|
34
|
+
group_props = Hash.new
|
35
|
+
group_props.store HREF_PROP_NAME, group.get_href
|
36
|
+
|
37
|
+
props = Hash.new
|
38
|
+
props.store ACCOUNT, account_props
|
39
|
+
props.store GROUP, group_props
|
40
|
+
|
41
|
+
group_membership = data_store.instantiate GroupMembership, props
|
42
|
+
|
43
|
+
data_store.create href, group_membership, GroupMembership
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete
|
48
|
+
data_store.delete self
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class PasswordResetToken < Resource
|
6
|
+
|
7
|
+
|
8
|
+
EMAIL = "email"
|
9
|
+
ACCOUNT = "account"
|
10
|
+
|
11
|
+
def get_email
|
12
|
+
get_property EMAIL
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_email email
|
16
|
+
set_property EMAIL, email
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_account
|
20
|
+
get_resource_property ACCOUNT, Account
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module Stormpath
|
2
|
+
|
3
|
+
module Resource
|
4
|
+
|
5
|
+
class Resource
|
6
|
+
|
7
|
+
include Utils
|
8
|
+
|
9
|
+
HREF_PROP_NAME = "href"
|
10
|
+
|
11
|
+
def initialize data_store, properties
|
12
|
+
|
13
|
+
@data_store = data_store
|
14
|
+
@read_lock = Mutex.new
|
15
|
+
@write_lock = Mutex.new
|
16
|
+
@properties = Hash.new
|
17
|
+
set_properties properties
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_properties properties
|
22
|
+
|
23
|
+
@write_lock.lock
|
24
|
+
|
25
|
+
begin
|
26
|
+
|
27
|
+
@dirty = false
|
28
|
+
|
29
|
+
if !properties.nil? and properties.is_a? Hash
|
30
|
+
@properties.replace properties
|
31
|
+
href_only = @properties.size == 1 and @properties.has_key? HREF_PROP_NAME
|
32
|
+
@materialized = !href_only
|
33
|
+
|
34
|
+
else
|
35
|
+
@materialized = false
|
36
|
+
end
|
37
|
+
|
38
|
+
ensure
|
39
|
+
@write_lock.unlock
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_property name
|
44
|
+
|
45
|
+
if !HREF_PROP_NAME.eql? name
|
46
|
+
#not the href/id, must be a property that requires materialization:
|
47
|
+
if !is_new and !materialized
|
48
|
+
|
49
|
+
materialize
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
read_property name
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_property_names
|
57
|
+
@read_lock.lock
|
58
|
+
|
59
|
+
begin
|
60
|
+
@properties.keys
|
61
|
+
ensure
|
62
|
+
@read_lock.unlock
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_href
|
68
|
+
get_property HREF_PROP_NAME
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :properties
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
attr_reader :data_store, :materialized
|
76
|
+
|
77
|
+
def get_resource_property key, clazz
|
78
|
+
|
79
|
+
value = get_property key
|
80
|
+
|
81
|
+
if value.is_a? Hash
|
82
|
+
href = get_href_from_hash value
|
83
|
+
end
|
84
|
+
|
85
|
+
if !href.nil?
|
86
|
+
@data_store.instantiate clazz, value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Returns {@code true} if the resource doesn't yet have an assigned 'href' property, {@code false} otherwise.
|
92
|
+
#
|
93
|
+
# @return {@code true} if the resource doesn't yet have an assigned 'href' property, {@code false} otherwise.
|
94
|
+
def is_new
|
95
|
+
|
96
|
+
#we can't call get_href in here, otherwise we'll have an infinite loop:
|
97
|
+
|
98
|
+
prop = read_property HREF_PROP_NAME
|
99
|
+
|
100
|
+
if prop.nil?
|
101
|
+
true
|
102
|
+
|
103
|
+
else
|
104
|
+
prop.respond_to? 'empty' and prop.empty?
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_property name, value
|
110
|
+
|
111
|
+
@write_lock.lock
|
112
|
+
|
113
|
+
begin
|
114
|
+
if value.nil?
|
115
|
+
|
116
|
+
removed = @properties.delete name
|
117
|
+
|
118
|
+
if !removed.nil?
|
119
|
+
@dirty = true
|
120
|
+
end
|
121
|
+
|
122
|
+
else
|
123
|
+
@properties.store name, value
|
124
|
+
@dirty = true
|
125
|
+
end
|
126
|
+
ensure
|
127
|
+
@write_lock.unlock
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
def materialize
|
133
|
+
clazz = to_class_from_instance self
|
134
|
+
|
135
|
+
@write_lock.lock
|
136
|
+
|
137
|
+
begin
|
138
|
+
|
139
|
+
resource = @data_store.get_resource get_href, clazz
|
140
|
+
@properties.replace resource.properties
|
141
|
+
@materialized = true
|
142
|
+
|
143
|
+
ensure
|
144
|
+
|
145
|
+
@write_lock.unlock
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def get_href_from_hash(props)
|
152
|
+
|
153
|
+
if !props.nil? and props.is_a? Hash
|
154
|
+
value = props[HREF_PROP_NAME]
|
155
|
+
end
|
156
|
+
|
157
|
+
value
|
158
|
+
end
|
159
|
+
|
160
|
+
def read_property name
|
161
|
+
@read_lock.lock
|
162
|
+
|
163
|
+
begin
|
164
|
+
@properties[name]
|
165
|
+
ensure
|
166
|
+
@read_lock.unlock
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|