keycloak-admin 1.1.2 → 1.1.4
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.
- checksums.yaml +4 -4
- data/.github/workflows/Dockerfile +24 -0
- data/.github/workflows/ci.yml +80 -0
- data/.gitignore +9 -9
- data/.rspec +2 -2
- data/CHANGELOG.md +194 -183
- data/Dockerfile +12 -12
- data/Gemfile +3 -3
- data/Gemfile.lock +51 -49
- data/MIT-LICENSE +20 -20
- data/README.md +748 -482
- data/bin/console +9 -9
- data/keycloak-admin.gemspec +24 -24
- data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
- data/lib/keycloak-admin/client/client.rb +56 -56
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +81 -0
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +76 -0
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +93 -0
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +71 -0
- data/lib/keycloak-admin/client/client_client.rb +71 -71
- data/lib/keycloak-admin/client/client_role_client.rb +20 -20
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
- data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
- data/lib/keycloak-admin/client/group_client.rb +148 -131
- data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
- data/lib/keycloak-admin/client/realm_client.rb +122 -106
- data/lib/keycloak-admin/client/role_client.rb +59 -59
- data/lib/keycloak-admin/client/role_mapper_client.rb +47 -45
- data/lib/keycloak-admin/client/token_client.rb +29 -29
- data/lib/keycloak-admin/client/user_client.rb +266 -266
- data/lib/keycloak-admin/configuration.rb +52 -52
- data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
- data/lib/keycloak-admin/representation/camel_json.rb +12 -12
- data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +34 -0
- data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +15 -0
- data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +27 -0
- data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +26 -0
- data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +17 -0
- data/lib/keycloak-admin/representation/client_representation.rb +71 -71
- data/lib/keycloak-admin/representation/credential_representation.rb +38 -38
- data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
- data/lib/keycloak-admin/representation/group_representation.rb +21 -21
- data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
- data/lib/keycloak-admin/representation/identity_provider_representation.rb +67 -67
- data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
- data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
- data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
- data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
- data/lib/keycloak-admin/representation/representation.rb +23 -23
- data/lib/keycloak-admin/representation/role_representation.rb +19 -19
- data/lib/keycloak-admin/representation/session_representation.rb +22 -22
- data/lib/keycloak-admin/representation/token_representation.rb +39 -39
- data/lib/keycloak-admin/representation/user_representation.rb +47 -47
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
- data/lib/keycloak-admin/resource/group_resource.rb +11 -11
- data/lib/keycloak-admin/resource/user_resource.rb +7 -7
- data/lib/keycloak-admin/version.rb +3 -3
- data/lib/keycloak-admin.rb +84 -75
- data/spec/client/attack_detection_client_spec.rb +102 -102
- data/spec/client/client_authz_permission_client_spec.rb +170 -0
- data/spec/client/client_authz_policy_client_spec.rb +170 -0
- data/spec/client/client_authz_resource_client_spec.rb +150 -0
- data/spec/client/client_authz_scope_client_spec.rb +134 -0
- data/spec/client/client_client_spec.rb +133 -133
- data/spec/client/client_role_mappings_client_spec.rb +82 -82
- data/spec/client/client_spec.rb +28 -28
- data/spec/client/configurable_token_client_spec.rb +34 -34
- data/spec/client/group_client_spec.rb +328 -258
- data/spec/client/identity_provider_client_spec.rb +92 -92
- data/spec/client/realm_client_spec.rb +155 -155
- data/spec/client/role_client_spec.rb +79 -79
- data/spec/client/role_mapper_client_spec.rb +113 -68
- data/spec/client/token_client_spec.rb +68 -68
- data/spec/client/user_client_spec.rb +373 -373
- data/spec/configuration_spec.rb +113 -113
- data/spec/integration/client_authorization_spec.rb +93 -0
- data/spec/representation/attack_detection_representation_spec.rb +15 -15
- data/spec/representation/client_authz_permission_representation_spec.rb +52 -0
- data/spec/representation/client_authz_policy_representation_spec.rb +47 -0
- data/spec/representation/client_authz_resource_representation_spec.rb +33 -0
- data/spec/representation/client_authz_scope_representation_spec.rb +19 -0
- data/spec/representation/client_representation_spec.rb +119 -119
- data/spec/representation/group_representation_spec.rb +22 -22
- data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
- data/spec/representation/identity_provider_representation_spec.rb +113 -113
- data/spec/representation/impersonation_representation_spec.rb +163 -163
- data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
- data/spec/representation/role_representation_spec.rb +37 -37
- data/spec/representation/session_representation_spec.rb +15 -15
- data/spec/representation/user_representation_spec.rb +15 -15
- data/spec/resource/group_resource_spec.rb +14 -14
- data/spec/resource/user_resource_spec.rb +14 -14
- data/spec/spec_helper.rb +37 -37
- metadata +29 -9
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class IdentityProviderClient < Client
|
|
3
|
-
def initialize(configuration, realm_client)
|
|
4
|
-
super(configuration)
|
|
5
|
-
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
6
|
-
@realm_client = realm_client
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def create(identity_provider_representation)
|
|
10
|
-
execute_http do
|
|
11
|
-
RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).post(
|
|
12
|
-
create_payload(identity_provider_representation), headers
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def add_mapping(identity_provider_alias, identity_provider_mapping_representation)
|
|
18
|
-
execute_http do
|
|
19
|
-
RestClient::Resource.new(identity_provider_mappers_url(identity_provider_alias), @configuration.rest_client_options).post(
|
|
20
|
-
create_payload(identity_provider_mapping_representation), headers
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def list
|
|
26
|
-
response = execute_http do
|
|
27
|
-
RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).get(headers)
|
|
28
|
-
end
|
|
29
|
-
JSON.parse(response).map { |provider_as_hash| IdentityProviderRepresentation.from_hash(provider_as_hash) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def get(internal_id_or_alias=nil)
|
|
33
|
-
response = execute_http do
|
|
34
|
-
RestClient::Resource.new(identity_providers_url(internal_id_or_alias), @configuration.rest_client_options).get(headers)
|
|
35
|
-
end
|
|
36
|
-
IdentityProviderRepresentation.from_hash(JSON.parse(response))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def identity_providers_url(internal_id_or_alias=nil)
|
|
40
|
-
if internal_id_or_alias
|
|
41
|
-
"#{@realm_client.realm_admin_url}/identity-provider/instances/#{internal_id_or_alias}"
|
|
42
|
-
else
|
|
43
|
-
"#{@realm_client.realm_admin_url}/identity-provider/instances"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def identity_provider_mappers_url(internal_id_or_alias)
|
|
48
|
-
"#{identity_providers_url(internal_id_or_alias)}/mappers"
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class IdentityProviderClient < Client
|
|
3
|
+
def initialize(configuration, realm_client)
|
|
4
|
+
super(configuration)
|
|
5
|
+
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
6
|
+
@realm_client = realm_client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create(identity_provider_representation)
|
|
10
|
+
execute_http do
|
|
11
|
+
RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).post(
|
|
12
|
+
create_payload(identity_provider_representation), headers
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_mapping(identity_provider_alias, identity_provider_mapping_representation)
|
|
18
|
+
execute_http do
|
|
19
|
+
RestClient::Resource.new(identity_provider_mappers_url(identity_provider_alias), @configuration.rest_client_options).post(
|
|
20
|
+
create_payload(identity_provider_mapping_representation), headers
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def list
|
|
26
|
+
response = execute_http do
|
|
27
|
+
RestClient::Resource.new(identity_providers_url, @configuration.rest_client_options).get(headers)
|
|
28
|
+
end
|
|
29
|
+
JSON.parse(response).map { |provider_as_hash| IdentityProviderRepresentation.from_hash(provider_as_hash) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get(internal_id_or_alias=nil)
|
|
33
|
+
response = execute_http do
|
|
34
|
+
RestClient::Resource.new(identity_providers_url(internal_id_or_alias), @configuration.rest_client_options).get(headers)
|
|
35
|
+
end
|
|
36
|
+
IdentityProviderRepresentation.from_hash(JSON.parse(response))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def identity_providers_url(internal_id_or_alias=nil)
|
|
40
|
+
if internal_id_or_alias
|
|
41
|
+
"#{@realm_client.realm_admin_url}/identity-provider/instances/#{internal_id_or_alias}"
|
|
42
|
+
else
|
|
43
|
+
"#{@realm_client.realm_admin_url}/identity-provider/instances"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def identity_provider_mappers_url(internal_id_or_alias)
|
|
48
|
+
"#{identity_providers_url(internal_id_or_alias)}/mappers"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -1,106 +1,122 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class RealmClient < Client
|
|
3
|
-
def initialize(configuration, realm_name=nil)
|
|
4
|
-
super(configuration)
|
|
5
|
-
@realm_name = realm_name
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def list
|
|
9
|
-
response = execute_http do
|
|
10
|
-
RestClient::Resource.new(realm_list_url, @configuration.rest_client_options).get(headers)
|
|
11
|
-
end
|
|
12
|
-
JSON.parse(response).map { |realm_as_hash| RealmRepresentation.from_hash(realm_as_hash) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def delete
|
|
16
|
-
execute_http do
|
|
17
|
-
RestClient::Resource.new(realm_admin_url, @configuration.rest_client_options).delete(headers)
|
|
18
|
-
end
|
|
19
|
-
true
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def save(realm_representation)
|
|
23
|
-
execute_http do
|
|
24
|
-
RestClient::Resource.new(realm_list_url, @configuration.rest_client_options).post(
|
|
25
|
-
create_payload(realm_representation), headers
|
|
26
|
-
)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def update(realm_representation_body)
|
|
31
|
-
execute_http do
|
|
32
|
-
RestClient::Resource.new(realm_admin_url, @configuration.rest_client_options).put(
|
|
33
|
-
create_payload(realm_representation_body), headers
|
|
34
|
-
)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def realm_url
|
|
39
|
-
if @realm_name
|
|
40
|
-
"#{server_url}/realms/#{@realm_name}"
|
|
41
|
-
else
|
|
42
|
-
"#{server_url}/realms"
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def realm_admin_url
|
|
47
|
-
if @realm_name
|
|
48
|
-
"#{server_url}/admin/realms/#{@realm_name}"
|
|
49
|
-
else
|
|
50
|
-
"#{server_url}/admin/realms"
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def realm_list_url
|
|
55
|
-
"#{server_url}/admin/realms"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def token
|
|
59
|
-
TokenClient.new(@configuration, self)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def configurable_token
|
|
63
|
-
ConfigurableTokenClient.new(@configuration, self)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def clients
|
|
67
|
-
ClientClient.new(@configuration, self)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def groups
|
|
71
|
-
GroupClient.new(@configuration, self)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def group(group_id)
|
|
75
|
-
GroupResource.new(@configuration, self, group_id)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def roles
|
|
79
|
-
RoleClient.new(@configuration, self)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def client_roles
|
|
83
|
-
ClientRoleClient.new(@configuration, self)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def users
|
|
87
|
-
UserClient.new(@configuration, self)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def attack_detections
|
|
91
|
-
AttackDetectionClient.new(@configuration, self)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def identity_providers
|
|
95
|
-
IdentityProviderClient.new(@configuration, self)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def user(user_id)
|
|
99
|
-
UserResource.new(@configuration, self, user_id)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def
|
|
103
|
-
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class RealmClient < Client
|
|
3
|
+
def initialize(configuration, realm_name=nil)
|
|
4
|
+
super(configuration)
|
|
5
|
+
@realm_name = realm_name
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def list
|
|
9
|
+
response = execute_http do
|
|
10
|
+
RestClient::Resource.new(realm_list_url, @configuration.rest_client_options).get(headers)
|
|
11
|
+
end
|
|
12
|
+
JSON.parse(response).map { |realm_as_hash| RealmRepresentation.from_hash(realm_as_hash) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def delete
|
|
16
|
+
execute_http do
|
|
17
|
+
RestClient::Resource.new(realm_admin_url, @configuration.rest_client_options).delete(headers)
|
|
18
|
+
end
|
|
19
|
+
true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def save(realm_representation)
|
|
23
|
+
execute_http do
|
|
24
|
+
RestClient::Resource.new(realm_list_url, @configuration.rest_client_options).post(
|
|
25
|
+
create_payload(realm_representation), headers
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def update(realm_representation_body)
|
|
31
|
+
execute_http do
|
|
32
|
+
RestClient::Resource.new(realm_admin_url, @configuration.rest_client_options).put(
|
|
33
|
+
create_payload(realm_representation_body), headers
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def realm_url
|
|
39
|
+
if @realm_name
|
|
40
|
+
"#{server_url}/realms/#{@realm_name}"
|
|
41
|
+
else
|
|
42
|
+
"#{server_url}/realms"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def realm_admin_url
|
|
47
|
+
if @realm_name
|
|
48
|
+
"#{server_url}/admin/realms/#{@realm_name}"
|
|
49
|
+
else
|
|
50
|
+
"#{server_url}/admin/realms"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def realm_list_url
|
|
55
|
+
"#{server_url}/admin/realms"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def token
|
|
59
|
+
TokenClient.new(@configuration, self)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def configurable_token
|
|
63
|
+
ConfigurableTokenClient.new(@configuration, self)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def clients
|
|
67
|
+
ClientClient.new(@configuration, self)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def groups
|
|
71
|
+
GroupClient.new(@configuration, self)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def group(group_id)
|
|
75
|
+
GroupResource.new(@configuration, self, group_id)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def roles
|
|
79
|
+
RoleClient.new(@configuration, self)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def client_roles
|
|
83
|
+
ClientRoleClient.new(@configuration, self)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def users
|
|
87
|
+
UserClient.new(@configuration, self)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def attack_detections
|
|
91
|
+
AttackDetectionClient.new(@configuration, self)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def identity_providers
|
|
95
|
+
IdentityProviderClient.new(@configuration, self)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def user(user_id)
|
|
99
|
+
UserResource.new(@configuration, self, user_id)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def authz_scopes(client_id, resource_id = nil)
|
|
103
|
+
ClientAuthzScopeClient.new(@configuration, self, client_id, resource_id)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def authz_resources(client_id)
|
|
107
|
+
ClientAuthzResourceClient.new(@configuration, self, client_id)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def authz_permissions(client_id, type, resource_id = nil)
|
|
111
|
+
ClientAuthzPermissionClient.new(@configuration, self, client_id, type, resource_id)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def authz_policies(client_id, type)
|
|
115
|
+
ClientAuthzPolicyClient.new(@configuration, self, client_id, type)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def name_defined?
|
|
119
|
+
!@realm_name.nil?
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class RoleClient < Client
|
|
3
|
-
def initialize(configuration, realm_client)
|
|
4
|
-
super(configuration)
|
|
5
|
-
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
6
|
-
@realm_client = realm_client
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def list
|
|
10
|
-
response = execute_http do
|
|
11
|
-
RestClient::Resource.new(roles_url, @configuration.rest_client_options).get(headers)
|
|
12
|
-
end
|
|
13
|
-
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Returns the role representation for the specified role name
|
|
17
|
-
def get(name)
|
|
18
|
-
# allows special characters in the name like space
|
|
19
|
-
name = URI.encode_uri_component(name)
|
|
20
|
-
response = execute_http do
|
|
21
|
-
RestClient::Resource.new(role_name_url(name), @configuration.rest_client_options).get(headers)
|
|
22
|
-
end
|
|
23
|
-
RoleRepresentation.from_hash JSON.parse(response)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Lists all groups that have the specified role name assigned
|
|
27
|
-
def list_groups(name)
|
|
28
|
-
# allows special characters in the name like space
|
|
29
|
-
name = URI.encode_uri_component(name)
|
|
30
|
-
response = execute_http do
|
|
31
|
-
RestClient::Resource.new("#{role_name_url(name)}/groups", @configuration.rest_client_options).get(headers)
|
|
32
|
-
end
|
|
33
|
-
JSON.parse(response).map { |role_as_hash| GroupRepresentation.from_hash(role_as_hash) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def save(role_representation)
|
|
37
|
-
execute_http do
|
|
38
|
-
payload = create_payload(role_representation)
|
|
39
|
-
if role_representation.id
|
|
40
|
-
RestClient::Resource.new(role_id_url(role_representation.id), @configuration.rest_client_options).put(payload, headers)
|
|
41
|
-
else
|
|
42
|
-
RestClient::Resource.new(roles_url, @configuration.rest_client_options).post(payload, headers)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def roles_url
|
|
48
|
-
"#{@realm_client.realm_admin_url}/roles"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def role_id_url(id)
|
|
52
|
-
"#{@realm_client.realm_admin_url}/roles-by-id/#{id}"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def role_name_url(name)
|
|
56
|
-
"#{@realm_client.realm_admin_url}/roles/#{name}"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class RoleClient < Client
|
|
3
|
+
def initialize(configuration, realm_client)
|
|
4
|
+
super(configuration)
|
|
5
|
+
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
6
|
+
@realm_client = realm_client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def list
|
|
10
|
+
response = execute_http do
|
|
11
|
+
RestClient::Resource.new(roles_url, @configuration.rest_client_options).get(headers)
|
|
12
|
+
end
|
|
13
|
+
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns the role representation for the specified role name
|
|
17
|
+
def get(name)
|
|
18
|
+
# allows special characters in the name like space
|
|
19
|
+
name = URI.encode_uri_component(name)
|
|
20
|
+
response = execute_http do
|
|
21
|
+
RestClient::Resource.new(role_name_url(name), @configuration.rest_client_options).get(headers)
|
|
22
|
+
end
|
|
23
|
+
RoleRepresentation.from_hash JSON.parse(response)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Lists all groups that have the specified role name assigned
|
|
27
|
+
def list_groups(name)
|
|
28
|
+
# allows special characters in the name like space
|
|
29
|
+
name = URI.encode_uri_component(name)
|
|
30
|
+
response = execute_http do
|
|
31
|
+
RestClient::Resource.new("#{role_name_url(name)}/groups", @configuration.rest_client_options).get(headers)
|
|
32
|
+
end
|
|
33
|
+
JSON.parse(response).map { |role_as_hash| GroupRepresentation.from_hash(role_as_hash) }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def save(role_representation)
|
|
37
|
+
execute_http do
|
|
38
|
+
payload = create_payload(role_representation)
|
|
39
|
+
if role_representation.id
|
|
40
|
+
RestClient::Resource.new(role_id_url(role_representation.id), @configuration.rest_client_options).put(payload, headers)
|
|
41
|
+
else
|
|
42
|
+
RestClient::Resource.new(roles_url, @configuration.rest_client_options).post(payload, headers)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def roles_url
|
|
48
|
+
"#{@realm_client.realm_admin_url}/roles"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def role_id_url(id)
|
|
52
|
+
"#{@realm_client.realm_admin_url}/roles-by-id/#{id}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def role_name_url(name)
|
|
56
|
+
"#{@realm_client.realm_admin_url}/roles/#{name}"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class RoleMapperClient < Client
|
|
3
|
-
def initialize(configuration, user_resource)
|
|
4
|
-
super(configuration)
|
|
5
|
-
@user_resource = user_resource
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def list
|
|
9
|
-
response = execute_http do
|
|
10
|
-
RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).get(headers)
|
|
11
|
-
end
|
|
12
|
-
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def save_realm_level(role_representation_list)
|
|
16
|
-
execute_http do
|
|
17
|
-
RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).post(
|
|
18
|
-
create_payload(role_representation_list), headers
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def remove_realm_level(role_representation_list)
|
|
24
|
-
execute_http do
|
|
25
|
-
RestClient::Request.execute(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class RoleMapperClient < Client
|
|
3
|
+
def initialize(configuration, user_resource)
|
|
4
|
+
super(configuration)
|
|
5
|
+
@user_resource = user_resource
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def list
|
|
9
|
+
response = execute_http do
|
|
10
|
+
RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).get(headers)
|
|
11
|
+
end
|
|
12
|
+
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def save_realm_level(role_representation_list)
|
|
16
|
+
execute_http do
|
|
17
|
+
RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).post(
|
|
18
|
+
create_payload(role_representation_list), headers
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def remove_realm_level(role_representation_list)
|
|
24
|
+
execute_http do
|
|
25
|
+
RestClient::Request.execute(
|
|
26
|
+
@configuration.rest_client_options.merge(
|
|
27
|
+
method: :delete,
|
|
28
|
+
url: realm_level_url,
|
|
29
|
+
payload: create_payload(role_representation_list),
|
|
30
|
+
headers: headers
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def remove_all_realm_roles
|
|
37
|
+
execute_http do
|
|
38
|
+
RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).delete(headers)
|
|
39
|
+
end
|
|
40
|
+
true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def realm_level_url
|
|
44
|
+
"#{@user_resource.resource_url}/role-mappings/realm"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
require "rest-client"
|
|
2
|
-
|
|
3
|
-
module KeycloakAdmin
|
|
4
|
-
class TokenClient < Client
|
|
5
|
-
def initialize(configuration, realm_client)
|
|
6
|
-
super(configuration)
|
|
7
|
-
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
8
|
-
@realm_client = realm_client
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def token_url
|
|
12
|
-
"#{realm_url}/protocol/openid-connect/token"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def realm_url
|
|
16
|
-
@realm_client.realm_url
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def get
|
|
20
|
-
response = execute_http do
|
|
21
|
-
RestClient::Resource.new(token_url, @configuration.rest_client_options).post(
|
|
22
|
-
@configuration.body_for_token_retrieval,
|
|
23
|
-
@configuration.headers_for_token_retrieval
|
|
24
|
-
)
|
|
25
|
-
end
|
|
26
|
-
TokenRepresentation.from_json(response.body)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
1
|
+
require "rest-client"
|
|
2
|
+
|
|
3
|
+
module KeycloakAdmin
|
|
4
|
+
class TokenClient < Client
|
|
5
|
+
def initialize(configuration, realm_client)
|
|
6
|
+
super(configuration)
|
|
7
|
+
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
8
|
+
@realm_client = realm_client
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def token_url
|
|
12
|
+
"#{realm_url}/protocol/openid-connect/token"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def realm_url
|
|
16
|
+
@realm_client.realm_url
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get
|
|
20
|
+
response = execute_http do
|
|
21
|
+
RestClient::Resource.new(token_url, @configuration.rest_client_options).post(
|
|
22
|
+
@configuration.body_for_token_retrieval,
|
|
23
|
+
@configuration.headers_for_token_retrieval
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
TokenRepresentation.from_json(response.body)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|