我遇到了与这里完全相同的问题:Jira user creation via REST results in 401 - This resource requires WebSudo 。但是,就我而言,我想与 Java Http Client 连接。
我已经检查了文档并尝试:
将凭据放入 header
{ final String encoding = Base64.getEncoder().encodeToString((SERVICE_DESK_ADMIN + ":" + SERVICE_DESK_ADMIN_KEY).getBytes("UTF-8")); httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encoding); }
尝试实现此处描述的抢先授权:HttpClient Basic Authentication
在这两种情况下,我从服务器得到了相同的响应:
{
"message" : "This resource requires WebSudo.",
"status-code" : 401
}
在抢占式情况下,我在日志中发现了如下内容:
2020/03/03 16:41:45:774 CET [DEBUG] MainClientExec - Connection can be kept alive indefinitely
2020/03/03 16:41:45:774 CET [DEBUG] HttpAuthenticator - Authentication required
2020/03/03 16:41:45:774 CET [DEBUG] HttpAuthenticator - <here_is_address>:443 requested authentication
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, CredSSP, Digest, Basic]
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Challenge for Negotiate authentication scheme not available
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Challenge for Kerberos authentication scheme not available
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Challenge for NTLM authentication scheme not available
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Challenge for CredSSP authentication scheme not available
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Challenge for Digest authentication scheme not available
2020/03/03 16:41:45:774 CET [DEBUG] TargetAuthenticationStrategy - Challenge for Basic authentication scheme not available
我的问题是:
- 从日志中看,最后一行是否表明我的配置不起作用?
- 有人成功地使用 HTTP 客户端通过 REST API 将用户添加到服务台吗?
最佳答案
这是我的问题的答案:
- HTTP 客户端与我的问题无关
- 使用 HTTP 客户端在 JIRA 中创建用户有 2 种可能的解决方案:
- 非常难看 - 我注意到第一个创建用户的 Http post 返回了 cookies。现在,当获取这些 cookie 并将它们放入下一个 Http post 并将登录名更改为电子邮件时,将导致工作(用户将成功创建)。然而,正如我所说,它很丑陋,并且完全违背 REST 理念,因为 REST 应该是无状态的。
- 禁用 WebSudo - Disable WEBSUDO in Jira 。小警告,要使其正常工作,您必须重新启动 jira。
我选择了第二个解决方案,现在它的效果非常好。
关于java - Jira ServiceDesk 用户创建 - 此资源需要 WebSudo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60511082/