Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为所有当前登录的用户重新加载权限_Java_Spring_Spring Security - Fatal编程技术网

Java 为所有当前登录的用户重新加载权限

Java 为所有当前登录的用户重新加载权限,java,spring,spring-security,Java,Spring,Spring Security,我以“超级管理员”的身份登录,并更改了一个特定用户组的权限。在此用户组中,有当前已登录且会话处于活动状态的用户。 如何重新加载所有已登录的用户权限而不将其注销 我将所有活动会话ID存储在数据库中,然后在“重新加载权限”中获取它们并传递给此方法: @Autowired private SessionRegistry sessionRegistry; private void refreshSessionWithNewAuthorities(Collection<GrantedAuthori

我以“超级管理员”的身份登录,并更改了一个特定用户组的权限。在此用户组中,有当前已登录且会话处于活动状态的用户。 如何重新加载所有已登录的用户权限而不将其注销

我将所有活动会话ID存储在数据库中,然后在“重新加载权限”中获取它们并传递给此方法:

@Autowired
private SessionRegistry sessionRegistry;

private void refreshSessionWithNewAuthorities(Collection<GrantedAuthority> authorities, String sessionId) {
    SessionInformation sessionInformation = sessionRegistry.getSessionInformation(sessionId);
    org.springframework.security.core.userdetails.User principal = (org.springframework.security.core.userdetails.User) sessionInformation.getPrincipal();

    sessionRegistry.registerNewSession(sessionId, principal);
    sessionInformation.refreshLastRequest();
}
@Autowired
非公开会议登记处会议登记处;
private void RefreshSessionWithNewAuthories(收集权限,字符串sessionId){
SessionInformation SessionInformation=sessionRegistry.getSessionInformation(sessionId);
org.springframework.security.core.userdetails.User principal=(org.springframework.security.core.userdetails.User)sessionInformation.getPrincipal();
sessionRegistry.registerNewSession(sessionId,负责人);
sessionInformation.refreshLastRequest();
}
我如何更新所有特定会话ID的权限

下面是重新加载请求“owner”的代码示例,是否有方法获取任何活动会话的身份验证对象

private void refreshSessionWithNewAuthorities(Collection<GrantedAuthority> authorities) {
    Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
    Authentication newAuth = new UsernamePasswordAuthenticationToken(currentAuth.getPrincipal(), currentAuth.getCredentials(), authorities);

    SecurityContextHolder.getContext().setAuthentication(newAuth);
}
private void refresh sessionwithnewauthorities(收款机构){
Authentication currentAuth=SecurityContextHolder.getContext().getAuthentication();
Authentication newAuth=新用户名PasswordAuthenticationToken(currentAuth.getPrincipal(),currentAuth.getCredentials(),authorities);
SecurityContextHolder.getContext().setAuthentication(newAuth);
}

与其痛苦地尝试使用新权限更新所有现有用户上下文,不如让他们注销并再次登录

更改用户权限时,您可以检查他当前是否有活动会话,并向客户端推送通知。通过这种方式,他将被主动通知权限更改,并且他现在有了更多的权力。与在后台秘密更改权限相比,这很可能会为用户带来积极的体验。我敢肯定他不会费心注销和登录,因为这会让他感觉自己可以激活新的权限

结论:
这对您来说更容易,对用户来说也会有更好的体验。

您真的想这样做吗?用户在权限更改后需要重新登录是很常见的。即使使用Windows,@HerrDerb也有一个团队会议,我们同意这个解决方案。也许,如果什么都没有出现,我会尝试说服他们用一些信息注销用户。这肯定是我的第一选择。否则,你会让生活变得不必要的复杂。您正在构建什么样的应用程序?森林行业、大量地图和森林管理。我们是在谈论云应用程序吗?这不是一个更好的解决方案吗?向客户端推送一个通知,告知其权限已更改,并且要使其生效,他需要再次登录?这样他也注意到了变化。如果您只是使用新权限刷新上下文,则会100%确定“您是否已经更改了我的权限?”问题,因为用户不会得到通知