Module: Keycloak::API::RoleResources
- Extended by:
- ActiveSupport::Concern
- Includes:
- Concerns::APIUtil
- Included in:
- Client
- Defined in:
- lib/keycloak/api/role_resources.rb
Instance Method Summary collapse
-
#add_role_mapping(user_id, role_mappings) ⇒ Object
Only role id and role name are required in role_mappings.
-
#create_or_find_role(role_rep) ⇒ Keycloak::Model::RoleRepresentation
Role representation.
- #create_role(role_rep) ⇒ Object
-
#find_role_by_name(name) ⇒ Keycloak::Model::RoleRepresentation
Role representation.
-
#find_user_realm_roles(user_id) ⇒ Array<Keycloak::Model::RoleRepresentation>
An array of role representations.
-
#realm_roles ⇒ Array<Keycloak::Model::RoleRepresentation>
Role representations.
-
#remove_role_mapping(user_id, role_mappings) ⇒ Object
Only role id and role name are required in role_mappings.
Methods included from Concerns::APIUtil
#admin_realm_url, #delete, #get, #post, #put, #realm_url
Instance Method Details
#add_role_mapping(user_id, role_mappings) ⇒ Object
Only role id and role name are required in role_mappings
48 49 50 51 |
# 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 |
#create_or_find_role(role_rep) ⇒ Keycloak::Model::RoleRepresentation
Returns role representation.
30 31 32 33 34 |
# 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 |
#create_role(role_rep) ⇒ Object
8 9 10 11 |
# 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 |
#find_role_by_name(name) ⇒ Keycloak::Model::RoleRepresentation
Returns role representation.
21 22 23 24 25 26 |
# 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 |
#find_user_realm_roles(user_id) ⇒ Array<Keycloak::Model::RoleRepresentation>
Returns an array of role representations.
38 39 40 41 42 |
# 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 |
#realm_roles ⇒ Array<Keycloak::Model::RoleRepresentation>
Returns role representations.
14 15 16 17 |
# 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 |
#remove_role_mapping(user_id, role_mappings) ⇒ Object
Only role id and role name are required in role_mappings
57 58 59 60 |
# 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 |