无法获取订户子帐户SAP Cloud Platform -CF

时间:2019-04-18 09:47:50

标签: java s4sdk sap-cloud-platform sap-cloud-sdk

在连接到本地部署的订阅者子帐户目标时遇到错误。通过连接服务和S4 SDK api从提供商帐户中的多租户应用程序中在Cloud Foundry中创建一个系统。 相同的安排可以正常工作,目标连接指向另一个与提供者子帐户连接的本地系统。

请参阅SAP帮助,该帮助显示连接服务具有开箱即用的内置能力: https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/9c0bdd0efc8640739c9d2fa5cfe56cbd.html

通过S4 SDK API从在提供商子帐户中运行的提供商SAAS应用程序访问订户子帐户目标时得到以下错误:

完成堆栈跟踪:

  

“ 2019-04-09T11:25:03.714 + 0000 [APP / PROC / WEB / 0] OUT {   “ write_at”:“ 2019-04-09T11:25:03.708Z”,“ writed_ts”:2225588987993569,“ component_type”:“ application”,“ component_id”:“ 212c1a7d-c897-4834-8f7c-6e2a3d6bfed3”,“ space_name” :“ Sandbox”,“ component_name”:“连接性”,“ component_instance”:“ 0”,“ organization_id”:“-”,“ correlation_id”:“-”,“ organization_name”:“-”,“ space_id”:“ f057513a-85e3-4229-b42f-f0fe7a058fa6“,” container_id“:” 10.0.75.11“,” type“:” log“,” logger“:” org.apache.catalina.core.ContainerBase。[Tomcat]。[localhost] ]。[/]。[dispatcherServlet]“,”线程“:” http-nio-8080-exec-6“,”级别“:” ERROR“,”类别“:[],” msg“:” Servlet.service ()用于在路径[]被抛出的上下文中的servlet [dispatcherServlet]   异常[请求处理失败;嵌套异常为   com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException:   com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException:   无法获取订户服务实例的目的地:未能   获取目标服务的访问令牌。如果您的申请是   在Cloud Foundry上运行,请确保同时绑定到   目的地服务以及授权和信任管理(xsuaa)   服务,并且您已经适当保护了您的应用程序或   将“ ALLOW_MOCKED_AUTH_HEADER”环境变量设置为true。   请注意,随着用户传播的身份验证类型,   例如,主体传播或OAuth2 SAML承载流需要   确保您保护应用程序安全,并且在使用   环境变量“ ALLOW_MOCKED_AUTH_HEADER”。如果您的申请   不在Cloud Foundry上运行,例如,在部署到   本地容器,请考虑声明“目的地”环境   变量以配置目标。   原因“,” stacktrace“:[” com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestDeniedException:   无法获取访问令牌:XSUAA服务拒绝了HTTP请求   状态401(未经授权)。请确保正确绑定您的   XSUAA服务实例的应用程序。请注意,此错误也可能   如果您使用的服务计划不适合您,则会发生   场景。如果您要在Cloud Foundry上构建SaaS应用程序,   创建XSUAA实例时,选择服务计划“应用程序”。   如果您正在构建应由其他用户使用的重用服务   应用程序,选择服务计划“经纪人”。”,“达”   com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequest.executeTokenRequest(TokenRequest.java:128)“,” tat   com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequest.requestTokenWithClientCredentialsGrant(TokenRequest.java:385)“,” tat   com.sap.cloud.sdk.cloudplatform.connectivity.XsuaaService.requestAccessToken(XsuaaService.java:156)“,” tat   com.sap.cloud.sdk.cloudplatform.connectivity.XsuaaService.getServiceToken(XsuaaService.java:216)“,” tat   com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.getAccessToken(DestinationServiceCommand.java:111)“,” tat   com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.run(DestinationServiceCommand.java:124)“,” tat   com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.run(DestinationServiceCommand.java:28)“,” tat   com.netflix.hystrix.HystrixCommand $ 2.call(HystrixCommand.java:302)“,” tat   com.netflix.hystrix.HystrixCommand $ 2.call(HystrixCommand.java:298)“,” tat   rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)“,” tat   rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)“,” tat   rx.Observable.unsafeSubscribe(Observable.java:10327)“,” tat   rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)“,” tat   rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)“,” tat   rx.Observable.unsafeSubscribe(Observable.java:10327)“,” tat   rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)“,” tat   rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)“,” tat   rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)“,” tat   rx.Observable.unsafeSubscribe(Observable.java:10327)“,” tat   rx.internal.operators.OperatorSubscribeOn $ SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)“,” tat   com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction $ 1.call(HystrixContexSchedulerAction.java:56)“,” tat   com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction $ 1.call(HystrixContexSchedulerAction.java:47)“,” tat   com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69)“,” tat   rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)“,” tat   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)“,”达   java.util.concurrent.FutureTask.run(FutureTask.java:266)“,” tat   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)“,” tat   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)“,”达   java.lang.Thread.run(Thread.java:836)“]} 2019-04-09T11:25:03.754 + 0000   [RTR / 5] OUT Connectivity-test.cfapps.eu10.hana.ondemand.com-   [2019-04-09T11:25:01.668 + 0000]“ GET / odata / UserDetails HTTP / 1.1” 500 0   1257“ https://.authentication.eu10.hana.ondemand.com/login”“ Mozilla / 5.0   (Windows NT 6.1; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)   Chrome / 73.0.3683.86 Safari / 537.36“”-“” 10.0.75.11:61046“   x_forwarded_for:“-” x_forwarded_proto:“ https”   vcap_request_id:“ eab68130-bfff-4cf2-733c-da051adfb1db”   响应时间:2.085981657   app_id:“ 212c1a7d-c897-4834-8f7c-6e2a3d6bfed3” app_index:“ 0”   x_correlationid:“ 8e2d22b0-b4c7-4d20-5461-600aea37b2d2”   x_b3_traceid:“ 7c4752638ec93577” x_b3_spanid:“ 7c4752638ec93577”   x_b3_parentspanid:“-” b3:“ 7c4752638ec93577-7c4752638ec93577”

请帮助。

谢谢, 悉达思

    if (TenantAccessor.getCurrentTenant().getTenantId().equals("<Subscriber tenet id>"))
            {
                final ErpConfigContext configContext = new ErpConfigContext("TEST_dest");

    else

    {
     < call provider destination using the above code with the destination belonging to Provider account >
    }

2 个答案:

答案 0 :(得分:2)

您是否已按照此处所述在应用程序中实现了订户回调服务? https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/ff540477f5404e3da2a8ce23dcee602a.html

更重要的一个是getDependencies回调(过程步骤2)。我知道它说是可选的,但是当使用目的地等服务时,这是必需的。需要这样,以便在订阅期间,SaaS Provisioning服务知道配置目标服务以授权订阅者帐户。

此外,如果之前未实现:在实现并重新部署应用程序之后,需要重新完成订阅过程,以使必要的配置生效。

答案 1 :(得分:1)

要实现此目的,您需要返回目标服务的xsappname作为getDependecies回调中的依赖项(如下所示)

@GetMapping(value = "/callback/v1.0/dependencies")
        public List<DependantServiceDto> callbackGet() {
            String logMessage = "callback service successfully called with RequestMethod = GET for tenant ";
            //logger.info(logMessage);
            List<DependantServiceDto> dependenciesList = new ArrayList<>();
            JSONObject vcap;
            String destinationXsAppName = "";
            try {
                vcap = new JSONObject(System.getenv("VCAP_SERVICES"));
                JSONArray arr = vcap.getJSONArray("destination");
                JSONObject credentials = arr.getJSONObject(0).getJSONObject("credentials");
                destinationXsAppName = credentials.getString("xsappname");
                if(!destinationXsAppName.isEmpty()){
                    dependenciesList.add(new DependantServiceDto(destinationXsAppName));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return dependenciesList;
        }

请记住,如果已经完成,请再次进行订阅。

完成后,您可以使用目标用户的子域和凭据(客户端ID和机密)来生成承载。

  

https://subacriber-subdomain.authentication.sap.hana.ondemand.com/oauth/token?grant_type=client_credentials&response_type=token

将Bearer令牌传递到目标服务API,以读取订户帐户目标。

  

https://destination-configuration.cfapps.sap.hana.ondemand.com/destination-configuration/v1/destinations/destinationName