简体   繁体   中英

Get Credentials from Current User in Atlassian Plugin

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.

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, eg:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM