春季安全hasIpAddress问题

问题描述:

我使用下面的配置的控制器的方法:春季安全hasIpAddress问题

@RequestMapping(value = "/encore/{userName}/{token}", method = RequestMethod.GET) 
@ResponseBody 
@PreAuthorize("hasIpAddress('192.168.1.2/24')") 
public EncoreAccount validateUserRequest(HttpServletRequest request, 
    @PathVariable(value = "userName") String userName, 
    @PathVariable(value = "token") String token) { 
} 

,我有这一个在webmvc-config.xml中

<security:global-method-security pre-post-annotations="enabled" /> 

但是当我运行它,我得到以下异常:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 0): Method call: Method hasIpAddress(java.lang.String) cannot be found on org.springframework.security.access.expression.method.MethodSecurityExpressionRoot type 

我知道hasIpAddress()是org.springframework.security.web.access.expression.WebSec urityExpressionRoot。

你知道为什么它不查找WebSecurityExpressionRoot中的方法吗?

非常感谢,

hasIpAddress()表达可用于网络安全

org.springframework.security。 网络 .access.expression.WebSecurityExpressionRoot

@PreAuth使用

org.springframework.security.access.expression。 方法 .MethodSecurityExpressionRoot

你可以用hasIpAddress()但没有一个方法确保URL(拦截)。

+0

当你阅读春季安全文档时,并不明显。我会把我的笔记放在这里,你仍然可以用PreAuthorize和spel来做到这一点,尽管这并没有考虑代理服务器或负载平衡器等事情。 User @PreAuthorize(“#request.getRemoteAddr()。equals('127.0.0.1')”)并将HttpServletRequest请求变量放入方法参数 – chrismarx 2015-06-23 17:52:23