user2800089
user2800089

Reputation: 2391

Spring security 5.0 : spring security savedrequest is null

I have a spring boot client application where I am using spring-boot-starter-oauth2-client and spring-boot-starter-security. Same application is working well in one environment, however after deploying in another environment , I can see spring security saved request is null and that's why it's keep on redirecting to login page.

After enabling spring security debug log , I can see that authentication is successful & user details are retrieved. However, it's keep on redirecting to "/" because spring security saved request is null.

I am clueless to understand where is the issue , how come it's able to save request in one environment and not in another. Where should I start looking? Any help would be highly appreciated.

DEBUG LOG WHERE APPLICATION IS NOT GETTING REDIRECTED

{"timestamp":"2021-05-12T17:24:40.918+10:00","app":"my-protected-application","logLevel":"INFO","thread":"http-nio-8080-exec-1","eventSource":"org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]","message":"Initializing Spring DispatcherServlet 'dispatcherServlet'"}
{"timestamp":"2021-05-12T17:24:41.104+10:00","app":"my-protected-application","traceId":"2efe5d4e6d04f787","spanId":"2efe5d4e6d04f787","logLevel":"DEBUG","thread":"http-nio-8080-exec-1","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/actuator/health/readiness'; against '/actuator/info'"}
{"timestamp":"2021-05-12T17:24:41.112+10:00","app":"my-protected-application","traceId":"2efe5d4e6d04f787","spanId":"2efe5d4e6d04f787","logLevel":"DEBUG","thread":"http-nio-8080-exec-1","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/actuator/health/readiness'; against '/actuator/health/readiness'"}
{"timestamp":"2021-05-12T17:24:41.112+10:00","app":"my-protected-application","traceId":"2efe5d4e6d04f787","spanId":"2efe5d4e6d04f787","logLevel":"DEBUG","thread":"http-nio-8080-exec-1","eventSource":"org.springframework.security.web.FilterChainProxy","message":"/actuator/health/readiness has an empty filter list"}
{"timestamp":"2021-05-12T17:24:55.666+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/oauth2/authorization/my-protected-application'; against '/actuator/info'"}
{"timestamp":"2021-05-12T17:24:55.666+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/oauth2/authorization/my-protected-application'; against '/actuator/health/readiness'"}
{"timestamp":"2021-05-12T17:24:55.666+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/oauth2/authorization/my-protected-application'; against '/actuator/health/liveness'"}
{"timestamp":"2021-05-12T17:24:55.668+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.FilterChainProxy","message":"/oauth2/authorization/my-protected-application at position 1 of 14 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'"}
{"timestamp":"2021-05-12T17:24:55.670+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.FilterChainProxy","message":"/oauth2/authorization/my-protected-application at position 2 of 14 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'"}
{"timestamp":"2021-05-12T17:24:55.670+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.context.HttpSessionSecurityContextRepository","message":"No HttpSession currently exists"}
{"timestamp":"2021-05-12T17:24:55.670+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.context.HttpSessionSecurityContextRepository","message":"No SecurityContext was available from the HttpSession: null. A new one will be created."}
{"timestamp":"2021-05-12T17:24:55.673+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.FilterChainProxy","message":"/oauth2/authorization/my-protected-application at position 3 of 14 in additional filter chain; firing Filter: 'HeaderWriterFilter'"}
{"timestamp":"2021-05-12T17:24:55.674+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.FilterChainProxy","message":"/oauth2/authorization/my-protected-application at position 4 of 14 in additional filter chain; firing Filter: 'LogoutFilter'"}
{"timestamp":"2021-05-12T17:24:55.674+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.OrRequestMatcher","message":"Trying to match using Ant [pattern='/logout', GET]"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/oauth2/authorization/my-protected-application'; against '/logout'"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.OrRequestMatcher","message":"Trying to match using Ant [pattern='/logout', POST]"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Request 'GET /oauth2/authorization/my-protected-application' doesn't match 'POST /logout'"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.OrRequestMatcher","message":"Trying to match using Ant [pattern='/logout', PUT]"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Request 'GET /oauth2/authorization/my-protected-application' doesn't match 'PUT /logout'"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.OrRequestMatcher","message":"Trying to match using Ant [pattern='/logout', DELETE]"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Request 'GET /oauth2/authorization/my-protected-application' doesn't match 'DELETE /logout'"}
{"timestamp":"2021-05-12T17:24:55.675+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.OrRequestMatcher","message":"No matches found"}
{"timestamp":"2021-05-12T17:24:55.676+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.FilterChainProxy","message":"/oauth2/authorization/my-protected-application at position 5 of 14 in additional filter chain; firing Filter: 'OAuth2AuthorizationRequestRedirectFilter'"}
{"timestamp":"2021-05-12T17:24:55.676+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/oauth2/authorization/my-protected-application'; against '/oauth2/authorization/{registrationId}'"}
{"timestamp":"2021-05-12T17:24:55.676+10:00","app":"my-protected-application","traceId":"9681ad4d267d4beb","spanId":"9681ad4d267d4beb","logLevel":"DEBUG","thread":"http-nio-8080-exec-2","eventSource":"org.springframework.security.web.util.matcher.AntPathRequestMatcher","message":"Checking match of request : '/oauth2/authorization/my-protected-application'; against '/oauth2/authorization/{registrationId}'"}

Upvotes: 1

Views: 1258

Answers (1)

changuk
changuk

Reputation: 181

Did you call the login URL directly instead of trying to login through the login page?

Request data requested by the user is stored in requestCache. The request data stored here is savedRequest. Spring security redirects requestCache and savedRequest objects after user authentication.

SavedRequest must be null because there is no request data in the previous request if you are using the URL directly without using the login page.

You can try to log in from a login page or use Referrer header to get the page URL.

Upvotes: 1

Related Questions