2013-05-03 3 views
2

내가 가지고있는 아래 구성을 사용하는 컨트롤러의 방법봄 보안 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에서 메서드를 조회하지 않는지 알고 있습니까?

많은 감사,

답변

2

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