I have a vehicle management system. The company in which I work has several business units, so the user can only see the cars of the unit on which he works. This I was able to do, but whenever someone logs in the system it replaces the data of the current session with the session that entered last. I created a UserStatic that made the user see only what is on his drive, but every time someone logs in he replaces the data. I put the code of my loginControle, because it is there that when a user enters it arrow to the userStatic a new user. If anyone knows a new way to do this.
public String logar() {
usuario = usuarioFacade.buscarUsuario(login, senha);
if (usuario != null) {
List<GrantedAuthority> roles = new ArrayList<>();
roles.add(new GrantedAuthorityImpl(usuario.getPermissaoUsuario().toString()));
UserStatic.setUsuario(usuario);
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(new UsernamePasswordAuthenticationToken(
login, senha, roles));