Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用AOP的JavaSpringMVC-CSRF令牌_Java_Spring_Spring Mvc_Aop - Fatal编程技术网

使用AOP的JavaSpringMVC-CSRF令牌

使用AOP的JavaSpringMVC-CSRF令牌,java,spring,spring-mvc,aop,Java,Spring,Spring Mvc,Aop,我正在尝试为使用SpringMVC的站点设置跨站点伪造保护。我的想法是在HTML请求头中发送一个令牌,并使用AOP进行验证,如下所示: @Aspect @Component public class RequestMappingInterceptor { @Before("execution(@org.springframework.web.bind.annotation.RequestMapping * *(..)) && args(request,..)")

我正在尝试为使用SpringMVC的站点设置跨站点伪造保护。我的想法是在HTML请求头中发送一个令牌,并使用AOP进行验证,如下所示:

@Aspect
@Component
public class RequestMappingInterceptor {
    @Before("execution(@org.springframework.web.bind.annotation.RequestMapping * *(..)) && args(request,..)")
    public void before(JoinPoint point, HttpServletRequest request) throws Throwable {
    UserEntity loggedUser = ((AmsUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserEntity();
    String encodedToken = Base64.encodeBase64String(SessionEncodingUtils.encryptDecryptString(loggedUser.getId() + ";" + request.getSession(true).getId().hashCode()).getBytes());
    if (!encodedToken.equals(request.getHeader("csrfToken"))) {
        throw new RuntimeException("go.away");
        }
    }
}

然而,这不起作用,我不知道为什么。这难道不应该拦截任何用
@RequestMapping
表示的包含请求参数的方法吗?任何帮助都将不胜感激

可能相关:为什么不使用Spring Security?它已经内置了CSRF保护?-请参阅并可能与之相关:为什么不使用Spring安全性?它已经内置了CSRF保护?-看到和