使用 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,错误:请求中缺少必需的令牌)