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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/Dockerfile +24 -0
  3. data/.github/workflows/ci.yml +80 -0
  4. data/.gitignore +9 -9
  5. data/.rspec +2 -2
  6. data/CHANGELOG.md +194 -183
  7. data/Dockerfile +12 -12
  8. data/Gemfile +3 -3
  9. data/Gemfile.lock +51 -49
  10. data/MIT-LICENSE +20 -20
  11. data/README.md +748 -482
  12. data/bin/console +9 -9
  13. data/keycloak-admin.gemspec +24 -24
  14. data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
  15. data/lib/keycloak-admin/client/client.rb +56 -56
  16. data/lib/keycloak-admin/client/client_authz_permission_client.rb +81 -0
  17. data/lib/keycloak-admin/client/client_authz_policy_client.rb +76 -0
  18. data/lib/keycloak-admin/client/client_authz_resource_client.rb +93 -0
  19. data/lib/keycloak-admin/client/client_authz_scope_client.rb +71 -0
  20. data/lib/keycloak-admin/client/client_client.rb +71 -71
  21. data/lib/keycloak-admin/client/client_role_client.rb +20 -20
  22. data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
  23. data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
  24. data/lib/keycloak-admin/client/group_client.rb +148 -131
  25. data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
  26. data/lib/keycloak-admin/client/realm_client.rb +122 -106
  27. data/lib/keycloak-admin/client/role_client.rb +59 -59
  28. data/lib/keycloak-admin/client/role_mapper_client.rb +47 -45
  29. data/lib/keycloak-admin/client/token_client.rb +29 -29
  30. data/lib/keycloak-admin/client/user_client.rb +266 -266
  31. data/lib/keycloak-admin/configuration.rb +52 -52
  32. data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
  33. data/lib/keycloak-admin/representation/camel_json.rb +12 -12
  34. data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +34 -0
  35. data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +15 -0
  36. data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +27 -0
  37. data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +26 -0
  38. data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +17 -0
  39. data/lib/keycloak-admin/representation/client_representation.rb +71 -71
  40. data/lib/keycloak-admin/representation/credential_representation.rb +38 -38
  41. data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
  42. data/lib/keycloak-admin/representation/group_representation.rb +21 -21
  43. data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
  44. data/lib/keycloak-admin/representation/identity_provider_representation.rb +67 -67
  45. data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
  46. data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
  47. data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
  48. data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
  49. data/lib/keycloak-admin/representation/representation.rb +23 -23
  50. data/lib/keycloak-admin/representation/role_representation.rb +19 -19
  51. data/lib/keycloak-admin/representation/session_representation.rb +22 -22
  52. data/lib/keycloak-admin/representation/token_representation.rb +39 -39
  53. data/lib/keycloak-admin/representation/user_representation.rb +47 -47
  54. data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
  55. data/lib/keycloak-admin/resource/group_resource.rb +11 -11
  56. data/lib/keycloak-admin/resource/user_resource.rb +7 -7
  57. data/lib/keycloak-admin/version.rb +3 -3
  58. data/lib/keycloak-admin.rb +84 -75
  59. data/spec/client/attack_detection_client_spec.rb +102 -102
  60. data/spec/client/client_authz_permission_client_spec.rb +170 -0
  61. data/spec/client/client_authz_policy_client_spec.rb +170 -0
  62. data/spec/client/client_authz_resource_client_spec.rb +150 -0
  63. data/spec/client/client_authz_scope_client_spec.rb +134 -0
  64. data/spec/client/client_client_spec.rb +133 -133
  65. data/spec/client/client_role_mappings_client_spec.rb +82 -82
  66. data/spec/client/client_spec.rb +28 -28
  67. data/spec/client/configurable_token_client_spec.rb +34 -34
  68. data/spec/client/group_client_spec.rb +328 -258
  69. data/spec/client/identity_provider_client_spec.rb +92 -92
  70. data/spec/client/realm_client_spec.rb +155 -155
  71. data/spec/client/role_client_spec.rb +79 -79
  72. data/spec/client/role_mapper_client_spec.rb +113 -68
  73. data/spec/client/token_client_spec.rb +68 -68
  74. data/spec/client/user_client_spec.rb +373 -373
  75. data/spec/configuration_spec.rb +113 -113
  76. data/spec/integration/client_authorization_spec.rb +93 -0
  77. data/spec/representation/attack_detection_representation_spec.rb +15 -15
  78. data/spec/representation/client_authz_permission_representation_spec.rb +52 -0
  79. data/spec/representation/client_authz_policy_representation_spec.rb +47 -0
  80. data/spec/representation/client_authz_resource_representation_spec.rb +33 -0
  81. data/spec/representation/client_authz_scope_representation_spec.rb +19 -0
  82. data/spec/representation/client_representation_spec.rb +119 -119
  83. data/spec/representation/group_representation_spec.rb +22 -22
  84. data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
  85. data/spec/representation/identity_provider_representation_spec.rb +113 -113
  86. data/spec/representation/impersonation_representation_spec.rb +163 -163
  87. data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
  88. data/spec/representation/role_representation_spec.rb +37 -37
  89. data/spec/representation/session_representation_spec.rb +15 -15
  90. data/spec/representation/user_representation_spec.rb +15 -15
  91. data/spec/resource/group_resource_spec.rb +14 -14
  92. data/spec/resource/user_resource_spec.rb +14 -14
  93. data/spec/spec_helper.rb +37 -37
  94. metadata +29 -9
@@ -1,43 +1,43 @@
1
- require "http-cookie"
2
-
3
- module KeycloakAdmin
4
- class ImpersonationRepresentation < Representation
5
- attr_accessor :set_cookie_strings,
6
- :set_cookies,
7
- :same_realm,
8
- :redirect,
9
- :domain
10
-
11
- def self.from_response(response, origin)
12
- body = JSON.parse(response.body)
13
- representation = new
14
- representation.set_cookie_strings = response.headers[:set_cookie]
15
- representation.set_cookies = representation.set_cookie_strings.map { |set_cookie| parse_set_cookie_string(set_cookie, origin) }
16
- representation.same_realm = body["sameRealm"]
17
- representation.redirect = body["redirect"]
18
- representation.domain = origin
19
- representation
20
- end
21
-
22
- def self.parse_set_cookie_string(set_cookie_string, origin)
23
- HTTP::Cookie.parse(set_cookie_string, origin).first
24
- end
25
-
26
- def cookies_to_rails_hash
27
- @set_cookies.map do |cookie|
28
- rails_cookie = {
29
- name: cookie.name,
30
- value: cookie.value,
31
- httponly: cookie.httponly,
32
- expires: cookie.expires,
33
- path: cookie.path,
34
- domain: cookie.domain
35
- }
36
-
37
- rails_cookie[:max_age] = cookie.max_age if cookie.max_age
38
- rails_cookie[:secure] = cookie.secure if cookie.secure
39
- rails_cookie
40
- end
41
- end
42
- end
43
- end
1
+ require "http-cookie"
2
+
3
+ module KeycloakAdmin
4
+ class ImpersonationRepresentation < Representation
5
+ attr_accessor :set_cookie_strings,
6
+ :set_cookies,
7
+ :same_realm,
8
+ :redirect,
9
+ :domain
10
+
11
+ def self.from_response(response, origin)
12
+ body = JSON.parse(response.body)
13
+ representation = new
14
+ representation.set_cookie_strings = response.headers[:set_cookie]
15
+ representation.set_cookies = representation.set_cookie_strings.map { |set_cookie| parse_set_cookie_string(set_cookie, origin) }
16
+ representation.same_realm = body["sameRealm"]
17
+ representation.redirect = body["redirect"]
18
+ representation.domain = origin
19
+ representation
20
+ end
21
+
22
+ def self.parse_set_cookie_string(set_cookie_string, origin)
23
+ HTTP::Cookie.parse(set_cookie_string, origin).first
24
+ end
25
+
26
+ def cookies_to_rails_hash
27
+ @set_cookies.map do |cookie|
28
+ rails_cookie = {
29
+ name: cookie.name,
30
+ value: cookie.value,
31
+ httponly: cookie.httponly,
32
+ expires: cookie.expires,
33
+ path: cookie.path,
34
+ domain: cookie.domain
35
+ }
36
+
37
+ rails_cookie[:max_age] = cookie.max_age if cookie.max_age
38
+ rails_cookie[:secure] = cookie.secure if cookie.secure
39
+ rails_cookie
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,19 +1,19 @@
1
- module KeycloakAdmin
2
- class ProtocolMapperRepresentation < Representation
3
- attr_accessor :config,
4
- :id,
5
- :name,
6
- :protocol,
7
- :protocolMapper
8
-
9
- def self.from_hash(hash)
10
- rep = new
11
- rep.id = hash["id"]
12
- rep.config = hash["config"]
13
- rep.name = hash["name"]
14
- rep.protocol = hash["protocol"]
15
- rep.protocolMapper = hash["protocolMapper"]
16
- rep
17
- end
18
- end
19
- end
1
+ module KeycloakAdmin
2
+ class ProtocolMapperRepresentation < Representation
3
+ attr_accessor :config,
4
+ :id,
5
+ :name,
6
+ :protocol,
7
+ :protocolMapper
8
+
9
+ def self.from_hash(hash)
10
+ rep = new
11
+ rep.id = hash["id"]
12
+ rep.config = hash["config"]
13
+ rep.name = hash["name"]
14
+ rep.protocol = hash["protocol"]
15
+ rep.protocolMapper = hash["protocolMapper"]
16
+ rep
17
+ end
18
+ end
19
+ end
@@ -1,14 +1,14 @@
1
- module KeycloakAdmin
2
- class RealmRepresentation < Representation
3
- attr_accessor :id,
4
- :realm
5
- # TODO: Add more attributes
6
-
7
- def self.from_hash(hash)
8
- realm = new
9
- realm.id = hash["id"]
10
- realm.realm = hash["realm"]
11
- realm
12
- end
13
- end
14
- end
1
+ module KeycloakAdmin
2
+ class RealmRepresentation < Representation
3
+ attr_accessor :id,
4
+ :realm
5
+ # TODO: Add more attributes
6
+
7
+ def self.from_hash(hash)
8
+ realm = new
9
+ realm.id = hash["id"]
10
+ realm.realm = hash["realm"]
11
+ realm
12
+ end
13
+ end
14
+ end
@@ -1,23 +1,23 @@
1
- require "json"
2
- require_relative "camel_json"
3
-
4
- class Representation
5
- include ::KeycloakAdmin::CamelJson
6
-
7
- def as_json(options=nil)
8
- Hash[instance_variables.map { |ivar| [ivar.to_s[1..-1], instance_variable_get(ivar)] }]
9
- end
10
-
11
- def to_json(options=nil)
12
- snaked_hash = as_json(options)
13
- snaked_hash.keys.reduce({}) do |camelized_hash, key|
14
- camelized_hash[camelize(key, false)] = snaked_hash[key]
15
- camelized_hash
16
- end.to_json(options)
17
- end
18
-
19
- def self.from_json(json)
20
- hash = JSON.parse(json)
21
- from_hash(hash)
22
- end
23
- end
1
+ require "json"
2
+ require_relative "camel_json"
3
+
4
+ class Representation
5
+ include ::KeycloakAdmin::CamelJson
6
+
7
+ def as_json(options=nil)
8
+ Hash[instance_variables.map { |ivar| [ivar.to_s[1..-1], instance_variable_get(ivar)] }]
9
+ end
10
+
11
+ def to_json(options=nil)
12
+ snaked_hash = as_json(options)
13
+ snaked_hash.keys.reduce({}) do |camelized_hash, key|
14
+ camelized_hash[camelize(key, false)] = snaked_hash[key]
15
+ camelized_hash
16
+ end.to_json(options)
17
+ end
18
+
19
+ def self.from_json(json)
20
+ hash = JSON.parse(json)
21
+ from_hash(hash)
22
+ end
23
+ end
@@ -1,19 +1,19 @@
1
- module KeycloakAdmin
2
- class RoleRepresentation < Representation
3
- attr_accessor :id,
4
- :name,
5
- :composite,
6
- :client_role,
7
- :container_id,
8
-
9
- def self.from_hash(hash)
10
- role = new
11
- role.id = hash["id"]
12
- role.name = hash["name"]
13
- role.composite = hash["composite"]
14
- role.client_role = hash["clientRole"]
15
- role.container_id = hash["containerId"]
16
- role
17
- end
18
- end
19
- end
1
+ module KeycloakAdmin
2
+ class RoleRepresentation < Representation
3
+ attr_accessor :id,
4
+ :name,
5
+ :composite,
6
+ :client_role,
7
+ :container_id,
8
+
9
+ def self.from_hash(hash)
10
+ role = new
11
+ role.id = hash["id"]
12
+ role.name = hash["name"]
13
+ role.composite = hash["composite"]
14
+ role.client_role = hash["clientRole"]
15
+ role.container_id = hash["containerId"]
16
+ role
17
+ end
18
+ end
19
+ end
@@ -1,23 +1,23 @@
1
- module KeycloakAdmin
2
- class SessionRepresentation < Representation
3
- attr_accessor :id,
4
- :username,
5
- :user_id,
6
- :ip_address,
7
- :start,
8
- :last_access,
9
- :remember_me,
10
-
11
- def self.from_hash(hash)
12
- rep = new
13
- rep.id = hash["id"]
14
- rep.username = hash["username"]
15
- rep.user_id = hash["userId"]
16
- rep.ip_address = hash["ipAddress"]
17
- rep.start = hash["start"]
18
- rep.last_access = hash["lastAccess"]
19
- rep.remember_me = hash["rememberMe"]
20
- rep
21
- end
22
- end
1
+ module KeycloakAdmin
2
+ class SessionRepresentation < Representation
3
+ attr_accessor :id,
4
+ :username,
5
+ :user_id,
6
+ :ip_address,
7
+ :start,
8
+ :last_access,
9
+ :remember_me,
10
+
11
+ def self.from_hash(hash)
12
+ rep = new
13
+ rep.id = hash["id"]
14
+ rep.username = hash["username"]
15
+ rep.user_id = hash["userId"]
16
+ rep.ip_address = hash["ipAddress"]
17
+ rep.start = hash["start"]
18
+ rep.last_access = hash["lastAccess"]
19
+ rep.remember_me = hash["rememberMe"]
20
+ rep
21
+ end
22
+ end
23
23
  end
@@ -1,39 +1,39 @@
1
-
2
- module KeycloakAdmin
3
- class TokenRepresentation < Representation
4
- attr_accessor :access_token,
5
- :token_type,
6
- :expires_in,
7
- :refresh_token,
8
- :refresh_expires_in,
9
- :id_token,
10
- :not_before_policy,
11
- :session_state
12
-
13
- def initialize(access_token, token_type, expires_in, refresh_token, refresh_expires_in, id_token, not_before_policy, session_state)
14
- @access_token = access_token
15
- @token_type = token_type
16
- @expires_in = expires_in
17
- @refresh_token = refresh_token
18
- @refresh_expires_in = refresh_expires_in
19
- @id_token = id_token
20
- @not_before_policy = not_before_policy
21
- @session_state = session_state
22
- end
23
-
24
- def self.from_hash(hash)
25
- new(
26
- hash["access_token"],
27
- hash["token_type"],
28
- hash["expires_in"],
29
- hash["refresh_token"],
30
- hash["refresh_expires_in"],
31
- hash["id_token"],
32
- hash["not-before-policy"],
33
- hash["session_state"],
34
- )
35
- end
36
- end
37
- end
38
-
39
-
1
+
2
+ module KeycloakAdmin
3
+ class TokenRepresentation < Representation
4
+ attr_accessor :access_token,
5
+ :token_type,
6
+ :expires_in,
7
+ :refresh_token,
8
+ :refresh_expires_in,
9
+ :id_token,
10
+ :not_before_policy,
11
+ :session_state
12
+
13
+ def initialize(access_token, token_type, expires_in, refresh_token, refresh_expires_in, id_token, not_before_policy, session_state)
14
+ @access_token = access_token
15
+ @token_type = token_type
16
+ @expires_in = expires_in
17
+ @refresh_token = refresh_token
18
+ @refresh_expires_in = refresh_expires_in
19
+ @id_token = id_token
20
+ @not_before_policy = not_before_policy
21
+ @session_state = session_state
22
+ end
23
+
24
+ def self.from_hash(hash)
25
+ new(
26
+ hash["access_token"],
27
+ hash["token_type"],
28
+ hash["expires_in"],
29
+ hash["refresh_token"],
30
+ hash["refresh_expires_in"],
31
+ hash["id_token"],
32
+ hash["not-before-policy"],
33
+ hash["session_state"],
34
+ )
35
+ end
36
+ end
37
+ end
38
+
39
+
@@ -1,47 +1,47 @@
1
- module KeycloakAdmin
2
- class UserRepresentation < Representation
3
- attr_accessor :id,
4
- :created_timestamp,
5
- :attributes,
6
- :origin,
7
- :username,
8
- :email,
9
- :enabled,
10
- :email_verified,
11
- :first_name,
12
- :last_name,
13
- :totp,
14
- :credentials,
15
- :federated_identities,
16
- :required_actions
17
-
18
- def self.from_hash(hash)
19
- user = new
20
- user.id = hash["id"]
21
- user.created_timestamp = hash["createdTimestamp"]
22
- user.origin = hash["origin"]
23
- user.username = hash["username"]
24
- user.email = hash["email"]
25
- user.enabled = hash["enabled"]
26
- user.email_verified = hash["emailVerified"]
27
- user.first_name = hash["firstName"]
28
- user.last_name = hash["lastName"]
29
- user.attributes = hash["attributes"]
30
- user.required_actions = hash["requiredActions"] || []
31
- user.totp = hash["totp"] || false
32
- user.credentials = hash["credentials"]&.map{ |hash| CredentialRepresentation.from_hash(hash) } || []
33
- user.federated_identities = hash["federatedIdentities"]&.map { |hash| FederatedIdentityRepresentation.from_hash(hash) } || []
34
- user
35
- end
36
-
37
- def add_credential(credential_representation)
38
- @credentials ||= []
39
- @credentials.push(credential_representation)
40
- end
41
-
42
- def add_federated_identity(federated_identity_representation)
43
- @federated_identities ||= []
44
- @federated_identities.push(federated_identity_representation)
45
- end
46
- end
47
- end
1
+ module KeycloakAdmin
2
+ class UserRepresentation < Representation
3
+ attr_accessor :id,
4
+ :created_timestamp,
5
+ :attributes,
6
+ :origin,
7
+ :username,
8
+ :email,
9
+ :enabled,
10
+ :email_verified,
11
+ :first_name,
12
+ :last_name,
13
+ :totp,
14
+ :credentials,
15
+ :federated_identities,
16
+ :required_actions
17
+
18
+ def self.from_hash(hash)
19
+ user = new
20
+ user.id = hash["id"]
21
+ user.created_timestamp = hash["createdTimestamp"]
22
+ user.origin = hash["origin"]
23
+ user.username = hash["username"]
24
+ user.email = hash["email"]
25
+ user.enabled = hash["enabled"]
26
+ user.email_verified = hash["emailVerified"]
27
+ user.first_name = hash["firstName"]
28
+ user.last_name = hash["lastName"]
29
+ user.attributes = hash["attributes"]
30
+ user.required_actions = hash["requiredActions"] || []
31
+ user.totp = hash["totp"] || false
32
+ user.credentials = hash["credentials"]&.map{ |hash| CredentialRepresentation.from_hash(hash) } || []
33
+ user.federated_identities = hash["federatedIdentities"]&.map { |hash| FederatedIdentityRepresentation.from_hash(hash) } || []
34
+ user
35
+ end
36
+
37
+ def add_credential(credential_representation)
38
+ @credentials ||= []
39
+ @credentials.push(credential_representation)
40
+ end
41
+
42
+ def add_federated_identity(federated_identity_representation)
43
+ @federated_identities ||= []
44
+ @federated_identities.push(federated_identity_representation)
45
+ end
46
+ end
47
+ end
@@ -1,28 +1,28 @@
1
- module KeycloakAdmin
2
- class BaseRoleContainingResource
3
- attr_reader :resource_id
4
-
5
- def initialize(configuration, realm_client, resource_id)
6
- @configuration = configuration
7
- raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
8
- @realm_client = realm_client
9
- @resource_id = resource_id
10
- end
11
-
12
- def resources_name
13
- raise NotImplementedError.new("must override in subclass")
14
- end
15
-
16
- def resource_url
17
- "#{@realm_client.realm_admin_url}/#{resources_name}/#{@resource_id}"
18
- end
19
-
20
- def client_role_mappings(client_id)
21
- ClientRoleMappingsClient.new(@configuration, self, client_id)
22
- end
23
-
24
- def role_mapper
25
- RoleMapperClient.new(@configuration, self)
26
- end
27
- end
28
- end
1
+ module KeycloakAdmin
2
+ class BaseRoleContainingResource
3
+ attr_reader :resource_id
4
+
5
+ def initialize(configuration, realm_client, resource_id)
6
+ @configuration = configuration
7
+ raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
8
+ @realm_client = realm_client
9
+ @resource_id = resource_id
10
+ end
11
+
12
+ def resources_name
13
+ raise NotImplementedError.new("must override in subclass")
14
+ end
15
+
16
+ def resource_url
17
+ "#{@realm_client.realm_admin_url}/#{resources_name}/#{@resource_id}"
18
+ end
19
+
20
+ def client_role_mappings(client_id)
21
+ ClientRoleMappingsClient.new(@configuration, self, client_id)
22
+ end
23
+
24
+ def role_mapper
25
+ RoleMapperClient.new(@configuration, self)
26
+ end
27
+ end
28
+ end
@@ -1,11 +1,11 @@
1
- module KeycloakAdmin
2
- class GroupResource < BaseRoleContainingResource
3
- def resources_name
4
- "groups"
5
- end
6
-
7
- def members(first:0, max:100)
8
- @realm_client.groups.members(@resource_id, first, max)
9
- end
10
- end
11
- end
1
+ module KeycloakAdmin
2
+ class GroupResource < BaseRoleContainingResource
3
+ def resources_name
4
+ "groups"
5
+ end
6
+
7
+ def members(first:0, max:100)
8
+ @realm_client.groups.members(@resource_id, first, max)
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
- module KeycloakAdmin
2
- class UserResource < BaseRoleContainingResource
3
- def resources_name
4
- "users"
5
- end
6
- end
7
- end
1
+ module KeycloakAdmin
2
+ class UserResource < BaseRoleContainingResource
3
+ def resources_name
4
+ "users"
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
- module KeycloakAdmin
2
- VERSION = "1.1.2"
3
- end
1
+ module KeycloakAdmin
2
+ VERSION = "1.1.4"
3
+ end