【发布时间】:2018-12-14 20:43:50
【问题描述】:
我正在关注本教程 Part 5: Integrating Spring Security with Spring Boot Web 尝试将 Spring Security 功能添加到我的网页,但我遇到了很多配置问题。
所以我已经到了需要@Override这个方法的部分:
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
但我不太确定将代码放在哪里。我用谷歌搜索发现大多数人把它放在扩展 WebSecurityConfigurerAdapter 的类中,但这在我的情况下不起作用,我收到一个错误,说该方法没有覆盖其超类中的任何方法。
这是我的SecurityConfig,扩展了WebSecurityConfigurerAdapter:
@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests().anyRequest().authenticated()
.antMatchers("/resources/**").permitAll()
.anyRequest().permitAll();
http
.formLogin().failureUrl("/ingresar?error")
.defaultSuccessUrl("/")
.loginPage("/ingresar").permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/logout")
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
}
有什么想法吗??我已经尝试了几个小时!
【问题讨论】:
标签: java spring spring-boot spring-mvc spring-security