confluence REST API request while not being admin ends in 401 error

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

i am developing confluence blueprint where a user can choose between jira projects and use them for specific jira issues report.

both instances are connected correctly with each other and i get results but only if i am logged as an admin. with normal user i am getting this:

<status>    <status-code>401</status-code>    <message>This resource requires WebSudo.</message> </status>

unfortunately i have to get the information from the jira server as ajax post request with javascript and here is my code:

i have tried to use login information with basic authentication in ajax but it didnt help. of course i can hardcode the id in the code but what if it get changed? its not the best solution imo. how can i manage the websudo problem?

thank you and i wish you merry xmas and a happy new year.

回答1:

I'm new here (as a contributor) so pardon my newbie bloopers.

Looks like accessing /rest/applinks/1.0/applicationlink/type/jira indeed requires admin permissions. But there's an undocumented (AFAIK) workaround and this is how I do it.

There's an Atlassian plugin called Confluence JIRA Plugin. It's bundled with Confluence (hence it should be available in your installation). It provides you with a few cool features allowing JIRA integration (e.g. JIRA and JIRA Chart macros). To provide the integration it also adds a few useful endpoints to your Confluence REST API (which don't require admin access):

  1. /rest/jiraanywhere/1.0/servers or /rest/jira-integration/1.0/servers to list the linked JIRA servers (inlcuding applink id)
  2. /jira-integration/1.0/servers/{INSERT APPLINK ID HERE}/projects to list JIRA projects available to the logged-in user

Now, per your requirements, I'd hit 1. to get the applink id and then 2. to get the list of the projects. Hope it works with your product versions.

BONUS - JIRA Proxy

Another nice endpoint is /plugins/servlet/applinks/proxy. It allows forwarding simple REST requests to the linked JIRA instances. For example /plugins/servlet/applinks/proxy?appId={INSERT APPLINK ID HERE}&path=%2Frest%2Fapi%2F2%2Fsearch will call JIRA's issue search REST endpoint and list issues available to the user (as in JIRA search). By "simple request" I mean that only GET and POST HTTP methods are supported in the current version (with POST limited to application/xml and multipart/form-data content types). The servlet supports both query-string and HTTP-header parameters. Check out the source of the servlet in plugin's source to get more info as I haven't found any online documentation for it.

Using this servlet you can get the projects list as well by requesting /plugins/servlet/applinks/proxy?appId={INSERT APPLINK ID HERE}&path=%2Frest%2Fapi%2F2%2Fproject

Servlets's path in the repo is confluence-jira-plugin/src/main/java/com/atlassian/confluence/plugins/jira/AppLinksProxyRequestServlet.java, but most of the important stuff is in its base class confluence-jira-plugin/src/main/java/com/atlassian/confluence/plugins/jira/AbstractProxyServlet.java



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!