I make a web application in Java using:
Spring MVC Spring Security Hibernate
The distribution of access rights to resources / pages occurs through Spring Security. There are two roles: ADMIN USER Problem -When USER made a login, it will show all USERs, including his Question- how to make sure that when USER made a login, he showed all USERs except him?
SECURITY Current User
public class CurrentUser extends User { private am.teletalk.teletalk.model.User user; public CurrentUser( am.teletalk.teletalk.model.User user) { super(user.getEmail(), user.getPassword(), AuthorityUtils.createAuthorityList(user.getUserType().name())); this.user = user; } public am.teletalk.teletalk.model.User getUser() { return user; } public int getId() { return user.getId(); } }
SECURITY CurrentUserDetailService
public class CurrentUserDetailService implements UserDetailsService { @Autowired private UserRepository userRepository; @Override public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { User user = userRepository.findOneByEmail(s); if (user == null) { throw new UsernameNotFoundException("User not exist"); } return new CurrentUser(user); } }
Controller
@RequestMapping(value = "/", method = RequestMethod.GET) public String mainPage(ModelMap map) { map.addAttribute("allUsers", userRepository.findAll()); map.addAttribute("manager", new User()); return "index"; }