I'm very new to the Spring Security Framework and I have a little problem here to solve.
I've already managed to use the @PreAuthorized("hasPermission('#person', Permission) annotation for service and controller methods. This works fine for me, but this only works for the whole Domain class.
In my case there are some fields which should be shown to users despite they haven't the permission to read this Person.
A quick example:
- A user logs in.
- He'd like to visit the profile page from Jon Doe.
- But the user did not have the right to read Jon Doe.
- The System should notice the user that he hasn't the rights and shows the Name like: You doesn't have the permission to read the profile from Jon Doe."
This is a very simple example, there are more fields a user could see.
Hopefully you'll understand what I'm asking for.
(I´m sorry my english is not that good.)
EDIT
PersonController
@RequestMapping("/{id}")
public String get(@PathVariable("id") Long personId, Model model,HttpSession session) {
Person person = personService.findById(personId);
/* DO STUFF HERE */
return "person.show";
}
PersonService
@PreAuthorize("hasPermission('#personId', <domainClass>, 'read')")
public Person findById(Long personId) {
return personRepository.findOne(personId);
}