1

使用 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/governance/apimgt/applicationdata/customdata/somedata,响应状态:403,响应类型:CLIENT_ERROR at org.wso2.carbon.registry.app.RemoteRegistry.put(RemoteRegistry.java:543) at 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:/registry/atom/_system/governance /apimgt/applicationdata/customdata/somedata,错误:请求中缺少必需的令牌)

4

3 回答 3

1

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

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

于 2016-08-22T17:10:58.467 回答
0

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

于 2016-08-22T03:20:02.490 回答
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 给出 403 Forbidden

于 2016-08-22T15:37:34.483 回答