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

[samples/spring-security-xsuaa-usage] - HXE - Cannot verify with online token key, jku, kid, uaadomain is null #189

Closed markuslorenzgmx closed 4 years ago

markuslorenzgmx commented 4 years ago

I'm not sure if this should work or if this is the right place. But I have tried to run the spring-security-xsuaa-usage on my local HXE environment. Instead of "cf create-service xsuaa application xsuaa-authentication -c xs-security.json" I have created the xsuaa service by "xs create-service xsuaa default xsuaa-authentication -c xs-security.json". The deployment of the "spring-security-xsuaa-usage" app was also successful (also binding works). I have also received a token by calling this endpoint: https://hxehost:39032/uaa-security/oauth/token But if I call the "spring-security-xsuaa-usage" app with the received token, I get an error:

15.11.19 21:20:58.409 [APP/1-0] OUT org.springframework.security.oauth2.core.OAuth2AuthenticationException: JWT verification failed: Cannot verify with online token key, jku, kid, uaadomain is null 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.authenticate(JwtAuthenticationProvider.java:92) ~[spring-security-oauth2-resource-server-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175) ~[spring-security-core-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:124) ~[spring-security-oauth2-resource-server-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.debug.DebugFilter.invokeWithWrappedRequest(DebugFilter.java:90) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.web.debug.DebugFilter.doFilter(DebugFilter.java:77) [spring-security-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181] 15.11.19 21:20:58.409 [APP/1-0] OUT at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.27.jar:9.0.27] 15.11.19 21:20:58.409 [APP/1-0] OUT at java.lang.Thread.run(Thread.java:836) [na:1.8.0_181] 15.11.19 21:20:58.409 [APP/1-0] OUT Caused by: org.springframework.security.oauth2.jwt.JwtException: JWT verification failed: Cannot verify with online token key, jku, kid, uaadomain is null 15.11.19 21:20:58.409 [APP/1-0] OUT at com.sap.cloud.security.xsuaa.token.authentication.XsuaaJwtDecoder.decode(XsuaaJwtDecoder.java:92) ~[spring-xsuaa-2.2.0.jar:na] 15.11.19 21:20:58.409 [APP/1-0] OUT at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.authenticate(JwtAuthenticationProvider.java:89) ~[spring-security-oauth2-resource-server-5.2.0.RELEASE.jar:5.2.0.RELEASE] 15.11.19 21:20:58.409 [APP/1-0] OUT ... 55 common frames omitted 15.11.19 21:20:58.409 [APP/1-0] OUT

The error seems to be correct because the JWT does not contain the mentioned attributes.

nenaraab commented 4 years ago

@markuslorenzgmx why do you use the default xsuaa plan? This plan is only supported in context of XSA (on-premise).

markuslorenzgmx commented 4 years ago

I'm working on a software which must be able to run in an on-premise and also in the SAP Cloud Platform environment. Within on-premise environment, I have only the plans: default, devuser and space. On SCP: space, application, broker and apiaccess.

nenaraab commented 4 years ago

@markuslorenzgmx It seems to be a duplicate of this issue : https://github.com/SAP/cloud-security-xsuaa-integration/issues/187

Can you please check?

Best regards, Nena