SAP / cloud-security-services-integration-library

Integration libraries and samples for authenticating users and clients bound to XSUAA authentication and authorization service or Identity authentication service.
Apache License 2.0
151 stars 135 forks source link

How to call a RFC on premise destination without user login - 2 #215

Closed maxvader closed 4 years ago

maxvader commented 4 years ago

Hello, since [#212 ] is closed I start this new issue. I need to do what is done here: https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/bfcb54ca058f4b1dafd26e438ff1e2f4.html but not starting from a user request, instead to do the call upon application startup. Is it possibile? I don't even know who to ask, so I asked you, no one seems to know. I even asked the community with no result https://answers.sap.com/questions/12954366/cloud-foundry-call-on-premise-system-via-jco-witho.html The JCO always gives me that weird error "User information is not set." if I don't have a session created by the router, and I don't have it... Can I create a session somehow...?

nenaraab commented 4 years ago

Hi @maxvader

I have to admit, we are not the experts in using the Jco library so I have to check whether there is somebody how can answer your question here.

Best regards, Nena

maxvader commented 4 years ago

@nenaraab if you are able to find someone I can ask this, I will never be able to thank you enough :-)

Emdee89 commented 4 years ago

Dear @maxvader , pls provide the full stack trace of your JCO exception.

maxvader commented 4 years ago

@Emdee89 thank you for your interest. This is the error that happens when I call JCODestinationManager.getDestination("...) while not having a Spring Security Session. 2020-01-30T11:33:04.691+0000 [APP/PROC/WEB/0] ERR java.lang.IllegalStateException: User information is not set. 2020-01-30T11:33:04.691+0000 [APP/PROC/WEB/0] ERR at com.sap.xs.security.UserInfoHolder.getUserInfo(UserInfoHolder.java:48) 2020-01-30T11:33:04.691+0000 [APP/PROC/WEB/0] ERR at com.sap.core.connectivity.jco.kotyo.cf.auth.CFTenantProvider.getCurrentTenant(CFTenantProvider.java:21) 2020-01-30T11:33:04.691+0000 [APP/PROC/WEB/0] ERR at com.sap.conn.jco.rt.TenantContextManager.getTenantContext(TenantContextManager.java:36) 2020-01-30T11:33:04.691+0000 [APP/PROC/WEB/0] ERR at com.sap.conn.jco.rt.DefaultDestinationManager.searchDestination(DefaultDestinationManager.java:376) 2020-01-30T11:33:04.691+0000 [APP/PROC/WEB/0] ERR at com.sap.conn.jco.rt.DefaultDestinationManager.getDestinationInstance(DefaultDestinationManager.java:109) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:56) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at it.horsa.spo.ws.LoginService.login(LoginService.java:83) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at java.lang.reflect.Method.invoke(Method.java:498) 2020-01-30T11:33:04.692+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) 2020-01-30T11:33:04.693+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at com.sap.hcp.cf.logging.servlet.filter.RequestLoggingFilter.doFilterRequest(RequestLoggingFilter.java:123) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at com.sap.hcp.cf.logging.servlet.filter.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:74) 2020-01-30T11:33:04.694+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at it.horsa.spo.utils.CharsetFilter.doFilter(CharsetFilter.java:33) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.695+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) 2020-01-30T11:33:04.696+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:364) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:170) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) 2020-01-30T11:33:04.697+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:256) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:679) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 2020-01-30T11:33:04.698+0000 [APP/PROC/WEB/0] ERR at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 2020-01-30T11:33:04.699+0000 [APP/PROC/WEB/0] ERR at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 2020-01-30T11:33:04.699+0000 [APP/PROC/WEB/0] ERR at java.lang.Thread.run(Thread.java:836)

Emdee89 commented 4 years ago

Thanks for the stack trace, that explains few things to me. Can you pls confirm that you work on Cloud Foundry and not on the Neo landscape?

maxvader commented 4 years ago

Yes, this Is from Cloud Foundry. On Neo this problem does not exists

Emdee89 commented 4 years ago

Alright, thanks for clarifying. To my knowledge it is currently not possible to use JCO without a tenant context on Cloud Foundry.

maxvader commented 4 years ago

@Emdee89 and is It possible somehow to create one manually? I managed to create user tokens on the server by talking to the xuaa, but I didn't find a way to put them in the spring security context.... I think It should be possible, but I don't know how... It HAS to be possible because the library does it, I guess

nenaraab commented 4 years ago

@maxvader you can initialize the Spring security context the following way: https://github.com/SAP/cloud-security-xsuaa-integration/blob/master/spring-xsuaa/README.md#setup-security-context-for-non-http-requests

Then you can get the tenant information from the token, which is stored as part of the security context.

maxvader commented 4 years ago

@nenaraab thank you, sound like a solid lead, I'll try it soon !

maxvader commented 4 years ago

Too bad it didn't work, I tried this code, all seemed ok but always "User is not set" ` XsuaaTokenFlows tokenFlows = new XsuaaTokenFlows( new XsuaaOAuth2TokenService(new RestTemplate()), new XsuaaDefaultEndpoints("https://horsacf.authentication.eu10.hana.ondemand.com"), new ClientCredentials("XXXX", "XXXX"));

OAuth2TokenResponse clientCredentialsToken = tokenFlows.passwordTokenFlow() .username("XXXX") .password("XXXX") .execute();

SpringSecurityContext.init(clientCredentialsToken.getAccessToken(), jwtDecoder, new LocalAuthoritiesExtractor(xsuaaServiceConfiguration.getAppId())); JCoDestinationManager.getDestination("SPO"); `

nenaraab commented 4 years ago

Hi @maxvader can you please provide the "full" error log? and maybe the decoded clientCredentialsToken.getAccessToken as well... ( you can decode it on jwt.io for example)

maxvader commented 4 years ago

So, the header: { "alg": "RS256", "jku": "https://horsacf.authentication.eu10.hana.ondemand.com/token_keys", "kid": "key-id-1", "typ": "JWT" } payload: { "jti": "b1da74b0142a4ef3a36019aadb15613c", "ext_attr": { "enhancer": "XSUAA", "zdn": "horsacf" }, "xs.system.attributes": { "xs.rolecollections": [ "all", "Org Manager", "Space Manager", "Space Developer" ] }, "given_name": "Massimo", "xs.user.attributes": {}, "family_name": "Nanni", "sub": "c99b3302-aae5-40f5-a917-911f15c383cb", "scope": [ "salesportal-ws-scp-motovario!t11590.all", "openid" ], "client_id": "sb-salesportal-ws-scp-motovario!t11590", "cid": "sb-salesportal-ws-scp-motovario!t11590", "azp": "sb-salesportal-ws-scp-motovario!t11590", "grant_type": "password", "user_id": "c99b3302-aae5-40f5-a917-911f15c383cb", "origin": "ldap", "user_name": "massimo.nanni@horsa.it", "email": "massimo.nanni@horsa.it", "auth_time": 1580984048, "rev_sig": "1d7a07c0", "iat": 1580984049, "exp": 1581027249, "iss": "http://horsacf.localhost:8080/uaa/oauth/token", "zid": "ecd36baa-1ec4-4990-bbaa-6e0eebcd3892", "aud": [ "sb-salesportal-ws-scp-motovario!t11590", "openid", "salesportal-ws-scp-motovario!t11590" ] }

And the stack trace is always the same:

"written_at":"2020-02-06T10:37:23.274Z","written_ts":490852556321330,"tenant_id":"-","component_id":"d1d5f2ae-5102-48f3-bc24-959d1c83e7a1","DCComponent":"","component_name":"salesportal-ws-scp-motovario","organization_name":"-","component_type":"application","space_name":"Salesportal Dev","component_instance":"0","organization_id":"-","correlation_id":"4b1d1c28-efee-40e5-4197-2332e3149926","CSNComponent":"","Application":"salesportal-ws-scp-motovario","space_id":"61cb2bbc-c3ff-4465-bd53-a68673b20d95","request_id":"4b1d1c28-efee-40e5-4197-2332e3149926","container_id":"10.0.137.200","type":"log","logger":"it.horsa.spo.ws.exception.ExceptionControllerAdvice","thread":"http-nio-0.0.0.0-8080-exec-2","level":"ERROR","categories":[],"msg":"java.lang.IllegalStateException: User information is not set." }
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR java.lang.IllegalStateException: User information is not set.
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.security.UserInfoHolder.getUserInfo(UserInfoHolder.java:48)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.core.connectivity.jco.kotyo.cf.auth.CFTenantProvider.getCurrentTenant(CFTenantProvider.java:21)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.TenantContextManager.getTenantContext(TenantContextManager.java:36)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.DefaultDestinationManager.searchDestination(DefaultDestinationManager.java:376)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.DefaultDestinationManager.getDestinationInstance(DefaultDestinationManager.java:109)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:56)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at it.horsa.spo.ws.ProvaController.cicciotommaso(ProvaController.java:50)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at java.lang.reflect.Method.invoke(Method.java:498)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.hcp.cf.logging.servlet.filter.RequestLoggingFilter.doFilterRequest(RequestLoggingFilter.java:123)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.hcp.cf.logging.servlet.filter.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:74)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at it.horsa.spo.utils.CharsetFilter.doFilter(CharsetFilter.java:33)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:98)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:364)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:170)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
2020-02-06T10:37:23.276+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:256)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:679)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
2020-02-06T10:37:23.277+0000 [APP/PROC/WEB/0] ERR   at java.lang.Thread.run(Thread.java:836)
nenaraab commented 4 years ago

Hi @maxvader that's helpful! Sorry, I didn't recognized the stack above...

"written_at":"2020-02-06T10:37:23.274Z","written_ts":490852556321330,"tenant_id":"-","component_id":"d1d5f2ae-5102-48f3-bc24-959d1c83e7a1","DCComponent":"","component_name":"salesportal-ws-scp-motovario","organization_name":"-","component_type":"application","space_name":"Salesportal Dev","component_instance":"0","organization_id":"-","correlation_id":"4b1d1c28-efee-40e5-4197-2332e3149926","CSNComponent":"","Application":"salesportal-ws-scp-motovario","space_id":"61cb2bbc-c3ff-4465-bd53-a68673b20d95","request_id":"4b1d1c28-efee-40e5-4197-2332e3149926","container_id":"10.0.137.200","type":"log","logger":"it.horsa.spo.ws.exception.ExceptionControllerAdvice","thread":"http-nio-0.0.0.0-8080-exec-2","level":"ERROR","categories":[],"msg":"java.lang.IllegalStateException: User information is not set." }
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR java.lang.IllegalStateException: User information is not set.
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.security.UserInfoHolder.getUserInfo(UserInfoHolder.java:48)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.core.connectivity.jco.kotyo.cf.auth.CFTenantProvider.getCurrentTenant(CFTenantProvider.java:21)
2020-02-06T10:37:23.275+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.TenantContextManager.getTenantContext(TenantContextManager.java:36)

So, my assumption is now, that the connectivity lib (com.sap.core.connectivity.jco.kotyo.cf.auth.CFTenantProvider.getCurrentTenant) uses an internal xs security library version. The UserInfoHolder is not initialized with the information from the jwt token and returns this error.

@Emdee89 please setup a meeting with me, so that we can discuss, how integration could look like.

Many greetings! Nena

arkyn-tox commented 4 years ago

Hi, I'm having the same problem as @maxvader

Would it be possible to initialize the UserInfoHolder manually, e.g. with a token generated with client credentials?

I'm having troubles importing the UserInfoholder dependency to my project to try this out.

I'm using this dependency: `

com.sap.cloud.sjb xs-user-holder 1.11.0

`

But that gives me this maven error: Failed to collect dependencies at com.sap.cloud.sjb:xs-user-holder:jar:1.11.0: Failed to read artifact descriptor for com.sap.cloud.sjb:xs-user-holder:jar:1.11.0: Failure to find com.sap.ldi:ldi-parent:pom:7.3.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

arkyn-tox commented 4 years ago

Please note more people are having this issue. Please see comments to Alexander's answer: https://answers.sap.com/questions/12969692/getting-access-to-the-sap-java-connector-in-cloud.html

It is not possible to use the Java Connector outside the scope of a http request.

nenaraab commented 4 years ago

Hi @arkyn-tox this issue states that maven has tried and failed to download the dependency... You can do a forced mvn update: mvn install -U or delete the respective "com" directory located in .m2/repository folder...

babyboyface commented 4 years ago

Hi, I have the same issue. Has it been solved?

nenaraab commented 4 years ago

Dear @maxvader, @arkyn-tox, @babyboyface

I've searched internally and i hope that your issue matches this feature request.

Background

Currently JCo always will try to do a token exchange for the logged in user, and if it fails the whole scenario will fail. The idea is to do it differently in the future, and to do this only if there is one.

Next steps

arkyn-tox commented 4 years ago

That solution definitely sounds better than the current situation.

Ideally it would be possible to use JCo within an authToken context like AuthTokenAccessor.executeWithAuthToken(token, () -> { // JCo code... })

I can't access the ticket-site so I can't see if that is part of the proposed solution.