clonk 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clonk/connection.rb +3 -0
- data/lib/clonk/permission.rb +12 -6
- data/lib/clonk/policy.rb +47 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dbbf649c57b88028e39c185d182ccb7502a82408d28897cdb3f0bfd61e43474
|
4
|
+
data.tar.gz: 9328de2fd40ed3d38a23a4d500bfc6e4b5e1d02ceb04817e2fe4b5fbbbdc966b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3023ad8b816db8dca997fb2b32c95661411523254f7cf51a681c20f01a86f229091627fc34e8f8644f57fdd9d5e36aaa38bef2ad655d93b9b1ee0baa2ba8144b
|
7
|
+
data.tar.gz: 47831b99a46c9289bff80ee78a25a1913b4b8fc71e7ec2366ba958b0957fc18f767abf0fd19e66e9d000b63953b6b97cfd87def5e9447c77edebadc4a37e61e9
|
data/lib/clonk/connection.rb
CHANGED
@@ -58,6 +58,9 @@ module Clonk
|
|
58
58
|
|
59
59
|
##
|
60
60
|
# Returns the config in SSO for an object.
|
61
|
+
#--
|
62
|
+
# FIXME: Does not work for policies or permissions
|
63
|
+
#++
|
61
64
|
def config(object)
|
62
65
|
class_name = object.class.name.split('::').last.downcase + 's'
|
63
66
|
class_name = 'roles-by-id' if class_name == 'roles'
|
data/lib/clonk/permission.rb
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Clonk
|
4
|
+
# Represents a permission in SSO. Methods on Clonk::Connection can be used to
|
5
|
+
# index its policies, resources and associated scopes
|
4
6
|
class Permission
|
5
|
-
def initialize(permission_response
|
7
|
+
def initialize(permission_response)
|
6
8
|
@id = permission_response['id']
|
7
|
-
@
|
9
|
+
@name = permission_response['name']
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
13
|
# Defines a connection to SSO.
|
12
14
|
class Connection
|
13
15
|
def permissions
|
14
|
-
clients.find { |client| client.name == 'realm-management' }
|
16
|
+
realm_management = clients.find { |client| client.name == 'realm-management' }
|
17
|
+
objects(type: 'Permission',
|
18
|
+
path: "/clients/#{realm_management.id}/authz/resource-server/permission"
|
19
|
+
)
|
15
20
|
end
|
21
|
+
|
16
22
|
##
|
17
23
|
# Returns the policy IDs associated with a permission.
|
18
24
|
# FIXME: untested!
|
19
|
-
def
|
25
|
+
def policies_for(permission)
|
20
26
|
parsed_response(
|
21
27
|
path: "#{url_for(permission, prefix: 'policy')}/associatedPolicies"
|
22
28
|
)
|
@@ -25,7 +31,7 @@ module Clonk
|
|
25
31
|
##
|
26
32
|
# Returns the resource IDs associated with this permission.
|
27
33
|
# FIXME: untested!
|
28
|
-
def
|
34
|
+
def resources_for(permission)
|
29
35
|
parsed_response(
|
30
36
|
path: "#{url_for(permission, prefix: 'policy')}/resources"
|
31
37
|
)
|
@@ -34,7 +40,7 @@ module Clonk
|
|
34
40
|
##
|
35
41
|
# Returns the scope IDs associated with this permission.
|
36
42
|
# FIXME: untested
|
37
|
-
def
|
43
|
+
def scopes_for(permission)
|
38
44
|
parsed_response(
|
39
45
|
path: "#{url_for(permission, prefix: 'policy')}/scopes"
|
40
46
|
)
|
data/lib/clonk/policy.rb
CHANGED
@@ -1,46 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Clonk
|
4
|
+
# Represents a policy in SSO.
|
5
|
+
# FIXME: Has not been fully updated from v1's use of the API.
|
4
6
|
class Policy
|
5
7
|
attr_accessor :id
|
6
8
|
attr_reader :name
|
7
9
|
|
8
|
-
def initialize(policy_response
|
10
|
+
def initialize(policy_response)
|
9
11
|
@id = policy_response['id']
|
10
12
|
@name = policy_response['name']
|
11
|
-
@realm = realm
|
12
|
-
end
|
13
|
-
|
14
|
-
##
|
15
|
-
# Gets config inside SSO for policy with ID in realm.
|
16
|
-
# FIXME: move to connection class
|
17
|
-
|
18
|
-
def self.get_config(id, realm = REALM)
|
19
|
-
Clonk.parsed_response(
|
20
|
-
path: "#{Clonk.realm_admin_root(realm)}/clients/#{Clonk::Client.find_by(name: 'realm-management').id}/authz/resource-server/policy/role/#{id}"
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Creates a new Policy instance from a policy that exists in SSO
|
26
|
-
# FIXME: move to connection class
|
27
|
-
|
28
|
-
def self.new_from_id(id, realm = REALM)
|
29
|
-
new(get_config(id, realm), realm)
|
30
13
|
end
|
31
14
|
|
32
15
|
##
|
33
16
|
# Returns defaults for a policy.
|
34
17
|
# I've found no reason to override these, but then again, I'm not 100% sure
|
35
18
|
# how they work. Overrides will be added to necessary methods if requested.
|
36
|
-
# FIXME: move to connection class
|
37
|
-
|
38
19
|
def self.defaults
|
39
20
|
{
|
40
21
|
logic: 'POSITIVE',
|
41
22
|
decisionStrategy: 'UNANIMOUS'
|
42
23
|
}
|
43
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Connection
|
28
|
+
def policies
|
29
|
+
realm_management = clients.find { |client| client.name == 'realm-management' }
|
30
|
+
objects(type: 'Policy',
|
31
|
+
path: "/clients/#{realm_management.id}/authz/resource-server/policy"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Gets config inside SSO for policy with ID in realm.
|
37
|
+
#--
|
38
|
+
# FIXME: bring in line with existing config method
|
39
|
+
#++
|
40
|
+
|
41
|
+
def get_policy_config(id)
|
42
|
+
parsed_response(
|
43
|
+
path: "#{realm_admin_root(realm)}/clients/#{clients.find { |client|
|
44
|
+
client.name == 'realm-management'
|
45
|
+
}.id}/authz/resource-server/policy/role/#{id}"
|
46
|
+
)
|
47
|
+
end
|
44
48
|
|
45
49
|
##
|
46
50
|
# Returns a policy definition that can then be used to create a policy in SSO.
|
@@ -48,15 +52,26 @@ module Clonk
|
|
48
52
|
#--
|
49
53
|
# TODO: Expand to allow for other policy types
|
50
54
|
# TODO: Don't assume role as default type
|
51
|
-
# FIXME:
|
55
|
+
# FIXME: give objects a type method, split this into two functions
|
52
56
|
#++
|
53
57
|
|
54
|
-
def
|
55
|
-
|
58
|
+
def define_policy(type: :role, name: nil, objects: [], description: nil, groups_claim: nil)
|
59
|
+
objects = if type == :role
|
60
|
+
{
|
61
|
+
roles: objects.map do |role|
|
62
|
+
{ id: role.id, required: true }
|
63
|
+
end
|
64
|
+
}
|
65
|
+
elsif type == :group
|
66
|
+
{
|
67
|
+
groups: objects.map do |group|
|
68
|
+
{ id: group.id, extendChildren: false }
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
defaults.merge(objects).merge(
|
56
73
|
type: type,
|
57
74
|
name: name,
|
58
|
-
roles: (objects.map { |role| { id: role.id, required: true } } if type == :role),
|
59
|
-
groups: (objects.map { |group| { id: group.id, extendChildren: false } } if type == :group),
|
60
75
|
groupsClaim: (groups_claim if type == :group),
|
61
76
|
clients: (objects.map(&:id) if type == :client),
|
62
77
|
description: description
|
@@ -64,15 +79,14 @@ module Clonk
|
|
64
79
|
end
|
65
80
|
|
66
81
|
##
|
67
|
-
#
|
82
|
+
# Creates a policy in SSO. You should do this after defining a policy with define_policy.
|
68
83
|
# FIXME: move to connection class
|
69
84
|
|
70
|
-
def self.create(
|
71
|
-
|
72
|
-
|
73
|
-
Clonk.parsed_response(
|
85
|
+
def self.create(data)
|
86
|
+
realm_management_url = url_for(clients.find { |c| c.name == 'realm-management' })
|
87
|
+
parsed_response(
|
74
88
|
method: :post,
|
75
|
-
path: "#{realm_management_url}/authz/resource-server/policy/#{type}",
|
89
|
+
path: "#{realm_management_url}/authz/resource-server/policy/#{data['type']}",
|
76
90
|
data: data
|
77
91
|
)
|
78
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clonk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Fish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|