问题
is it possible to get Username and Password in a Confluence Plugin? The Usernam works for me like this:
ApplicationUser user = userUtil.getUserByName(userManager.getRemoteUsername(request));
I want to connect to the Jira Rest Api with the current User.
回答1:
As @Philipp Sander already commented, it is not possible to retrieve the user's password. Confluence only stores passwords in an encrypted way, so it doesn't even know user passwords.
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.
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:
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, e.g.:
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. JIRA.
For more info, you can also check the SAL API documentation which has an example about how to use a RequestFactory.
There's also this useful related question on Atlassian Community that explains how you can get a RequestFactory to marshall objects using JAXB.
来源:https://stackoverflow.com/questions/45140653/get-credentials-from-current-user-in-atlassian-plugin