Kum*_*hav 13 spring-security spring-boot spring-java-config
我正在尝试使用Spring Security java配置来保护Web应用程序.
这是配置的外观: -
@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private String googleClientSecret;
@Autowired
private CustomUserService customUserService;
/*
* (non-Javadoc)
*
* @see org.springframework.security.config.annotation.web.configuration.
* WebSecurityConfigurerAdapter
* #configure(org.springframework.security.config
* .annotation.web.builders.HttpSecurity)
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/","/static/**", "/resources/**","/resources/public/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic().disable()
.requiresChannel().anyRequest().requiresSecure();
// @formatter:on
super.configure(http);
}
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
// @formatter:off
auth
.eraseCredentials(true)
.userDetailsService(customUserService);
// @formatter:on
super.configure(auth);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我已使用以下方法明确禁用HTTP基本身份验证:
.httpBasic().disable()
Run Code Online (Sandbox Code Playgroud)
我在访问安全网址时仍然会收到HTTP Authenticaton提示框.为什么?
请帮我解决这个问题.我只想渲染捆绑的默认登录表单.
Spring Boot Starter版本:1.1.5 Spring Security版本:3.2.5
谢谢
kaz*_*uar 19
首先,调用super.configure(http);将覆盖您之前的整个配置.
试试这个:
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic().disable();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62185 次 |
| 最近记录: |