How is it possible to create your own web security expression, so that I'll be able to use it in JSP file like:
<sec:authorize access="isOwner()"> some content here </sec:authorize>
How is it possible to create your own web security expression, so that I'll be able to use it in JSP file like:
<sec:authorize access="isOwner()"> some content here </sec:authorize>
Here is what you need. Follow below to create custom SpEL expression:
1) Create custom subclass of WebSecurityExpressionRoot class. In this subclass create a new method which you will use in expression. For example:
2) Create custom subclass of DefaultWebSecurityExpressionHandler class and override method createSecurityExpressionRoot(Authentication authentication, FilterInvocation fi) (not createEvaluationContext(...)) in it to return your CustomWebSecurityExpressionRoot instance. For example:
3) Define in your spring-security.xml the reference to your expression handler bean
After this, you can use your own custom expression instead of the standard one:
I suggest you using
Shiro
framework.Official Link:http://shiro.apache.org/
Implement
AuthorizingRealm
withextends
, then add the expression of security control in thedoGetAuthorizationInfo(...)
.In the JSP, first add Shiro JSP tag library, official link :http://shiro.apache.org/web.html#Web-taglibrary
Using
<shiro:hasPermission name="...">...</shiro:hasPermission>
can control the things you need.name
property is the expression which will compare with what you set inAuthorizingRealm
.Here is permission expression guide :http://shiro.apache.org/permissions.html
Here is some usage: