None of the above methods will work anymore. It seems that Spring has come a long way so that users do not redefine SecurityExpressionRoot.
EDIT 11/19/14 Configuring Spring to use security annotations:
<beans ... xmlns:sec="http://www.springframework.org/schema/security" ... > ... <sec:global-method-security pre-post-annotations="enabled" />
Create a bean as follows:
@Component("mySecurityService") public class MySecurityService { public boolean hasPermission(String key) { return true; } }
Then do something similar in jsp:
<sec:authorize access="@mySecurityService.hasPermission('special')"> <input type="button" value="Special Button" /> </sec:authorize>
Or annotate the method:
@PreAuthorize("@mySecurityService.hasPermission('special')") public void doSpecialStuff() { ... }
And remember: if you use Spring, and you need to solve the problem by extending classes, overriding methods, implementing interfaces, etc ... then you are probably doing something wrong. All annotations and xml, so we really love Spring and not (old versions) EJB.
In addition, you can use the Spring Expression Language in your @PreAuthorize annotations to access the current authentication, as well as the method arguments.
For example:
@Component("mySecurityService") public class MySecurityService { public boolean hasPermission(Authentication authentication, String foo) { ... } }
Then update your @PreAuthorize to match the new method signature:
@PreAuthorize("@mySecurityService.hasPermission(authentication, #foo)") public void doSpecialStuff(String foo) { ... }
James Watkins Feb 15 '13 at 22:05 2013-02-15 22:05
source share