首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring安全4不使用现有的基于java的配置的spring项目。

Spring安全4不使用现有的基于java的配置的spring项目。
EN

Stack Overflow用户
提问于 2015-11-01 07:48:47
回答 1查看 327关注 0票数 0

我在前端开发了Spring4web项目和angularjs应用程序.我使用基于java的spring安全配置。现在,我尝试为用户授权实现SpringWebSecurity4。我创建了SecurityConfig类:

代码语言:javascript
复制
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
        .inMemoryAuthentication()
            .withUser("user").password("password").roles("USER");
}

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .and()
        .httpBasic();
}
...

并向主spring配置类添加了导入注释:

代码语言:javascript
复制
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.gepick.*")
@EnableTransactionManagement
@Import({ SecurityConfig.class })
public class WebAppConfig extends WebMvcConfigurerAdapter{
...

如果我理解得很好,现在当打开项目的浏览器弹簧应该重定向到默认的spring安全登录表单(.anyRequest().authenticated()),但在我的情况下,不是重定向,而是打开未经授权形式的web应用程序。为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-03 13:11:50

您在您的springSecurityFilterChain中添加了web.xml吗?

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

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33460220

复制
相关文章

相似问题

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