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



使用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 applicationdata/customdata/somedata,响应状态:403,响应类型:CLIENT_ERROR atorg.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] WARN - JavaLogger潜在的跨站点请求伪造(CSRF)攻击被挫败(user:,知识产权:127.0.0.1,方法:,uri:/注册/atom/_system/管理/apimgt/applicationdata/customdata/somedata,错误:请求中缺少所需的令牌)

APIM 2.0.0在CSRF配置中缺少一行。需要将注册中心端点添加到为存储和发布者配置的注册中心端点中。在"Owasp.CsrfGuard.Carbon"中添加端点。在[APIM_HOME]/repository/conf/security目录中找到的文件。在该文件的末尾,添加如下所示的行:

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

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

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

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

更新:由于JDK 1.8.0_151中的一个错误,会出现相同的错误。

参见wso2 api manager carbon page给出的403 Forbidden

最新更新