[英]Get Credentials from Current User in Atlassian Plugin
is it possible to get Username and Password in a Confluence Plugin? 是否可以在Confluence插件中获取用户名和密码? The Usernam works for me like this:
Usernam像这样为我工作:
ApplicationUser user = userUtil.getUserByName(userManager.getRemoteUsername(request));
I want to connect to the Jira Rest Api with the current User. 我想用当前用户连接到Jira Rest Api。
As @Philipp Sander already commented, it is not possible to retrieve the user's password. 正如@Philipp Sander所说,无法检索用户的密码。 Confluence only stores passwords in an encrypted way, so it doesn't even know user passwords.
Confluence仅以加密方式存储密码,因此它甚至不知道用户密码。
However, since you're talking about a Confluence plugin, there is another way to talk to other Atlassian applications' REST APIs by using application links. 但是,由于您正在谈论Confluence插件,因此存在另一种使用应用程序链接与其他Atlassian应用程序的REST API进行通信的方法。
If you require users to configure an application link to JIRA in their Confluence, then your plugin can get that ApplicationLink instance using the ApplicationLinkService 's getApplicationLinks method: 如果您需要用户在其Confluence中配置指向JIRA的应用程序链接,则您的插件可以使用ApplicationLinkService的getApplicationLinks方法获取该ApplicationLink实例:
java.lang.Iterable<ApplicationLink> getApplicationLinks(java.lang.Class<? extends ApplicationType> type)
Retrieves all ApplicationLinks of a particular ApplicationType.
Next, you can call the createAuthenticatedRequestFactory method on your ApplicationLink instance, eg: 接下来,您可以在ApplicationLink实例上调用createAuthenticatedRequestFactory方法,例如:
ApplicationLinkRequestFactory createAuthenticatedRequestFactory()
The ApplicationLinkRequestFactory returned by this method will choose a single AuthenticationProvider for automatically authenticating created Request objects.
And the RequestFactory makes it possible to send REST requests to the application you're targetting, ie. 通过RequestFactory,可以将REST请求发送到您要定位的应用程序。 JIRA.
JIRA。
For more info, you can also check the SAL API documentation which has an example about how to use a RequestFactory . 有关更多信息,您还可以查看SAL API文档,其中包含有关如何使用RequestFactory的示例。
There's also this useful related question on Atlassian Community that explains how you can get a RequestFactory to marshall objects using JAXB. Atlassian社区中还有一个有用的相关问题 ,它解释了如何使用JAXB获取RequestFactory来编组对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.