Class: KeycloakAdmin::ClientAuthzPolicyClient
- Inherits:
-
Client
- Object
- Client
- KeycloakAdmin::ClientAuthzPolicyClient
show all
- Defined in:
- lib/keycloak-admin/client/client_authz_policy_client.rb
Instance Method Summary
collapse
-
#authz_policy_url(client_id, type, id = nil) ⇒ Object
-
#build(name, description, type, logic, decision_strategy, fetch_roles, roles = []) ⇒ Object
-
#create!(name, description, type, logic, decision_strategy, fetch_roles, roles) ⇒ Object
-
#delete(policy_id) ⇒ Object
-
#find_by(name, type) ⇒ Object
-
#get(policy_id) ⇒ Object
-
#initialize(configuration, realm_client, client_id, type) ⇒ ClientAuthzPolicyClient
constructor
A new instance of ClientAuthzPolicyClient.
-
#list ⇒ Object
-
#save(policy_representation) ⇒ Object
Methods inherited from Client
#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url
Constructor Details
#initialize(configuration, realm_client, client_id, type) ⇒ ClientAuthzPolicyClient
Returns a new instance of ClientAuthzPolicyClient.
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 4
def initialize(configuration, realm_client, client_id, type)
super(configuration)
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
raise ArgumentError.new("type must be defined") unless type
raise ArgumentError.new("only 'role' policies supported") unless type.to_sym == :role
@realm_client = realm_client
@client_id = client_id
@type = type
end
|
Instance Method Details
#authz_policy_url(client_id, type, id = nil) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 57
def authz_policy_url(client_id, type, id = nil)
if id
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/policy/#{encode_segment(type)}/#{encode_segment(id)}"
else
"#{@realm_client.realm_admin_url}/clients/#{encode_segment(client_id)}/authz/resource-server/policy/#{encode_segment(type)}?permission=false"
end
end
|
#build(name, description, type, logic, decision_strategy, fetch_roles, roles = []) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 65
def build(name, description, type, logic, decision_strategy, fetch_roles, roles=[])
policy = ClientAuthzPolicyRepresentation.new
policy.name = name
policy.description = description
policy.type = type
policy.logic = logic
policy.decision_strategy = decision_strategy
policy.fetch_roles = fetch_roles
policy.roles = roles
policy
end
|
#create!(name, description, type, logic, decision_strategy, fetch_roles, roles) ⇒ Object
15
16
17
18
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 15
def create!(name, description, type, logic, decision_strategy, fetch_roles, roles)
response = save(build(name, description, type, logic, decision_strategy, fetch_roles, roles))
ClientAuthzPolicyRepresentation.from_hash(JSON.parse(response))
end
|
#delete(policy_id) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 43
def delete(policy_id)
execute_http do
resource(authz_policy_url(@client_id, @type, policy_id)).delete()
end
true
end
|
#find_by(name, type) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 35
def find_by(name, type)
response = execute_http do
url = "#{authz_policy_url(@client_id, @type)}&#{build_query(name: name, type: type, first: 0, max: 11)}"
resource(url).get()
end
JSON.parse(response).map { |role_as_hash| ClientAuthzPolicyRepresentation.from_hash(role_as_hash) }
end
|
#get(policy_id) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 28
def get(policy_id)
response = execute_http do
resource(authz_policy_url(@client_id, @type, policy_id)).get()
end
ClientAuthzPolicyRepresentation.from_hash(JSON.parse(response))
end
|
#list ⇒ Object
50
51
52
53
54
55
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 50
def list
response = execute_http do
resource(authz_policy_url(@client_id, @type)).get()
end
JSON.parse(response).map { |role_as_hash| ClientAuthzPolicyRepresentation.from_hash(role_as_hash) }
end
|
#save(policy_representation) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/keycloak-admin/client/client_authz_policy_client.rb', line 20
def save(policy_representation)
execute_http do
resource(authz_policy_url(@client_id, @type)).post(
create_payload(policy_representation),
)
end
end
|