Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Boot自定义授权标头请求根本无法通过_Spring_Rest_Spring Boot_Spring Security - Fatal编程技术网

Spring Boot自定义授权标头请求根本无法通过

Spring Boot自定义授权标头请求根本无法通过,spring,rest,spring-boot,spring-security,Spring,Rest,Spring Boot,Spring Security,所以我有一个Spring Boot应用程序,我使用PostMan向它发送一个请求。它使用Spring安全性和JWT进行身份验证。我正试图获得工作授权,但遇到了问题。Spring能够登录用户并返回令牌罚款。但是,当我把令牌放在标题中时,它根本不起作用。我没有收到服务器的响应。当令牌被移除时,它可以正常工作。现在,无论是否登录,所有请求都应该能够通过 我的Spring Web配置: @Configuration @EnableWebSecurity @EnableGlobalMethodSecuri

所以我有一个Spring Boot应用程序,我使用PostMan向它发送一个请求。它使用Spring安全性和JWT进行身份验证。我正试图获得工作授权,但遇到了问题。Spring能够登录用户并返回令牌罚款。但是,当我把令牌放在标题中时,它根本不起作用。我没有收到服务器的响应。当令牌被移除时,它可以正常工作。现在,无论是否登录,所有请求都应该能够通过

我的Spring Web配置:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurity extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().csrf().disable()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .addFilter(new JWTAuthenticationFilter(authenticationManager()))
        .addFilter(new JWTAuthorizationFilter(authenticationManager()));
    }
}
我尝试访问的REST路径:

@RestController("threadService")
@RequestMapping("/api/thread")
public class ThreadService {
    @RequestMapping(value="/list", method=RequestMethod.GET)
    public List<ThreadDetails> getThreadList() {
        logger.info("getThreadList");
        return threadDao.getThreadList();
    }
}

当标头中没有授权时,上述请求可以正常工作。

不确定这正是我所面临的问题。 当我想与spring引导应用程序公开的restservice通信时,没有设置“授权”。我遵循了沟通所需的步骤,但值不会通过标题传递

我找到的解决方案“通用编解码器”库丢失了。一旦我在我的web应用程序中添加了依赖项,它就开始向我的spring boot应用程序发送头中的“授权”。
希望这对某人有所帮助。

好的,不错,在你的情况下,但是当你在Postman上做请求时,一切都很好,但是当你使用Axios(比如React)时,授权标头永远不会到达请求标头上的服务器端,怎么样?
GET /api/thread/list HTTP/1.1
Host: localhost:8080
Authorization : Bearer (JWT token here)
Cache-Control: no-cache
Postman-Token: 69565839-4806-b4f6-9a03-11382a80c7da