【发布时间】:2017-10-22 00:08:05
【问题描述】:
我正在尝试为我的 Spring Boot 应用程序添加安全性。我当前的应用程序正在使用 REST 控制器,每次收到 GET 或 POST 请求时,我都会读取 HTTP 标头以检索用户和密码,以便根据我存储的所有用户的属性文件验证它们。我想将其更改为使用 Spring Security,这就是我目前所得到的:
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/index.html").permitAll()
.antMatchers("/swagger-ui.html").hasRole("ADMIN")
.anyRequest().authenticated();
}
@Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("admin").password("password").roles("ADMIN").build());
}
}
我如何告诉configure 方法是从标头而不是登录表单中检索用户凭据?
【问题讨论】:
-
您的意思是使用
Authentication标头进行基本身份验证吗? -
你的HTTP头是什么意思,头的名字是什么?
标签: security authentication spring-boot spring-security http-headers