Class: KeycloakAdmin::RoleMapperClient

Inherits:
Client
  • Object
show all
Defined in:
lib/keycloak-admin/client/role_mapper_client.rb

Instance Method Summary collapse

Methods inherited from Client

#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url

Constructor Details

#initialize(configuration, user_resource) ⇒ RoleMapperClient

Returns a new instance of RoleMapperClient.



3
4
5
6
# File 'lib/keycloak-admin/client/role_mapper_client.rb', line 3

def initialize(configuration, user_resource)
  super(configuration)
  @user_resource = user_resource
end

Instance Method Details

#listObject



8
9
10
11
12
13
# File 'lib/keycloak-admin/client/role_mapper_client.rb', line 8

def list
  response = execute_http do
    RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).get(headers)
  end
  JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
end

#realm_level_urlObject



41
42
43
# File 'lib/keycloak-admin/client/role_mapper_client.rb', line 41

def realm_level_url
  "#{@user_resource.resource_url}/role-mappings/realm"
end

#remove_all_realm_rolesObject



34
35
36
37
38
39
# File 'lib/keycloak-admin/client/role_mapper_client.rb', line 34

def remove_all_realm_roles
  execute_http do
    RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).delete(headers)
  end
  true
end

#remove_realm_level(role_representation_list) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/keycloak-admin/client/role_mapper_client.rb', line 23

def remove_realm_level(role_representation_list)
  execute_http do
    RestClient::Request.execute(
      method: :delete, 
      url: realm_level_url, 
      payload: create_payload(role_representation_list), 
      headers: headers
    )
  end
end

#save_realm_level(role_representation_list) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/keycloak-admin/client/role_mapper_client.rb', line 15

def save_realm_level(role_representation_list)
  execute_http do
    RestClient::Resource.new(realm_level_url, @configuration.rest_client_options).post(
      create_payload(role_representation_list), headers
    )
  end
end