插件之间的 Atlassian Confluence communication/authentication

Atlassian Confluence communication/authentication between plugins

我正在(新手)开发一个宏插件,该插件基于现有插件通过其 REST API 提供的数据。他们将 运行 在 Confluence 的同一个实例上,版本 5.9。

我无法使用插件的 Java API,因为它只提供非常有限的访问 类,所以我决定使用 Rest。

鉴于用户已经通过 Confluence 进行了身份验证,是否有任何方法可以将我当前的用户凭据从我的插件 Java Rest 客户端传递给另一个客户端,最好不要使用基本身份验证?

到目前为止,我已经尝试过:

  1. 共享访问层 - 这显然用于使用方法 Request#addTrustedTokenAuthentication() 但在 SAL 3.0.5 中已弃用, 参见 SAL Documentation (outdated?), and SAL Version Matrix

  2. ApplicationLink - 允许我 link 到另一个应用程序,但显然不可能 link 回到同一个 Confluence 实例

  3. SAL TrustedRequestFactory- 对此 atlassian answer 的评论表明可能有使用它的方法,但我似乎无法弄清楚(还)。

  4. 我也尝试阅读 atlassian 文档并post在 atlassian answers here 上提出了一个类似的问题。我并不是要加倍 post,但不幸的是,在该平台上查看其他问题时,似乎很少有人能及时得到答复,所以我想在这里试试运气。

这似乎不是一个很常见的问题,但我想我会 post 我们最终是如何解决这个问题的,以防再次需要它:

@Component
public class RestClient {

    @ComponentImport
    private TrustedTokenFactory tokenFactory;

    // [...]
    public String doRequest(HttpClient client, String url) throws Exception {
        TrustedTokenAuthenticator auth = 
           new TrustedTokenAuthenticator(tokenFactory);
        HttpMethod method = auth.makeMethod(client, url);
        try {
             // add request headers, etc... 
             int statusCode = client.executeMethod(method);   
             // be sure to use response data here, catch exceptions...   
        } finally {
             method.releaseConnection();
        }
    }
}