Module: Keycloak::Admin
- Included in:
- Internal
- Defined in:
- lib/keycloak.rb
Overview
Os recursos desse module (admin) serão utilizadas apenas por usuários que possuem as roles do client realm-management
Class Method Summary collapse
- .add_client_level_roles_to_user(id, client, role_representation, access_token = nil) ⇒ Object
- .count_users(access_token = nil) ⇒ Object
- .create_user(user_representation, access_token = nil) ⇒ Object
- .delete_client_level_roles_from_user(id, client, role_representation, access_token = nil) ⇒ Object
- .delete_user(id, access_token = nil) ⇒ Object
- .generic_delete(service, query_parameters = nil, body_parameter = nil, access_token = nil) ⇒ Object
-
.generic_get(service, query_parameters = nil, access_token = nil) ⇒ Object
Generics methods.
- .generic_post(service, query_parameters, body_parameter, access_token = nil) ⇒ Object
- .generic_put(service, query_parameters, body_parameter, access_token = nil) ⇒ Object
- .get_all_roles_client(id, access_token = nil) ⇒ Object
- .get_client_level_role_for_user_and_app(id, client, access_token = nil) ⇒ Object
- .get_clients(query_parameters = nil, access_token = nil) ⇒ Object
- .get_effective_client_level_role_composite_user(id, client, access_token = nil) ⇒ Object
- .get_groups(query_parameters = nil, access_token = nil) ⇒ Object
- .get_groups_by_role_name(role_name, query_parameters = nil, access_token = nil) ⇒ Object
- .get_role_mappings(id, access_token = nil) ⇒ Object
- .get_roles_client_by_name(id, role_name, access_token = nil) ⇒ Object
- .get_user(id, access_token = nil) ⇒ Object
- .get_users(query_parameters = nil, access_token = nil) ⇒ Object
- .get_users_by_group(id, query_parameters = nil, access_token = nil) ⇒ Object
- .get_users_by_role_name(role_name, query_parameters = nil, access_token = nil) ⇒ Object
- .get_users_client_by_role_name(id, role_name, access_token = nil) ⇒ Object
- .reset_password(id, credential_representation, access_token = nil) ⇒ Object
- .revoke_consent_user(id, client_id = nil, access_token = nil) ⇒ Object
- .update_account_email(id, actions, redirect_uri = '', client_id = nil, access_token = nil) ⇒ Object
- .update_effective_user_roles(id, client_id, roles_names, access_token = nil) ⇒ Object
- .update_user(id, user_representation, access_token = nil) ⇒ Object
Class Method Details
.add_client_level_roles_to_user(id, client, role_representation, access_token = nil) ⇒ Object
491 492 493 |
# File 'lib/keycloak.rb', line 491 def self.add_client_level_roles_to_user(id, client, role_representation, access_token = nil) generic_post("users/#{id}/role-mappings/clients/#{client}", nil, role_representation, access_token) end |
.count_users(access_token = nil) ⇒ Object
433 434 435 |
# File 'lib/keycloak.rb', line 433 def self.count_users(access_token = nil) generic_get("users/count/", nil, access_token) end |
.create_user(user_representation, access_token = nil) ⇒ Object
429 430 431 |
# File 'lib/keycloak.rb', line 429 def self.create_user(user_representation, access_token = nil) generic_post("users/", nil, user_representation, access_token) end |
.delete_client_level_roles_from_user(id, client, role_representation, access_token = nil) ⇒ Object
495 496 497 |
# File 'lib/keycloak.rb', line 495 def self.delete_client_level_roles_from_user(id, client, role_representation, access_token = nil) generic_delete("users/#{id}/role-mappings/clients/#{client}", nil, role_representation, access_token) end |
.delete_user(id, access_token = nil) ⇒ Object
445 446 447 |
# File 'lib/keycloak.rb', line 445 def self.delete_user(id, access_token = nil) generic_delete("users/#{id}", nil, nil, access_token) end |
.generic_delete(service, query_parameters = nil, body_parameter = nil, access_token = nil) ⇒ Object
572 573 574 |
# File 'lib/keycloak.rb', line 572 def self.generic_delete(service, query_parameters = nil, body_parameter = nil, access_token = nil) Keycloak.generic_request(effective_access_token(access_token), full_url(service), query_parameters, body_parameter, 'DELETE') end |
.generic_get(service, query_parameters = nil, access_token = nil) ⇒ Object
Generics methods
560 561 562 |
# File 'lib/keycloak.rb', line 560 def self.generic_get(service, query_parameters = nil, access_token = nil) Keycloak.generic_request(effective_access_token(access_token), full_url(service), query_parameters, nil, 'GET') end |
.generic_post(service, query_parameters, body_parameter, access_token = nil) ⇒ Object
564 565 566 |
# File 'lib/keycloak.rb', line 564 def self.generic_post(service, query_parameters, body_parameter, access_token = nil) Keycloak.generic_request(effective_access_token(access_token), full_url(service), query_parameters, body_parameter, 'POST') end |
.generic_put(service, query_parameters, body_parameter, access_token = nil) ⇒ Object
568 569 570 |
# File 'lib/keycloak.rb', line 568 def self.generic_put(service, query_parameters, body_parameter, access_token = nil) Keycloak.generic_request(effective_access_token(access_token), full_url(service), query_parameters, body_parameter, 'PUT') end |
.get_all_roles_client(id, access_token = nil) ⇒ Object
479 480 481 |
# File 'lib/keycloak.rb', line 479 def self.get_all_roles_client(id, access_token = nil) generic_get("clients/#{id}/roles", nil, access_token) end |
.get_client_level_role_for_user_and_app(id, client, access_token = nil) ⇒ Object
499 500 501 |
# File 'lib/keycloak.rb', line 499 def self.get_client_level_role_for_user_and_app(id, client, access_token = nil) generic_get("users/#{id}/role-mappings/clients/#{client}", nil, access_token) end |
.get_clients(query_parameters = nil, access_token = nil) ⇒ Object
475 476 477 |
# File 'lib/keycloak.rb', line 475 def self.get_clients(query_parameters = nil, access_token = nil) generic_get("clients/", query_parameters, access_token) end |
.get_effective_client_level_role_composite_user(id, client, access_token = nil) ⇒ Object
554 555 556 |
# File 'lib/keycloak.rb', line 554 def self.get_effective_client_level_role_composite_user(id, client, access_token = nil) generic_get("users/#{id}/role-mappings/clients/#{client}/composite", nil, access_token) end |
.get_groups(query_parameters = nil, access_token = nil) ⇒ Object
463 464 465 |
# File 'lib/keycloak.rb', line 463 def self.get_groups(query_parameters = nil, access_token = nil) generic_get("groups/", query_parameters, access_token) end |
.get_groups_by_role_name(role_name, query_parameters = nil, access_token = nil) ⇒ Object
471 472 473 |
# File 'lib/keycloak.rb', line 471 def self.get_groups_by_role_name(role_name, query_parameters = nil, access_token = nil) generic_get("roles/#{role_name}/groups", query_parameters, access_token) end |
.get_role_mappings(id, access_token = nil) ⇒ Object
459 460 461 |
# File 'lib/keycloak.rb', line 459 def self.get_role_mappings(id, access_token = nil) generic_get("users/#{id}/role-mappings", nil, access_token) end |
.get_roles_client_by_name(id, role_name, access_token = nil) ⇒ Object
483 484 485 |
# File 'lib/keycloak.rb', line 483 def self.get_roles_client_by_name(id, role_name, access_token = nil) generic_get("clients/#{id}/roles/#{role_name}", nil, access_token) end |
.get_user(id, access_token = nil) ⇒ Object
437 438 439 |
# File 'lib/keycloak.rb', line 437 def self.get_user(id, access_token = nil) generic_get("users/#{id}", nil, access_token) end |
.get_users(query_parameters = nil, access_token = nil) ⇒ Object
421 422 423 |
# File 'lib/keycloak.rb', line 421 def self.get_users(query_parameters = nil, access_token = nil) generic_get("users/", query_parameters, access_token) end |
.get_users_by_group(id, query_parameters = nil, access_token = nil) ⇒ Object
425 426 427 |
# File 'lib/keycloak.rb', line 425 def self.get_users_by_group(id, query_parameters = nil, access_token = nil) generic_get("groups/#{id}/members", query_parameters, access_token) end |
.get_users_by_role_name(role_name, query_parameters = nil, access_token = nil) ⇒ Object
467 468 469 |
# File 'lib/keycloak.rb', line 467 def self.get_users_by_role_name(role_name, query_parameters = nil, access_token = nil) generic_get("roles/#{role_name}/users", query_parameters, access_token) end |
.get_users_client_by_role_name(id, role_name, access_token = nil) ⇒ Object
487 488 489 |
# File 'lib/keycloak.rb', line 487 def self.get_users_client_by_role_name(id, role_name, access_token = nil) generic_get("clients/#{id}/roles/#{role_name}/users", nil, access_token) end |
.reset_password(id, credential_representation, access_token = nil) ⇒ Object
550 551 552 |
# File 'lib/keycloak.rb', line 550 def self.reset_password(id, credential_representation, access_token = nil) generic_put("users/#{id}/reset-password", nil, credential_representation, access_token) end |
.revoke_consent_user(id, client_id = nil, access_token = nil) ⇒ Object
449 450 451 452 |
# File 'lib/keycloak.rb', line 449 def self.(id, client_id = nil, access_token = nil) client_id = Keycloak::Client.client_id if isempty?(client_id) generic_delete("users/#{id}/consents/#{client_id}", nil, nil, access_token) end |
.update_account_email(id, actions, redirect_uri = '', client_id = nil, access_token = nil) ⇒ Object
454 455 456 457 |
# File 'lib/keycloak.rb', line 454 def self.update_account_email(id, actions, redirect_uri = '', client_id = nil, access_token = nil) client_id = Keycloak::Client.client_id if isempty?(client_id) generic_put("users/#{id}/execute-actions-email", { redirect_uri: redirect_uri, client_id: client_id }, actions, access_token) end |
.update_effective_user_roles(id, client_id, roles_names, access_token = nil) ⇒ Object
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/keycloak.rb', line 503 def self.update_effective_user_roles(id, client_id, roles_names, access_token = nil) client = JSON get_clients({ clientId: client_id }, access_token) user_roles = JSON get_client_level_role_for_user_and_app(id, client[0]['id'], access_token) roles = Array.new # Include new role roles_names.each do |r| if r && !r.empty? found = false user_roles.each do |ur| found = ur['name'] == r break if found found = false end if !found role = JSON get_roles_client_by_name(client[0]['id'], r, access_token) roles.push(role) end end end garbage_roles = Array.new # Exclude old role user_roles.each do |ur| found = false roles_names.each do |r| if r && !r.empty? found = ur['name'] == r break if found found = false end end if !found garbage_roles.push(ur) end end if garbage_roles.count > 0 delete_client_level_roles_from_user(id, client[0]['id'], garbage_roles, access_token) end if roles.count > 0 add_client_level_roles_to_user(id, client[0]['id'], roles, access_token) end end |
.update_user(id, user_representation, access_token = nil) ⇒ Object
441 442 443 |
# File 'lib/keycloak.rb', line 441 def self.update_user(id, user_representation, access_token = nil) generic_put("users/#{id}", nil, user_representation, access_token) end |