我开始使用java配置的spring安全性,但当我去http://localhost:8080/myapp时,我没有重定向到登录表单,正如我们所预期的那样。Spring Security拦截不起作用
我有基本的配置,我一直在关注this guide。
我正在使用Spring Security 3.2.5.RELEASE和Spring版本4.1.2.RELEASE。
这是我的安全配置:
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
}
}
和我的安全初始化:
public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer {
}
我的春天servlet调度:
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
什么是您使用的网络服务器?你是否也在使用Spring Web MVC? – shazin 2015-02-24 01:18:59
我通过gradle使用了jetty,是的,我也使用Spring Web MVC。 – Vercryger 2015-02-24 01:29:25
请为您的Spring Web MVC DispatcherServlet注册显示代码 – shazin 2015-02-24 01:38:08