汇总REST API请求而不是管理员以401错误结束 [英] confluence REST API request while not being admin ends in 401 error

查看:282
本文介绍了汇总REST API请求而不是管理员以401错误结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发汇流蓝图,用户可以在jira项目中进行选择并将其用于特定的jira问题报告。

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>

不幸的是我必须从jira服务器获取信息作为带javascript的ajax发布请求,这里是我的代码:

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

function pickDate(e, state) {
    AJS.$('#spLebenStart').datePicker({
        overrideBrowserDefault: true
    });

    getJiraUrl();
}

function getJiraUrl(){
    var appUrl = AJS.contextPath() + "/rest/applinks/1.0/applicationlink/type/jira";

    $.ajax({
        type: 'GET',
        url: appUrl,
        data: {
            key: "value"
        }, 
        dataType: "xml",
        success: function (xml){
            jiraID = $(xml).find("id").text();
        },
        complete: function(){
            getJiraProjects(jiraID);
        },
        error: function() {
            alert("ERROR @ getJiraUrl");
        }
    });
}

function getJiraProjects(applicationId){
    var restUrl = AJS.contextPath() + "/rest/applinks/1.0/entities/"+applicationId+"?os_authType=any";

    $.ajax({
        type: 'GET',
        url: restUrl,
        data: {
            key: "value"
        },
        dataType: "xml",
        success: function (xml){
            jiraProjectKeys = [];
            $(xml).find("entity").each(function(){
                jiraProjectKeys.push({id: $(this).attr("key"), text: $(this).attr("name")});
            });
        },
        crossDomain: true,
        xhrFields: {
            withCredentials: true
        },
        error: function() {
            alert("ERROR @ getJiraProjects");
        },
        complete: function(){
            AJS.$('#spSelect').auiSelect2({
                placeholder: 'Projekt auswählen...',
                data:jiraProjectKeys,
                multiple: false
            });
        }
    });
}

我试图在ajax中使用基本身份验证的登录信息,但它没有帮助。当然我可以在代码中硬编码id,但如果它被改变了怎么办?它不是最好的解决方案。我如何管理网络问题?

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.

推荐答案

我是新来的(作为贡献者)所以请原谅我的新手。

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

看起来像访问 /rest/applinks/1.0/applicationlink/type/jira 确实需要管理员权限。但是有一个未记录的(AFAIK)解决方法,我就是这样做的。

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.

有一个名为 Confluence JIRA插件的Atlassian插件。它与Confluence捆绑在一起(因此它应该在您的安装中可用)。它为您提供了一些允许JIRA集成的很酷的功能(例如JIRA和JIRA Chart宏)。为了提供集成,它还为Confluence REST API添加了一些有用的端点(不需要管理员访问权限):

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 /rest/jira-integration/1.0/servers 列出链接的JIRA服务器(包含applink id)

  2. /jira-integration/1.0/servers/ {INSERT APPLINK ID HERE} / projects 列出可用的JIRA项目登录用户

  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

现在,根据您的要求,我点击1.获取applink ID然后2。获取项目列表。希望它适用于您的产品版本。

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.

另一个不错的终点是 /插件/ servlet的/ applinks /代理。它允许将简单的REST请求转发到链接的JIRA实例。例如 / plugins / servlet / applinks / proxy?appId = {INSERT APPLINK ID HERE}& path =%2Frest%2Fapi%2F2%2Fsearch 将调用JIRA的问题搜索REST端点并列出用户可用的问题(如JIRA中所示)搜索)。通过简单请求我的意思是当前版本仅支持GET和POST HTTP方法(POST限于 application / xml multipart / form-data 内容类型)。 servlet支持query-string和HTTP-header参数。在插件的来源中查看servlet的来源,以获取更多信息,因为我没有找到了它的任何在线文档。

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.

使用这个servlet你也可以通过请求 / plugins / servlet / applinks / proxy来获取项目列表? appId = {INSERT APPLINK ID HERE}& path =%2Frest%2Fapi%2F2%2Fproject

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

Servlet在回购路径中的路径是 confluence-jira-plugin / src / main / java / com / atlassian / confluence / plugins / jira / AppLinksProxyRequestServlet.java ,但大部分重要内容都在其基类 confluence-jira-plugin / src / main / java / com / atlassian / confluence / plugins / jira / AbstractProxyServlet.java

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

这篇关于汇总REST API请求而不是管理员以401错误结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆