keycloak-admin 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +4 -8
- data/README.md +26 -0
- data/lib/keycloak-admin/client/group_client.rb +22 -0
- data/lib/keycloak-admin/client/role_client.rb +13 -0
- data/lib/keycloak-admin/representation/role_representation.rb +3 -1
- data/lib/keycloak-admin/version.rb +1 -1
- data/spec/representation/role_representation_spec.rb +2 -2
- 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: bf6847f9dc60316780255644c15320d06a998331df2283e30a007c4bea951ba1
|
4
|
+
data.tar.gz: 4af207ec29032148c58ff23194f4ade85aec556718bb4896c00ec29fe95000a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e03b3d8ae4f5eac52399fefcbea427d34a5afc5e08475365a8166faa5031eebb7b87cff23393e16e91e2df0f50263023b29262addff9550f79ef7bb5c739637
|
7
|
+
data.tar.gz: 1c91e21ee8d74ba5ca05f773d20acdc11e3a6c8fd8ab3e8098cb75c7d44ed1c7763e3954b094012a5fe9000c1ff4cb048355e7a3a1f134b8911fc349b03919d9
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [1.1.1] - 2024-01-21
|
9
|
+
|
10
|
+
* Add/List realm-role/s to a group, Allow role-names with spaces, List groups assigned to role (thanks to @LiquidMagical
|
11
|
+
)
|
12
|
+
|
8
13
|
## [1.1.0] - 2023-10-03
|
9
14
|
|
10
15
|
* Search for groups with parameters (thanks to @@tlloydthwaites)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
keycloak-admin (1.1.
|
4
|
+
keycloak-admin (1.1.1)
|
5
5
|
http-cookie (~> 1.0, >= 1.0.3)
|
6
6
|
rest-client (~> 2.0)
|
7
7
|
|
@@ -10,14 +10,13 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
byebug (11.1.3)
|
12
12
|
diff-lcs (1.5.0)
|
13
|
-
domain_name (0.
|
14
|
-
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
domain_name (0.6.20240107)
|
15
14
|
http-accept (1.7.0)
|
16
15
|
http-cookie (1.0.5)
|
17
16
|
domain_name (~> 0.5)
|
18
|
-
mime-types (3.5.
|
17
|
+
mime-types (3.5.2)
|
19
18
|
mime-types-data (~> 3.2015)
|
20
|
-
mime-types-data (3.2023.
|
19
|
+
mime-types-data (3.2023.1205)
|
21
20
|
netrc (0.11.0)
|
22
21
|
rest-client (2.1.0)
|
23
22
|
http-accept (>= 1.7.0, < 2.0)
|
@@ -37,9 +36,6 @@ GEM
|
|
37
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
37
|
rspec-support (~> 3.12.0)
|
39
38
|
rspec-support (3.12.1)
|
40
|
-
unf (0.1.4)
|
41
|
-
unf_ext
|
42
|
-
unf_ext (0.0.8.2)
|
43
39
|
|
44
40
|
PLATFORMS
|
45
41
|
ruby
|
data/README.md
CHANGED
@@ -120,6 +120,8 @@ All options have a default value. However, all of them can be changed in your in
|
|
120
120
|
* Get list of realms, save/update/delete a realm
|
121
121
|
* Get list of client role mappings for a user/group
|
122
122
|
* Get list of members of a group
|
123
|
+
* Get list of groups that have a specific role assigned
|
124
|
+
* Get list of realm-roles assigned to a group, add a realm-role to a group
|
123
125
|
* Save client role mappings for a user/group
|
124
126
|
* Save realm-level role mappings for a user/group
|
125
127
|
* Add a Group on a User
|
@@ -367,6 +369,30 @@ You can specify paging with `first` and `max`:
|
|
367
369
|
KeycloakAdmin.realm("a_realm").group("group_id").members(first:0, max:100)
|
368
370
|
```
|
369
371
|
|
372
|
+
### Get list of groups that have a specific role assigned
|
373
|
+
|
374
|
+
Returns an array of `KeycloakAdmin::GroupRepresentation`
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
KeycloakAdmin.realm("a_realm").roles.list_groups("role_name")
|
378
|
+
```
|
379
|
+
|
380
|
+
### Get list of realm-roles assigned to a group
|
381
|
+
|
382
|
+
Returns an array of `KeycloakAdmin::RoleRepresentation`
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
KeycloakAdmin.realm("a_realm").groups.get_realm_level_roles("group_id")
|
386
|
+
```
|
387
|
+
|
388
|
+
### Add a realm-role to a group
|
389
|
+
|
390
|
+
Returns added `KeycloakAdmin::RoleRepresentation`
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
KeycloakAdmin.realm("a_realm").groups.add_realm_level_role_name!("group_id", "role_name")
|
394
|
+
```
|
395
|
+
|
370
396
|
### Get list of roles in a realm
|
371
397
|
|
372
398
|
Returns an array of `KeycloakAdmin::RoleRepresentation`.
|
@@ -61,6 +61,28 @@ module KeycloakAdmin
|
|
61
61
|
JSON.parse(response).map { |user_as_hash| UserRepresentation.from_hash(user_as_hash) }
|
62
62
|
end
|
63
63
|
|
64
|
+
# Gets all realm-level roles for a group
|
65
|
+
def get_realm_level_roles(group_id)
|
66
|
+
url = "#{groups_url(group_id)}/role-mappings/realm"
|
67
|
+
response = execute_http do
|
68
|
+
RestClient::Resource.new(url, @configuration.rest_client_options).get(headers)
|
69
|
+
end
|
70
|
+
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
71
|
+
end
|
72
|
+
|
73
|
+
# Adds a realm-level role to a group via the role name
|
74
|
+
def add_realm_level_role_name!(group_id, role_name)
|
75
|
+
# creates a full role-representation object needed by the keycloak api to work
|
76
|
+
role_representation = RoleClient.new(@configuration, @realm_client).get(role_name)
|
77
|
+
url = "#{groups_url(group_id)}/role-mappings/realm"
|
78
|
+
response = execute_http do
|
79
|
+
RestClient::Resource.new(url, @configuration.rest_client_options).post(
|
80
|
+
create_payload([role_representation]), headers
|
81
|
+
)
|
82
|
+
end
|
83
|
+
role_representation
|
84
|
+
end
|
85
|
+
|
64
86
|
def groups_url(id=nil)
|
65
87
|
if id
|
66
88
|
"#{@realm_client.realm_admin_url}/groups/#{id}"
|
@@ -13,13 +13,26 @@ module KeycloakAdmin
|
|
13
13
|
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
|
14
14
|
end
|
15
15
|
|
16
|
+
# Returns the role representation for the specified role name
|
16
17
|
def get(name)
|
18
|
+
# allows special characters in the name like space
|
19
|
+
name = URI.encode_uri_component(name)
|
17
20
|
response = execute_http do
|
18
21
|
RestClient::Resource.new(role_name_url(name), @configuration.rest_client_options).get(headers)
|
19
22
|
end
|
20
23
|
RoleRepresentation.from_hash JSON.parse(response)
|
21
24
|
end
|
22
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
|
+
|
23
36
|
def save(role_representation)
|
24
37
|
execute_http do
|
25
38
|
RestClient::Resource.new(roles_url, @configuration.rest_client_options).post(
|
@@ -3,7 +3,8 @@ module KeycloakAdmin
|
|
3
3
|
attr_accessor :id,
|
4
4
|
:name,
|
5
5
|
:composite,
|
6
|
-
:client_role
|
6
|
+
:client_role,
|
7
|
+
:container_id,
|
7
8
|
|
8
9
|
def self.from_hash(hash)
|
9
10
|
role = new
|
@@ -11,6 +12,7 @@ module KeycloakAdmin
|
|
11
12
|
role.name = hash["name"]
|
12
13
|
role.composite = hash["composite"]
|
13
14
|
role.client_role = hash["clientRole"]
|
15
|
+
role.container_id = hash["containerId"]
|
14
16
|
role
|
15
17
|
end
|
16
18
|
end
|
@@ -12,7 +12,7 @@ RSpec.describe KeycloakAdmin::RoleRepresentation do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "can convert to json" do
|
15
|
-
expect(@mapper.to_json).to eq "{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false}"
|
15
|
+
expect(@mapper.to_json).to eq "{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false,\"containerId\":null}"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -31,7 +31,7 @@ RSpec.describe KeycloakAdmin::RoleRepresentation do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can convert to json" do
|
34
|
-
expect(@mappers.to_json).to eq "[{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false}]"
|
34
|
+
expect(@mappers.to_json).to eq "[{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false,\"containerId\":null}]"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorent Lempereur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http-cookie
|