module Keycloak::API::RoleResources
Public Instance Methods
Only role id and role name are required in role_mappings
@param user_id [String] user id @param role_mappings [Array<Keycloak::Model::RoleRepresentation>] an array of roles
# File lib/keycloak/api/role_resources.rb, line 48 def add_role_mapping(user_id, role_mappings) url = admin_realm_url + "/users/#{user_id}/role-mappings/realm" post(url, role_mappings.to_json, headers: {content_type: :json}) end
@param role_rep [Keycloak::Model::RoleRepresentation] role representation @return [Keycloak::Model::RoleRepresentation] role representation
# File lib/keycloak/api/role_resources.rb, line 30 def create_or_find_role(role_rep) create_role(role_rep) && find_role_by_name(role_rep.name) rescue RestClient::Conflict find_role_by_name(role_rep.name) end
@param role_rep [Keycloak::Model::RoleRepresentation] role representation
# File lib/keycloak/api/role_resources.rb, line 8 def create_role(role_rep) url = admin_realm_url + "/roles" post(url, role_rep.to_json, headers: {content_type: :json}) end
@param name [String] name of role @return [Keycloak::Model::RoleRepresentation] role representation
# File lib/keycloak/api/role_resources.rb, line 21 def find_role_by_name(name) url = admin_realm_url + "/roles/#{name}" Model::RoleRepresentation.new JSON.parse(get(url).body) rescue RestClient::NotFound nil end
@param user_id [String] user id @return [Array<Keycloak::Model::RoleRepresentation>] an array of role representations
# File lib/keycloak/api/role_resources.rb, line 38 def find_user_realm_roles(user_id) JSON.parse(get("#{user_resources_url}/#{user_id}/role-mappings/realm")).map do |role| Model::RoleRepresentation.new role end end
@return [Array<Keycloak::Model::RoleRepresentation>] role representations
# File lib/keycloak/api/role_resources.rb, line 14 def realm_roles url = admin_realm_url + "/roles" JSON.parse(get(url)).map { |role| Model::RoleRepresentation.new role } end
Only role id and role name are required in role_mappings
@param user_id [String] user id @param role_mappings [Array<Keycloak::Model::RoleRepresentation>] an array of roles
# File lib/keycloak/api/role_resources.rb, line 57 def remove_role_mapping(user_id, role_mappings) url = admin_realm_url + "/users/#{user_id}/role-mappings/realm" delete(url, payload: role_mappings.to_json, headers: {content_type: :json}) end