SecurityContextHolder.getContext().setAuthentication(auth)重新设值

String role = roleMapper.findByUserIdAndOrgId(AuthenticationUtils.getUserId(),po.getId());

SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role) ;

List list = new ArrayList<>();

list.add(grantedAuthority);

PreAuthenticatedAuthenticationToken auth = new PreAuthenticatedAuthenticationToken(
                                                userDetails, userDetails.getPassword(),list
                                            );
auth.setDetails(new WebAuthenticationDetails(request));

SecurityContextHolder.getContext().setAuthentication(auth);

你可能感兴趣的:(java)