Spring boot Spring安全允许甚至未经身份验证的用户?这个代码有什么问题?
我正在做一个简单的spring security poc,但遇到了一些问题。 在扩展WebSecurityConfigureAdapter并实现自己的UserDetailsService之后,spring security允许所有用户即使没有身份验证。请指出下面代码中的缺陷Spring boot Spring安全允许甚至未经身份验证的用户?这个代码有什么问题?,spring-boot,spring-security,Spring Boot,Spring Security,我正在做一个简单的spring security poc,但遇到了一些问题。 在扩展WebSecurityConfigureAdapter并实现自己的UserDetailsService之后,spring security允许所有用户即使没有身份验证。请指出下面代码中的缺陷 ... @EnableWebSecurity public class MyWebSecurity extends WebSecurityConfigurerAdapter { @Autowired Us
...
@EnableWebSecurity
public class MyWebSecurity extends WebSecurityConfigurerAdapter {
@Autowired
UserDetailsService myUserDtlSrv;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(myUserDtlSrv);
}
@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
UserDetailsService的我的实现
...
@Service
public class MyUserDtlSrv implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return new User("a", "a", Arrays.asList());
}
}
spring security不是保护每个url(默认情况下为资源)吗?您需要指定授权的请求。下面的片段 授权经过身份验证(通过表单登录)的请求
@覆盖
受保护的无效配置(HttpSecurity http)引发异常{
http.antMatcher(“/**”)
.csrf(t->t.disable())
.authorizeRequests(t->t.anyRequest().authorized())
.formLogin(Customizer.withDefaults());
}
}
谢谢,并不是默认情况下每个URL都是安全的。也许这是匹配Ant matcher或request matcher.cool的请求的默认设置。在+1内俯仰时的Thx