无法使用Java API将资源推送到WSO2 API Manager v2.0.0注册表

时间:2016-08-19 13:39:06

标签: wso2 wso2-am wso2greg api-manager

使用Java API将资源推送到APIM 2.0.0的注册表失败。

对APIM 1.10.0使用的相同代码成功。

要重现的示例代码是

    String tenantDomain = “mytenant.com"; 
    String url = "https://localhost:9443/t/"+tenantDomain+"/registry"; 
    String userName = “admin@mytenant.com"; 

    String password = “admin"; 

    System.setProperty("carbon.repo.write.mode", "true"); 


    //Get the file which needs to be added to the registry
    File file = new File(“/home/bob/Desktop/myPayload.json"); 
    RemoteRegistry remote_registry = new RemoteRegistry(new URL(url), userName, password); 

    //Import the file to config registry
    RegistryClientUtils.importToRegistry(file ,"/_system/config" ,remote_registry); 

    //Export  from registry 
    //RegistryClientUtils.exportFromRegistry(file ,"/_system/governance/SomePayload.json" ,remote_registry);

RegistryClientUtils.importToRegistry(file ,"/_system/config" ,remote_registry);的调用将失败。针对APIM 1.10.0运行的相同代码运行正常,因为它始终与其他产品(如ESB)一起使用。

典型的例外是:

  

引起:org.wso2.carbon.registry.core.exceptions.RegistryException:   添加资源失败。建议路径:   / _SYSTEM /管理/ apimgt /应用 - /的CustomData / somedata,   响应状态:403,响应类型:CLIENT_ERROR at   org.wso2.carbon.registry.app.RemoteRegistry.put(RemoteRegistry.java:543)     在   org.wso2.carbon.registry.core.utils.RegistryClientUtils.processImport(RegistryClientUtils.java:113)     在   org.wso2.carbon.registry.core.utils.RegistryClientUtils.processImport(RegistryClientUtils.java:102)     在   org.wso2.carbon.registry.core.utils.RegistryClientUtils.processImport(RegistryClientUtils.java:102)     在   org.wso2.carbon.registry.core.utils.RegistryClientUtils.processImport(RegistryClientUtils.java:102)     在   org.wso2.carbon.registry.core.utils.RegistryClientUtils.importToRegistry(RegistryClientUtils.java:65)

在APIM 2.0.0日志中,我们通常会看到

  

[2016-08-18 15:57:34,699]警告--JavaLogger潜在的跨站点   请求伪造(CSRF)攻击被挫败(用户:,   ip:127.0.0.1,方法:POST,   URI:/注册表/原子/ _SYSTEM /治理/ apimgt /应用 - 数据/的CustomData / somedata,   错误:请求中缺少必需的令牌)

3 个答案:

答案 0 :(得分:1)

APIM 2.0.0缺少CSRF配置中的一行。需要将注册表端点添加到为商店和发布者配置的端点。在" Owasp.CsrfGuard.Carbon.properties"中添加终点。在[APIM_HOME] / repository / conf / security目录中找到的文件。 在此文件的末尾,添加下面给出的行。

org.owasp.csrfguard.unprotected.registry =%参数servletContext%/吨/ *

答案 1 :(得分:0)

似乎API调用被CSRF过滤器阻止。您可以打开carbon.xml并将您正在使用的URL列入白名单,然后再次查看。

答案 2 :(得分:0)

尝试在 <APIM_HOME>/repository/conf/security/Owasp.CsrfGuard.Carbon.properties 文件的末尾添加以下行。

org.owasp.csrfguard.unprotected.reg=%servletContext%/registry/*

更新:由于JDK 1.8.0_151中的错误,会发生同样的错误。

请参阅wso2 api manger carbon page gives 403 Forbidden