Skip to content

Commit

Permalink
Fixes #38138 - As a user, I want to invalidate JWTs for all users.
Browse files Browse the repository at this point in the history
  • Loading branch information
girijaasoni committed Jan 17, 2025
1 parent 0ea2685 commit 6967f38
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def impersonate
end
end

def invalidate_jwt_for_all_users
user_ids = User.authorized(:edit_users).except_hidden.ids.uniq
JwtSecret.where(user_id: user_ids).destroy_all
process_success(
:success_msg => _('Successfully invalidated registration tokens for all users.')
)
end

def invalidate_jwt
@user = find_resource(:edit_users)
@user.jwt_secret&.destroy
Expand Down
5 changes: 4 additions & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<% title _("Users") %>

<% title_actions new_link(_("Create User")) %>
<% title_actions new_link(_("Create User")), new_link(_("Invalidate JWTs for all users"),
hash_for_invalidate_jwt_for_all_users_users_path.merge(:auth_object => User.current, :permission => "edit_users"),
:method => :delete,
:data => { :confirm => _("Invalidate all JSON Web Tokens for all users?") }) %>

<table class="<%= table_css_classes 'table-fixed' %>">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/f_foreman_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
:users => [:new, :create],
:"api/v2/users" => [:create]
map.permission :edit_users,
:users => [:edit, :update, :invalidate_jwt],
:users => [:edit, :update, :invalidate_jwt, :invalidate_jwt_for_all_users],
:"api/v2/users" => [:update],
:"api/v2/registration_tokens" => [:invalidate_jwt_tokens, :invalidate_jwt]
map.permission :destroy_users,
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
get 'extlogout'
get 'auto_complete_search'
delete 'stop_impersonation'
delete 'invalidate_jwt_for_all_users'
end
member do
post 'impersonate'
Expand Down

0 comments on commit 6967f38

Please sign in to comment.