When I configure the context-path after login in it does not redirect to the
host:port/context-path instead it stays at host:port
An example project is here:
https://github.com/altfatterz/spring-boot-admin
Using the following config:
spring:
security:
user:
name: admin
password: admin
boot:
admin:
context-path: /admin
And security configuration
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public WebSecurityConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
http.authorizeRequests()
.antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
.httpBasic()
.and()
.csrf().disable();
}
}
Thanks for providing the sample project!
This is primarily not a Spring Boot Admin issue, but as it's the code from the sample/docs I did take a look at it. The problem is the Spring Security configuration. You need to set the defaultTarget url via successHandler.setDefaultTargetUrl(adminContextPath + "/");
I've updated the samples.
Great! Thanks.
Most helpful comment
Thanks for providing the sample project!
This is primarily not a Spring Boot Admin issue, but as it's the code from the sample/docs I did take a look at it. The problem is the Spring Security configuration. You need to set the
defaultTargeturl viasuccessHandler.setDefaultTargetUrl(adminContextPath + "/");I've updated the samples.