簡體   English   中英

在Atlassian插件中從當前用戶獲取憑據

[英]Get Credentials from Current User in Atlassian Plugin

是否可以在Confluence插件中獲取用戶名和密碼? Usernam像這樣為我工作:

ApplicationUser user = userUtil.getUserByName(userManager.getRemoteUsername(request));

我想用當前用戶連接到Jira Rest Api。

正如@Philipp Sander所說,無法檢索用戶的密碼。 Confluence僅以加密方式存儲密碼,因此它甚至不知道用戶密碼。

但是,由於您正在談論Confluence插件,因此存在另一種使用應用程序鏈接與其他Atlassian應用程序的REST API進行通信的方法。

如果您需要用戶在其Confluence中配置指向JIRA的應用程序鏈接,則您的插件可以使用ApplicationLinkService的getApplicationLinks方法獲取該ApplicationLink實例:

java.lang.Iterable<ApplicationLink> getApplicationLinks(java.lang.Class<? extends ApplicationType> type) 

    Retrieves all ApplicationLinks of a particular ApplicationType.

接下來,您可以在ApplicationLink實例上調用createAuthenticatedRequestFactory方法,例如:

ApplicationLinkRequestFactory   createAuthenticatedRequestFactory() 

    The ApplicationLinkRequestFactory returned by this method will choose a single AuthenticationProvider for automatically authenticating created Request objects.

通過RequestFactory,可以將REST請求發送到您要定位的應用程序。 JIRA。

有關更多信息,您還可以查看SAL API文檔,其中包含有關如何使用RequestFactory的示例。

Atlassian社區中還有一個有用的相關問題 ,它解釋了如何使用JAXB獲取RequestFactory來編組對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM