I have spring boot application (frontend[using spring boot and thymeleaf] and backend[spring boot] separated) which uses authorization server. The frontend is authenticated and authorized by the auth server with a token. This token is used by the frontend to communicated to the backend.
The auth server when authenticating and authorizing the frontend ALWAYS forwards the request to the frontend dashboard with a token. This is main issue here, I don't have control over the auth server. How can I store the request URL (received by the frontend) before redirecting the request to the auth server authorization so that I can redirect the user to the correct URL and not always to the dashboard of the application.

Is there any way in spring boot to store the URL (step 1) and later when token is received from the auth server (step 3), use this token to communicate to the backend instead of always redirecting to the dashboard.
Please note as auth server out of my reach, I cannot make any changes to it. So when the auth server authorizes the request, it changes the url used by the user and always redirect to the dashboard.
I assuming you want to capture the URL in 1 to redirect after 5 completes instead of your standard page?
In spring you can do this with spring security with SavedRequestAwareAuthenticationSuccessHandler.
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/public-pages/**").permitAll()
.anyRequest().authenticated() // All other URLz req authentication
.and()
.formLogin()
.loginPage("/login") // <- your login page
.successHandler(savedRequestAwareAuthenticationSuccessHandler()) // this saves the previous url
.permitAll()
.and()
.logout()
.permitAll();
}
@Bean
public SavedRequestAwareAuthenticationSuccessHandler savedRequestAwareAuthenticationSuccessHandler() {
SavedRequestAwareAuthenticationSuccessHandler authSuccessHandler = new SavedRequestAwareAuthenticationSuccessHandler();
authSuccessHandler.setTargetUrlParameter("redirectTo");
return authSuccessHandler;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With