Spring boot Spring Security OAuth2 Jwt访问被拒绝
我试图做这个关于SpringSecurity和OAuth2的教程,SpringBoot1.5。我可以拿到通行证。但当我试图获取端点时,我在Postman中得到了拒绝访问错误。我在Mac操作系统上工作 配置方法Spring boot Spring Security OAuth2 Jwt访问被拒绝,spring-boot,spring-security,oauth-2.0,jwt,postman,Spring Boot,Spring Security,Oauth 2.0,Jwt,Postman,我试图做这个关于SpringSecurity和OAuth2的教程,SpringBoot1.5。我可以拿到通行证。但当我试图获取端点时,我在Postman中得到了拒绝访问错误。我在Mac操作系统上工作 配置方法 @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().authenticated().and(
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER);
}
在tokenEnhancer方法中,我对公钥进行了注释,因为我在Mac验证方面出错
@Bean
public JwtAccessTokenConverter tokenEnhancer() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(privateKey);
//converter.setVerifierKey(publicKey);
return converter;
}
拥有适当授权的用户应该可以访问端点,并且可以通过下一步的设置来实现 比如说
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/products/**").hasRole("USER")
.anyRequest().authenticated()
.and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER);
}
另一方面,我们需要知道用户的“角色”
可以在db或其他保存此信息的地方进行检查
或者需要找到定义当前用户原则的方法。这取决于身份验证的类型。方法
doFilterInternal
负责定义原则的抽象类的实现。403错误意味着用户已通过身份验证,但无权访问。用户未经授权。你能展示一下你的配置(HttpSecurity http)方法吗?@dos4dev我更新了我的问题