首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过XML配置使用Spring安全启用CSRF预防

通过XML配置使用Spring安全启用CSRF预防
EN

Stack Overflow用户
提问于 2015-08-06 14:47:40
回答 1查看 1.1K关注 0票数 0

在我的web应用程序中,我正在使用Spring4.1.6和Spring-Security4.0.1。在我的应用程序中,我已经浏览过许多文章,使csrf能够使用spring安全性。但我仍然没有找到解决办法。我不会在jsp中得到csrf令牌。它们仍然是空的。我的正常web应用程序运行良好,但在安全设置方面存在问题。

我为启用安全性所做的以下更改是

添加了以下jars:弹簧-安全性-核心-4.0.1弹簧-安全性-Web-4.0.1弹簧-安全性-4.0.1春季-安全-配置-4.0.1

添加了SecurityConfig类

代码语言:javascript
复制
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import  org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    private Logger logger = Logger.getLogger(SecurityConfig.class);

    @Override
protected void configure(HttpSecurity http) throws Exception {

    logger.debug("Inside configure method of SecurityConfig class....");
    http
            .authorizeRequests()
            .anyRequest().permitAll();
}
}    

在web.xml中添加了此过滤器

代码语言:javascript
复制
     springSecurityFilterChain         org.springframework.web.filter.DelegatingFilterProxy     
代码语言:javascript
复制
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

请帮帮忙。

我有一些例外,比如

严重:WebModule/AG_INDREVIEWPWC1270 1270:异常启动筛选器springSecurityFilterChain java.lang.InstantiationException 警告: org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer,:无法加载类WEB9052原因: java.lang.NoClassDefFoundError: org/springframework/web/WebApplicationInitializer

EN

回答 1

Stack Overflow用户

发布于 2015-08-06 15:02:51

您的主要问题似乎是正确安装和部署Spring安全性。您确定所有的spring jars都部署到您的web容器中了吗?

WebApplicationInitializer类通常位于spring-web-4.x.x-RELEASE.jar中。如果您的WEB/lib包含这个jar,您可以选择吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31858912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档