我在前端开发了Spring4web项目和angularjs应用程序.我使用基于java的spring安全配置。现在,我尝试为用户授权实现SpringWebSecurity4。我创建了SecurityConfig类:
@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配置类添加了导入注释:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.gepick.*")
@EnableTransactionManagement
@Import({ SecurityConfig.class })
public class WebAppConfig extends WebMvcConfigurerAdapter{
...如果我理解得很好,现在当打开项目的浏览器弹簧应该重定向到默认的spring安全登录表单(.anyRequest().authenticated()),但在我的情况下,不是重定向,而是打开未经授权形式的web应用程序。为什么?
发布于 2015-11-03 13:11:50
您在您的springSecurityFilterChain中添加了web.xml吗?
<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>https://stackoverflow.com/questions/33460220
复制相似问题