java - Spring security 401 Unauthorized 尽管有 permitAll
问题描述
我正在尝试使用 Spring Boot 做我的第二个应用程序。即使我使用permittAll
方法,我的安全配置也有问题。这是我的代码的一部分WebSecurityConfig
:
@Configuration
@EnableWebSecurity(debug=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
MyUserDetailsService userDetailsService;
@Autowired
private PasswordEncoder passwordEncoder;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/register").permitAll()
.antMatchers("/users").authenticated()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}
@Bean
public DaoAuthenticationProvider authenticationProvider(){
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setPasswordEncoder(passwordEncoder);
provider.setUserDetailsService(userDetailsService);
return provider;
}
}
当我在 /register 上使用 Postman 时,我有 401 Unauthorized,尝试了很多方法,但不知道该怎么做。当然,Rest 控制器处理 /register 和 /users。
预先感谢您的任何帮助。
解决方案
推荐阅读
- amazon-web-services - 属性参数的值必须是具有字符串(或简单类型)属性的对象
- java - 使用 BIRT 解析 XML
- python - 使用 Scipy 优化器执行单个优化步骤
- r - R Group Data,确定重复项,在最早的实例上更新列
- python - 将 RGB 图像转换为棕褐色滤镜的公式是什么?
- r - 在组和年份上循环函数
- python - 如何测试 PyObject 是否有迭代器
- ios - 使用 UserDefaults 保存数据的正确事件是什么?
- javascript - 如何使用 javascript 按钮切换 url
- security - 没有 SSL 的网站显示不需要的广告,添加 SSL 后它们就消失了。是什么导致出现不需要的内容?