Spent a lot of time browsing the Internet on the same issue. The proposed solutions did not work (maybe I was so unlucky :). So here is my way
First, we create the Grails service as follows:
class SecurityHelperService { final Set<String> userUpdates = new HashSet<String>() public void markUserUpdate(String username) { synchronized (userUpdates) { userUpdates.add(username) } } public boolean clearUserUpdate(String username) { synchronized (userUpdates) { return userUpdates.remove(username) != null } } public boolean checkUserUpdate() { def principal = springSecurityService.principal if (principal instanceof org.springframework.security.core.userdetails.User) { synchronized (userUpdates) { if (!userUpdates.remove(principal.username)) { return true } } springSecurityService.reauthenticate(principal.username) return false } return true } }
In the grails-app/conf directory, we create a Grails filter to check if the current user rights have been changed, for example
class MyFilters { SecurityHelperService securityHelper def filters = { userUpdateCheck(controller: '*', action: '*') { before = { if (!securityHelper.checkUserUpdate()) { redirect url: '/' return false } return true } } } }
It's all. Each time when updating user rights in the code, we call the service method
securityHelper.markUserUpdate('username')
The next time the online user visits the page, his / her permissions are automatically checked and reloaded. No manual logout required.
Optionally, we clear the previous user update on a new login to avoid unnecessary redirection in the filter
Hope this helps
source share