[英]Java Spring Security exception
我收到异常启动Web应用程序时No bean named 'springSecurityFilterChain' is defined
,但不明白为什么。 我的配置:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Inject private TokenProvider tokenProvider;
@Inject private CustomUserDetailsService userDetailsService;
@Inject private DefaultEntryPoint defaultEntryPoint;
@Inject
public void registerGlobalAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
private XAuthTokenConfigurer securityConfigurerAdapter() {
return new XAuthTokenConfigurer(userDetailsService, tokenProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(defaultEntryPoint)
.and()
.apply(securityConfigurerAdapter())
.and()
.csrf().disable()
.authorizeRequests()
.antMatchers("/", "/login", "/logout").permitAll()
.antMatchers("/feed").authenticated()
.anyRequest().authenticated();
}
@Bean
public TokenProvider tokenProvider(){
String secret = "secret";
int validityInSeconds = 172800;
return new TokenProvider(secret, validityInSeconds, 172800);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/favicon.ico")
.antMatchers("/resources/**")
.antMatchers("/userresources/**");
}
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
}
此安全初始化程序配置:
@Configuration
public class SecurityInit extends AbstractSecurityWebApplicationInitializer {
}
和应用程序初始化程序:
@Configuration
public class ApplicationInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebMvcConfig.class);
ctx.register(DatabaseConfig.class);
ctx.register(SecurityConfig.class);
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
ctx.setServletContext(servletContext);
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
我错过了什么?
在我的应用程序中,我已定义为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>
我在类路径中有spring-web jar。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.