i have project were iam spring security 3.1.3 and mvc 3.2
i want too allow a url wehen in the userid in the path is matching the principal userid
<security:intercept-url pattern="/user/{id}/edit" access="#id == principal.userId"/>
http use-expressions it set to true and when a try principal.userId == 1 it works but i need to use the extracted value from the url.
i already tried all possible combinations.
It's not possible. But there is another way. You can define you own web expression that will be responsible for extracting of id parameter from URL. It may looks like that:
To do so you need:
1. Add CustomWebSecurityExpressionRoot that extends WebSecurityExpressionRoot
2. Add getIdUrlPathParameter() method. It will have access to HttpServletRequest object.
3. Define CustomWebSecurityExpressionHandler that extends DefaultWebSecurityExpressionHandler. Override createSecurityExpressionRoot method abd use your CustomWebSecurityExpressionRoot here.
4. Define custom access decision manager (xml below)
5. Inject it into your http element via access-decision-manager-ref attribute
This cannot be done with Spring Security.