首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring安全性测试:撤回令牌

Spring安全性测试:撤回令牌
EN

Stack Overflow用户
提问于 2018-06-12 14:49:46
回答 1查看 235关注 0票数 0

我成功地实现了代码,它允许我通过OAuth和UserDetailsService从我的应用程序中检索一个JWT令牌。

我正在尝试实现测试来确认这一点,但是我总是收到400条坏请求

代码语言:javascript
复制
@Test
public void is_status_up() throws InterruptedException, JSONException {
    // Given

    final String TOKEN_URL = "http://localhost:8080/oauth/token";
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("username","username");
    params.add("credential","credentials");
    params.add("grant_type","password");

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    HttpEntity<String> entity = new HttpEntity<>("parameters" , headers);

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(params, headers);



    RestTemplate restTemplate = new RestTemplate();

    restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor("client-id","client-secret"));

    //When
    String result = restTemplate.postForObject(TOKEN_URL, request, String.class);

    //Then
    assertThat(result).isNotNull();
}

这应该尝试从的/oauth/token端点检索令牌,我遇到了一个400坏的请求。

在成功检索令牌的postman中,我已经设置了请求。

标题授权:基本内容-类型: application/x-www-form-urlencoded

正文(x-www-form-urlencoded所选)用户名:密码:grant_type:“密码”

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-12 15:00:51

问题是,当密码应该是密码时,我将凭证放在我的param中。我最初是这样做的,就像SonarLint或IntelliJ所强调的那样,并抛出了一个令人讨厌的词密码是如此公开的声明。

  • 解决方案
    • 将参数映射中的“凭据”更改为“密码”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50820063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档