keycloak-admin 1.1.4 → 1.1.5

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/Dockerfile +24 -24
  3. data/.github/workflows/ci.yml +80 -80
  4. data/.gitignore +9 -9
  5. data/.rspec +2 -2
  6. data/CHANGELOG.md +6 -0
  7. data/Dockerfile +12 -12
  8. data/Gemfile +3 -3
  9. data/Gemfile.lock +1 -1
  10. data/MIT-LICENSE +20 -20
  11. data/README.md +9 -1
  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 +80 -80
  17. data/lib/keycloak-admin/client/client_authz_policy_client.rb +75 -75
  18. data/lib/keycloak-admin/client/client_authz_resource_client.rb +92 -92
  19. data/lib/keycloak-admin/client/client_authz_scope_client.rb +70 -70
  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 -148
  25. data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
  26. data/lib/keycloak-admin/client/realm_client.rb +122 -122
  27. data/lib/keycloak-admin/client/role_client.rb +59 -59
  28. data/lib/keycloak-admin/client/role_mapper_client.rb +47 -47
  29. data/lib/keycloak-admin/client/token_client.rb +29 -29
  30. data/lib/keycloak-admin/client/user_client.rb +278 -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 +33 -33
  35. data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +14 -14
  36. data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +26 -26
  37. data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +25 -25
  38. data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +16 -16
  39. data/lib/keycloak-admin/representation/client_representation.rb +71 -71
  40. data/lib/keycloak-admin/representation/credential_representation.rb +71 -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 -84
  59. data/spec/client/attack_detection_client_spec.rb +102 -102
  60. data/spec/client/client_authz_permission_client_spec.rb +170 -170
  61. data/spec/client/client_authz_policy_client_spec.rb +169 -169
  62. data/spec/client/client_authz_resource_client_spec.rb +150 -150
  63. data/spec/client/client_authz_scope_client_spec.rb +133 -133
  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 -328
  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 -113
  73. data/spec/client/token_client_spec.rb +68 -68
  74. data/spec/client/user_client_spec.rb +418 -373
  75. data/spec/configuration_spec.rb +113 -113
  76. data/spec/integration/client_authorization_spec.rb +93 -93
  77. data/spec/representation/attack_detection_representation_spec.rb +15 -15
  78. data/spec/representation/client_authz_permission_representation_spec.rb +52 -52
  79. data/spec/representation/client_authz_policy_representation_spec.rb +46 -46
  80. data/spec/representation/client_authz_resource_representation_spec.rb +33 -33
  81. data/spec/representation/client_authz_scope_representation_spec.rb +18 -18
  82. data/spec/representation/client_representation_spec.rb +119 -119
  83. data/spec/representation/credential_representation_spec.rb +68 -0
  84. data/spec/representation/group_representation_spec.rb +22 -22
  85. data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
  86. data/spec/representation/identity_provider_representation_spec.rb +113 -113
  87. data/spec/representation/impersonation_representation_spec.rb +163 -163
  88. data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
  89. data/spec/representation/role_representation_spec.rb +37 -37
  90. data/spec/representation/session_representation_spec.rb +15 -15
  91. data/spec/representation/user_representation_spec.rb +15 -15
  92. data/spec/resource/group_resource_spec.rb +14 -14
  93. data/spec/resource/user_resource_spec.rb +14 -14
  94. data/spec/spec_helper.rb +37 -37
  95. metadata +7 -6
@@ -1,17 +1,17 @@
1
- module KeycloakAdmin
2
- class AttackDetectionRepresentation < Representation
3
- attr_accessor :num_failures,
4
- :disabled,
5
- :last_ip_failure,
6
- :last_failure
7
-
8
- def self.from_hash(hash)
9
- rep = new
10
- rep.num_failures = hash["numFailures"]
11
- rep.disabled = hash["disabled"]
12
- rep.last_ip_failure = hash["lastIPFailure"]
13
- rep.last_failure = hash["lastFailure"]
14
- rep
15
- end
16
- end
17
- end
1
+ module KeycloakAdmin
2
+ class AttackDetectionRepresentation < Representation
3
+ attr_accessor :num_failures,
4
+ :disabled,
5
+ :last_ip_failure,
6
+ :last_failure
7
+
8
+ def self.from_hash(hash)
9
+ rep = new
10
+ rep.num_failures = hash["numFailures"]
11
+ rep.disabled = hash["disabled"]
12
+ rep.last_ip_failure = hash["lastIPFailure"]
13
+ rep.last_failure = hash["lastFailure"]
14
+ rep
15
+ end
16
+ end
17
+ end
@@ -1,12 +1,12 @@
1
- module KeycloakAdmin
2
- module CamelJson
3
-
4
- def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
5
- if first_letter_in_uppercase
6
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
7
- else
8
- lower_case_and_underscored_word[0] + camelize(lower_case_and_underscored_word)[1..-1]
9
- end
10
- end
11
- end
12
- end
1
+ module KeycloakAdmin
2
+ module CamelJson
3
+
4
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
5
+ if first_letter_in_uppercase
6
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
7
+ else
8
+ lower_case_and_underscored_word[0] + camelize(lower_case_and_underscored_word)[1..-1]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,34 +1,34 @@
1
- # frozen_string_literal: true
2
-
3
-
4
- ## ### {"resources":["4f55e984-d1ec-405c-a25c-1387f88acd5c"],"policies":["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"],"name":"delme policy","description":"delme polidy ","decisionStrategy":"UNANIMOUS","resourceType":""}
5
- #
6
- module KeycloakAdmin
7
- class ClientAuthzPermissionRepresentation < Representation
8
- attr_accessor :id,
9
- :name,
10
- :description,
11
- :decision_strategy,
12
- :resource_type,
13
- :resources,
14
- :policies,
15
- :scopes,
16
- :logic,
17
- :type
18
-
19
- def self.from_hash(hash)
20
- resource = new
21
- resource.id = hash["id"]
22
- resource.name = hash["name"]
23
- resource.description = hash["description"]
24
- resource.decision_strategy = hash["decisionStrategy"]
25
- resource.resource_type = hash["resourceType"]
26
- resource.resources = hash["resources"]
27
- resource.policies = hash["policies"]
28
- resource.scopes = hash["scopes"]
29
- resource.logic = hash["logic"]
30
- resource.type = hash["type"]
31
- resource
32
- end
33
- end
1
+ # frozen_string_literal: true
2
+
3
+
4
+ ## ### {"resources":["4f55e984-d1ec-405c-a25c-1387f88acd5c"],"policies":["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"],"name":"delme policy","description":"delme polidy ","decisionStrategy":"UNANIMOUS","resourceType":""}
5
+ #
6
+ module KeycloakAdmin
7
+ class ClientAuthzPermissionRepresentation < Representation
8
+ attr_accessor :id,
9
+ :name,
10
+ :description,
11
+ :decision_strategy,
12
+ :resource_type,
13
+ :resources,
14
+ :policies,
15
+ :scopes,
16
+ :logic,
17
+ :type
18
+
19
+ def self.from_hash(hash)
20
+ resource = new
21
+ resource.id = hash["id"]
22
+ resource.name = hash["name"]
23
+ resource.description = hash["description"]
24
+ resource.decision_strategy = hash["decisionStrategy"]
25
+ resource.resource_type = hash["resourceType"]
26
+ resource.resources = hash["resources"]
27
+ resource.policies = hash["policies"]
28
+ resource.scopes = hash["scopes"]
29
+ resource.logic = hash["logic"]
30
+ resource.type = hash["type"]
31
+ resource
32
+ end
33
+ end
34
34
  end
@@ -1,15 +1,15 @@
1
- module KeycloakAdmin
2
- class ClientAuthzPolicyConfigRepresentation < Representation
3
- attr_accessor :roles,
4
- :code
5
-
6
- def self.from_hash(hash)
7
- resource = new
8
- resource.code = hash["code"]
9
- resource.roles = JSON.parse(hash["roles"] || '[]').map do |str|
10
- RoleRepresentation.from_hash(str)
11
- end
12
- resource
13
- end
14
- end
1
+ module KeycloakAdmin
2
+ class ClientAuthzPolicyConfigRepresentation < Representation
3
+ attr_accessor :roles,
4
+ :code
5
+
6
+ def self.from_hash(hash)
7
+ resource = new
8
+ resource.code = hash["code"]
9
+ resource.roles = JSON.parse(hash["roles"] || '[]').map do |str|
10
+ RoleRepresentation.from_hash(str)
11
+ end
12
+ resource
13
+ end
14
+ end
15
15
  end
@@ -1,27 +1,27 @@
1
- module KeycloakAdmin
2
- class ClientAuthzPolicyRepresentation < Representation
3
- attr_accessor :id,
4
- :name,
5
- :description,
6
- :type,
7
- :logic,
8
- :decision_strategy,
9
- :config,
10
- :fetch_roles,
11
- :roles
12
-
13
- def self.from_hash(hash)
14
- resource = new
15
- resource.id = hash["id"]
16
- resource.name = hash["name"]
17
- resource.description = hash["description"]
18
- resource.type = hash["type"]
19
- resource.logic = hash["logic"]
20
- resource.decision_strategy = hash["decisionStrategy"]
21
- resource.roles = hash["roles"]
22
- resource.fetch_roles = hash["fetchRoles"]
23
- resource.config = ClientAuthzPolicyConfigRepresentation.from_hash((hash["config"] || {}))
24
- resource
25
- end
26
- end
1
+ module KeycloakAdmin
2
+ class ClientAuthzPolicyRepresentation < Representation
3
+ attr_accessor :id,
4
+ :name,
5
+ :description,
6
+ :type,
7
+ :logic,
8
+ :decision_strategy,
9
+ :config,
10
+ :fetch_roles,
11
+ :roles
12
+
13
+ def self.from_hash(hash)
14
+ resource = new
15
+ resource.id = hash["id"]
16
+ resource.name = hash["name"]
17
+ resource.description = hash["description"]
18
+ resource.type = hash["type"]
19
+ resource.logic = hash["logic"]
20
+ resource.decision_strategy = hash["decisionStrategy"]
21
+ resource.roles = hash["roles"]
22
+ resource.fetch_roles = hash["fetchRoles"]
23
+ resource.config = ClientAuthzPolicyConfigRepresentation.from_hash((hash["config"] || {}))
24
+ resource
25
+ end
26
+ end
27
27
  end
@@ -1,26 +1,26 @@
1
- module KeycloakAdmin
2
-
3
- class ClientAuthzResourceRepresentation < Representation
4
- attr_accessor :id,
5
- :name,
6
- :type,
7
- :uris,
8
- :owner_managed_access,
9
- :display_name,
10
- :attributes,
11
- :scopes
12
-
13
- def self.from_hash(hash)
14
- resource = new
15
- resource.id = hash["_id"]
16
- resource.type = hash["type"]
17
- resource.name = hash["name"]
18
- resource.owner_managed_access = hash["ownerManagedAccess"]
19
- resource.uris = hash["uris"]
20
- resource.display_name = hash["displayName"]
21
- resource.attributes = hash.fetch("attributes", {}).map { |k, v| [k.to_sym, Array(v)] }.to_h
22
- resource.scopes = (hash["scopes"] || []).map { |scope_hash| ClientAuthzScopeRepresentation.from_hash(scope_hash) }
23
- resource
24
- end
25
- end
1
+ module KeycloakAdmin
2
+
3
+ class ClientAuthzResourceRepresentation < Representation
4
+ attr_accessor :id,
5
+ :name,
6
+ :type,
7
+ :uris,
8
+ :owner_managed_access,
9
+ :display_name,
10
+ :attributes,
11
+ :scopes
12
+
13
+ def self.from_hash(hash)
14
+ resource = new
15
+ resource.id = hash["_id"]
16
+ resource.type = hash["type"]
17
+ resource.name = hash["name"]
18
+ resource.owner_managed_access = hash["ownerManagedAccess"]
19
+ resource.uris = hash["uris"]
20
+ resource.display_name = hash["displayName"]
21
+ resource.attributes = hash.fetch("attributes", {}).map { |k, v| [k.to_sym, Array(v)] }.to_h
22
+ resource.scopes = (hash["scopes"] || []).map { |scope_hash| ClientAuthzScopeRepresentation.from_hash(scope_hash) }
23
+ resource
24
+ end
25
+ end
26
26
  end
@@ -1,17 +1,17 @@
1
- module KeycloakAdmin
2
- class ClientAuthzScopeRepresentation < Representation
3
- attr_accessor :id,
4
- :name,
5
- :icon_uri,
6
- :display_name
7
-
8
- def self.from_hash(hash)
9
- scope = new
10
- scope.id = hash["id"]
11
- scope.name = hash["name"]
12
- scope.icon_uri = hash["iconUri"]
13
- scope.display_name = hash["displayName"]
14
- scope
15
- end
16
- end
1
+ module KeycloakAdmin
2
+ class ClientAuthzScopeRepresentation < Representation
3
+ attr_accessor :id,
4
+ :name,
5
+ :icon_uri,
6
+ :display_name
7
+
8
+ def self.from_hash(hash)
9
+ scope = new
10
+ scope.id = hash["id"]
11
+ scope.name = hash["name"]
12
+ scope.icon_uri = hash["iconUri"]
13
+ scope.display_name = hash["displayName"]
14
+ scope
15
+ end
16
+ end
17
17
  end
@@ -1,71 +1,71 @@
1
- module KeycloakAdmin
2
- class ClientRepresentation < Representation
3
- attr_accessor :id,
4
- :name,
5
- :client_id,
6
- :description,
7
- :client_authenticator_type,
8
- :always_display_in_console,
9
- :surrogate_auth_required,
10
- :redirect_uris,
11
- :web_origins,
12
- :not_before,
13
- :bearer_only,
14
- :consent_required,
15
- :standard_flow_enabled,
16
- :implicit_flow_enabled,
17
- :direct_access_grants_enabled,
18
- :service_accounts_enabled,
19
- :authorization_services_enabled,
20
- :public_client,
21
- :frontchannel_logout,
22
- :protocol,
23
- :base_url,
24
- :root_url,
25
- :attributes,
26
- :authentication_flow_binding_overrides,
27
- :full_scope_allowed,
28
- :node_re_registration_timeout,
29
- :attributes,
30
- :protocol_mappers,
31
- :default_client_scopes,
32
- :optional_client_scopes,
33
- :access
34
-
35
- def self.from_hash(hash)
36
- client = new
37
- client.id = hash["id"]
38
- client.name = hash["name"]
39
- client.client_id = hash["clientId"]
40
- client.description = hash["description"]
41
- client.client_authenticator_type = hash["clientAuthenticatorType"]
42
- client.always_display_in_console = hash["alwaysDisplayInConsole"] || false
43
- client.surrogate_auth_required = hash["surrogateAuthRequired"] || false
44
- client.redirect_uris = hash["redirectUris"] || false
45
- client.web_origins = hash["webOrigins"] || false
46
- client.not_before = hash["notBefore"] || false
47
- client.bearer_only = hash["bearerOnly"] || false
48
- client.consent_required = hash["consentRequired"] || false
49
- client.standard_flow_enabled = hash["standardFlowEnabled"] || false
50
- client.implicit_flow_enabled = hash["implicitFlowEnabled"] || false
51
- client.direct_access_grants_enabled = hash["directAccessGrantsEnabled"] || false
52
- client.service_accounts_enabled = hash["serviceAccountsEnabled"] || false
53
- client.authorization_services_enabled = hash["authorizationServicesEnabled"] || false
54
- client.public_client = hash["publicClient"] || false
55
- client.frontchannel_logout = hash["frontchannelLogout"] || false
56
- client.protocol = hash["protocol"]
57
- client.base_url = hash["baseUrl"]
58
- client.root_url = hash["rootUrl"]
59
- client.attributes = hash["attributes"] || {}
60
- client.authentication_flow_binding_overrides = hash["authenticationFlowBindingOverrides"] || {}
61
- client.full_scope_allowed = hash["fullScopeAllowed"] || false
62
- client.node_re_registration_timeout = hash["nodeReRegistrationTimeout"] || -1
63
- client.attributes = hash["attributes"]
64
- client.protocol_mappers = (hash["protocolMappers"] || []).map { |protocol_mapper_hash| ProtocolMapperRepresentation.from_hash(protocol_mapper_hash) }
65
- client.default_client_scopes = hash["defaultClientScopes"] || []
66
- client.optional_client_scopes = hash["optionalClientScopes"] || []
67
- client.access = hash["access"] || {}
68
- client
69
- end
70
- end
71
- end
1
+ module KeycloakAdmin
2
+ class ClientRepresentation < Representation
3
+ attr_accessor :id,
4
+ :name,
5
+ :client_id,
6
+ :description,
7
+ :client_authenticator_type,
8
+ :always_display_in_console,
9
+ :surrogate_auth_required,
10
+ :redirect_uris,
11
+ :web_origins,
12
+ :not_before,
13
+ :bearer_only,
14
+ :consent_required,
15
+ :standard_flow_enabled,
16
+ :implicit_flow_enabled,
17
+ :direct_access_grants_enabled,
18
+ :service_accounts_enabled,
19
+ :authorization_services_enabled,
20
+ :public_client,
21
+ :frontchannel_logout,
22
+ :protocol,
23
+ :base_url,
24
+ :root_url,
25
+ :attributes,
26
+ :authentication_flow_binding_overrides,
27
+ :full_scope_allowed,
28
+ :node_re_registration_timeout,
29
+ :attributes,
30
+ :protocol_mappers,
31
+ :default_client_scopes,
32
+ :optional_client_scopes,
33
+ :access
34
+
35
+ def self.from_hash(hash)
36
+ client = new
37
+ client.id = hash["id"]
38
+ client.name = hash["name"]
39
+ client.client_id = hash["clientId"]
40
+ client.description = hash["description"]
41
+ client.client_authenticator_type = hash["clientAuthenticatorType"]
42
+ client.always_display_in_console = hash["alwaysDisplayInConsole"] || false
43
+ client.surrogate_auth_required = hash["surrogateAuthRequired"] || false
44
+ client.redirect_uris = hash["redirectUris"] || false
45
+ client.web_origins = hash["webOrigins"] || false
46
+ client.not_before = hash["notBefore"] || false
47
+ client.bearer_only = hash["bearerOnly"] || false
48
+ client.consent_required = hash["consentRequired"] || false
49
+ client.standard_flow_enabled = hash["standardFlowEnabled"] || false
50
+ client.implicit_flow_enabled = hash["implicitFlowEnabled"] || false
51
+ client.direct_access_grants_enabled = hash["directAccessGrantsEnabled"] || false
52
+ client.service_accounts_enabled = hash["serviceAccountsEnabled"] || false
53
+ client.authorization_services_enabled = hash["authorizationServicesEnabled"] || false
54
+ client.public_client = hash["publicClient"] || false
55
+ client.frontchannel_logout = hash["frontchannelLogout"] || false
56
+ client.protocol = hash["protocol"]
57
+ client.base_url = hash["baseUrl"]
58
+ client.root_url = hash["rootUrl"]
59
+ client.attributes = hash["attributes"] || {}
60
+ client.authentication_flow_binding_overrides = hash["authenticationFlowBindingOverrides"] || {}
61
+ client.full_scope_allowed = hash["fullScopeAllowed"] || false
62
+ client.node_re_registration_timeout = hash["nodeReRegistrationTimeout"] || -1
63
+ client.attributes = hash["attributes"]
64
+ client.protocol_mappers = (hash["protocolMappers"] || []).map { |protocol_mapper_hash| ProtocolMapperRepresentation.from_hash(protocol_mapper_hash) }
65
+ client.default_client_scopes = hash["defaultClientScopes"] || []
66
+ client.optional_client_scopes = hash["optionalClientScopes"] || []
67
+ client.access = hash["access"] || {}
68
+ client
69
+ end
70
+ end
71
+ end
@@ -1,39 +1,72 @@
1
- module KeycloakAdmin
2
- class CredentialRepresentation < Representation
3
- attr_accessor :type,
4
- :device,
5
- :value,
6
- :hashedSaltedValue,
7
- :salt,
8
- :hashIterations,
9
- :counter,
10
- :algorithm,
11
- :digits,
12
- :period,
13
- :created_date,
14
- :config,
15
- :temporary
16
-
17
- def self.from_password(password, temporary=false)
18
- credential = new
19
- credential.value = password
20
- credential.type = "password"
21
- credential.temporary = temporary
22
- credential
23
- end
24
-
25
- def self.from_json(json)
26
- attributes = JSON.parse(json)
27
- from_hash(attributes)
28
- end
29
-
30
- def self.from_hash(hash)
31
- credential = new
32
- hash.each do |key, value|
33
- property = "@#{key}".to_sym
34
- credential.instance_variable_set(property, value)
35
- end
36
- credential
37
- end
38
- end
1
+ module KeycloakAdmin
2
+ class CredentialRepresentation < Representation
3
+ attr_accessor :id,
4
+ :type,
5
+ :userLabel,
6
+ :device,
7
+ :value,
8
+ :hashedSaltedValue,
9
+ :salt,
10
+ :hashIterations,
11
+ :counter,
12
+ :algorithm,
13
+ :digits,
14
+ :period,
15
+ :createdDate,
16
+ :credentialData,
17
+ :secretData,
18
+ :config,
19
+ :temporary
20
+
21
+ def self.from_password(password, temporary=false)
22
+ credential = new
23
+ credential.value = password
24
+ credential.type = "password"
25
+ credential.temporary = temporary
26
+ credential
27
+ end
28
+
29
+ def self.from_json(json)
30
+ attributes = JSON.parse(json)
31
+ from_hash(attributes)
32
+ end
33
+
34
+ def self.from_hash(hash)
35
+ credential = new
36
+ hash.each do |key, value|
37
+ if credential.respond_to?("#{key}=")
38
+ credential.public_send("#{key}=", value)
39
+ end
40
+ end
41
+
42
+ nested_attributes = safely_parse_nested_json(hash["credentialData"]).merge(safely_parse_nested_json(hash["secretData"]))
43
+
44
+ nested_attributes.each do |key, value|
45
+ if credential.respond_to?("#{key}=")
46
+ current_value = credential.public_send(key)
47
+ if current_value.nil?
48
+ credential.public_send("#{key}=", value)
49
+ end
50
+ end
51
+ end
52
+
53
+ credential
54
+ end
55
+
56
+ class << self
57
+ private
58
+
59
+ def safely_parse_nested_json(json_string)
60
+ if json_string.nil? || json_string.strip.empty?
61
+ {}
62
+ else
63
+ begin
64
+ JSON.parse(json_string)
65
+ rescue JSON::ParserError
66
+ {}
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
39
72
  end
@@ -1,15 +1,15 @@
1
- module KeycloakAdmin
2
- class FederatedIdentityRepresentation < Representation
3
- attr_accessor :identity_provider,
4
- :user_id,
5
- :user_name
6
-
7
- def self.from_hash(hash)
8
- rep = new
9
- rep.identity_provider = hash["identityProvider"]
10
- rep.user_id = hash["userId"]
11
- rep.user_name = hash["userName"]
12
- rep
13
- end
14
- end
15
- end
1
+ module KeycloakAdmin
2
+ class FederatedIdentityRepresentation < Representation
3
+ attr_accessor :identity_provider,
4
+ :user_id,
5
+ :user_name
6
+
7
+ def self.from_hash(hash)
8
+ rep = new
9
+ rep.identity_provider = hash["identityProvider"]
10
+ rep.user_id = hash["userId"]
11
+ rep.user_name = hash["userName"]
12
+ rep
13
+ end
14
+ end
15
+ end
@@ -1,21 +1,21 @@
1
- module KeycloakAdmin
2
- class GroupRepresentation < Representation
3
- attr_accessor :id,
4
- :name,
5
- :path,
6
- :attributes,
7
- :sub_group_count,
8
- :sub_groups
9
-
10
- def self.from_hash(hash)
11
- group = new
12
- group.id = hash["id"]
13
- group.name = hash["name"]
14
- group.path = hash["path"]
15
- group.attributes = hash.fetch("attributes", {}).map { |k, v| [k.to_sym, Array(v)] }.to_h
16
- group.sub_group_count = hash["subGroupCount"]
17
- group.sub_groups = hash.fetch("subGroups", []).map { |sub_group_hash| self.from_hash(sub_group_hash) }
18
- group
19
- end
20
- end
21
- end
1
+ module KeycloakAdmin
2
+ class GroupRepresentation < Representation
3
+ attr_accessor :id,
4
+ :name,
5
+ :path,
6
+ :attributes,
7
+ :sub_group_count,
8
+ :sub_groups
9
+
10
+ def self.from_hash(hash)
11
+ group = new
12
+ group.id = hash["id"]
13
+ group.name = hash["name"]
14
+ group.path = hash["path"]
15
+ group.attributes = hash.fetch("attributes", {}).map { |k, v| [k.to_sym, Array(v)] }.to_h
16
+ group.sub_group_count = hash["subGroupCount"]
17
+ group.sub_groups = hash.fetch("subGroups", []).map { |sub_group_hash| self.from_hash(sub_group_hash) }
18
+ group
19
+ end
20
+ end
21
+ end