【发布时间】:2017-07-31 02:06:23
【问题描述】:
我是 Spring Security 的新手,我已经为我的 Spring Boot 应用程序创建了一个基本身份验证来试用它
我已经创建了 MYGlobalAuthenticationConfigurerAdapter 像这样:
@Value("${username}")
String username;
@Value("${password}")
String password;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return new User(username, password, true, true, true, true,
AuthorityUtils.createAuthorityList("USER"));
}
};
}
请注意,我从属性文件加载用户名和密码,并根据值进行验证
和这样的 MyWebSecurityConfigurerAdapter:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and().
httpBasic().and().
csrf().disable();
}
带有@EnableWebSecurity 注释。
每次我更改用户名时,我都会尝试使用 postman 使用用户名和密码连接到我的一个 Web 服务,即使用户名与我放入属性文件中的用户名不同,请求也会得到验证
【问题讨论】:
标签: spring spring-boot spring-security basic-authentication