Spring Security hasIpAddress issue

I have a method in a controller using the below configuration:

@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) {
}

and I have this one in webmvc-config.xml

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

But when I run it, I get the below exception:

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

I know that the hasIpAddress() is in org.springframework.security.web.access.expression.WebSecurityExpressionRoot.

Do you know why it doesn't look up the method in WebSecurityExpressionRoot?

Many thanks,

Answers


The hasIpAddress() expression is available for web security.

org.springframework.security.web.access.expression.WebSecurityExpressionRoot

@PreAuth uses

org.springframework.security.access.expression.method.MethodSecurityExpressionRoot

You can secure a URL (intercept) with hasIpAddress() but not a method.


Need Your Help

Unloading swfs loaded with Loader::load()

actionscript-3 flash loader

I'm using Loader::load() successfully to load swfs into my main swf and then I add them as a child of a Sprite. When other events occur I want to remove the swfs as needed. I have looked at unlo...