Atlassian Confluence插件之间的通信/认证

问题描述 投票:2回答:1

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

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

鉴于用户已经使用Confluence进行了身份验证,有没有办法将我当前的用户凭据从我的插件Java Rest客户端传递给另一个,最好不使用基本身份验证?

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

  1. 共享访问层 - 这显然用于使用方法Request#addTrustedTokenAuthentication()但在SAL 3.0.5中已弃用,请参阅SAL Documentation (outdated?)SAL Version Matrix
  2. ApplicationLink - 允许我链接到另一个应用程序,但显然无法链接回同一个Confluence实例
  3. SAL TrustedRequestFactory-对这个atlassian answer的评论表明可能有一种方法使用它,但我似乎无法弄明白(还)。
  4. 我也尝试阅读atlassian文档并在atlassian答案here上发布了类似的问题。我不是故意双重发帖,但不幸的是,在该平台上查看其他问题,很少有人及时得到答复,所以我想我会在这里试试运气。
java rest plugins confluence
1个回答
2
投票

似乎这不是一个非常普遍的问题,但我想我会发布我们最终如何解决这个问题,以防万一它再次需要:

@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();
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.