For two years since this question was asked, but due to the problems that I encountered today, I would prefer to stop using @Secured , @PreAuthorize , etc. on @Controller s.
For me there was no @Validated in combination with the @Secured controller:
@Controller @Secured("ROLE_ADMIN") public class AdministrationController { // @InitBinder here... @RequestMapping(value = "/administration/add-product", method = RequestMethod.POST) public String addProductPost(@ModelAttribute("product") @Validated ProductDto product, BindingResult bindingResult) { // ... }
The validator simply does not start (Spring MVC 4.1.2, Spring Security 3.2.5) and no checks are performed.
Similar problems are caused by CGLIB proxies used by Spring (in the absence of an interface implemented by a class, Spring creates a CGLIB proxy; if the class implements any interface, then JDK proxies are created - the documentation is well explained here and here ).
As mentioned in the answers that were linked above, it is better to use Spring service-level security annotations that usually implement interfaces (which is why JDK proxies are used), since this does not lead to such problems.
If you want to protect web controllers, it is better to use <http> and <intercept-url /> , which are bound to specific URLs, rather than methods in controllers and work very well. In my case:
<http use-expressions="true" disable-url-rewriting="true"> ... <intercept-url pattern="/administration/**" access="hasRole('ROLE_ADMIN')" /> </http>
dominik Dec 26 '14 at 1:29 2014-12-26 01:29
source share