Java 为什么当我尝试使用resfresh令牌时,springboot总是返回401?

Java 为什么当我尝试使用resfresh令牌时,springboot总是返回401?,java,spring-boot,spring-security,oauth-2.0,refresh-token,Java,Spring Boot,Spring Security,Oauth 2.0,Refresh Token,我试图弄明白为什么在SpringBootAPI中使用刷新令牌时,我总是得到401状态 这是邮递员的要求: 但是auth endpoind的工作没有问题 我不知道为什么会这样 这是我为端点设置的安全设置 package com.bolsadeideas.apirest.auth; import java.util.Arrays; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.sp

我试图弄明白为什么在SpringBootAPI中使用刷新令牌时,我总是得到401状态

这是邮递员的要求:

但是auth endpoind的工作没有问题

我不知道为什么会这样

这是我为端点设置的安全设置

package com.bolsadeideas.apirest.auth;

import java.util.Arrays;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    // configuracion centralizada de la seguridad de las rutas
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/clientes", "/api/clientes/page/**", "/api/uploads/img/**", "/images/**","/oauth/**").permitAll()
            .antMatchers(HttpMethod.POST, "/oauth/**").permitAll()
                .antMatchers(HttpMethod.GET, "/api/clientes/{id}").hasAnyRole("USER", "ADMIN")
                .antMatchers(HttpMethod.POST, "/api/clientes/upload").hasAnyRole("USER", "ADMIN")
                .antMatchers(HttpMethod.POST, "/api/clientes").hasRole("ADMIN")
                .antMatchers("/api/clientes/**").hasRole("ADMIN")
                .anyRequest().authenticated()
                .and().cors().configurationSource(corsConfigurationSource());
    }

    // PASO 1 crear en bean (metodo inyectable) de la configuracion del cors
    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowedOrigins(Arrays.asList("http://localhost:4200"));
        config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
        config.setAllowCredentials(true);
        config.setAllowedHeaders(Arrays.asList("Content-Type", "Authorization"));

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", config);
        return source;
    }

    // PASO 2 registra esta configuracion y la pasa a los interceptores del spring security
    @Bean
    public FilterRegistrationBean<CorsFilter> corsFilter(){
        FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(corsConfigurationSource()));
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return bean;
    }


}
package com.bolsadeideas.apirest.auth;
导入java.util.array;
导入org.springframework.boot.web.servlet.FilterRegistrationBean;
导入org.springframework.context.annotation.Bean;
导入org.springframework.context.annotation.Configuration;
导入org.springframework.core.Ordered;
导入org.springframework.http.HttpMethod;
导入org.springframework.security.config.annotation.web.builders.HttpSecurity;
导入org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
导入org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
导入org.springframework.web.cors.cors配置;
导入org.springframework.web.cors.cors配置源;
导入org.springframework.web.cors.UrlBasedCorsConfigurationSource;
导入org.springframework.web.filter.CorsFilter;
@配置
@EnableResourceServer
公共类ResourceServerConfig扩展了ResourceServerConfigurerAdapter{
//拉斯鲁塔斯酒店
@凌驾
public void configure(HttpSecurity http)引发异常{
http.authorizeRequests()
.antMatchers(HttpMethod.POST,“/oauth/**”).permitAll()
.antMatchers(HttpMethod.GET,“/api/clientes/{id}”).hasAnyRole(“用户”,“管理员”)
.antMatchers(HttpMethod.POST,“/api/clientes/upload”).hasAnyRole(“用户”、“管理员”)
.antMatchers(HttpMethod.POST,“/api/clientes”).hasRole(“ADMIN”)
.antMatchers(“/api/clientes/**”).hasRole(“管理员”)
.anyRequest().authenticated()
.and().cors().configurationSource(corsConfigurationSource());
}
//在cors结构中添加一种豆制品(metodo inyectable)
@豆子
公共公司配置源公司配置源(){
CorsConfiguration配置=新的CorsConfiguration();
config.setAllowedOrigins(Arrays.asList(“http://localhost:4200"));
config.setAllowedMethods(Arrays.asList(“GET”、“POST”、“PUT”、“DELETE”、“OPTIONS”);
config.setAllowCredentials(true);
config.setAllowedHeaders(Arrays.asList(“内容类型”、“授权”));
UrlBasedCorsConfigurationSource=新的UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration(“/**”,config);
返回源;
}
//PASO 2注册机构的配置和安全性
@豆子
公共过滤器注册Bean公司过滤器(){
FilterRegistrationBean=新的FilterRegistrationBean(新的CorsFilter(CorsConfiguration Source());
setOrder(有序的、最高的_优先级);
返回豆;
}
}
如您所见,我添加了路由
.antMatchers(HttpMethod.POST,“/oauth/**”).permitAll()
,但它仍然不起作用

这是整个项目(是一个edu项目)


您忘记使用存储,因此您没有存储刷新令牌,这就是您无法获取刷新令牌的原因,在postman中,请不要忘记添加基本身份验证。

在第二个映像的10个请求标头中,第一个映像的9个标头中没有的是什么?您有3个不同的配置授权路由,是否尝试在禁用其他2个的情况下运行项目?