Spring-boot-admin: Redirect location after login with context-path is incorrect

Created on 18 Jul 2018  路  2Comments  路  Source: codecentric/spring-boot-admin

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();
    }
}
documentation

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 defaultTarget url via successHandler.setDefaultTargetUrl(adminContextPath + "/");

I've updated the samples.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikhalchenko-alexander picture mikhalchenko-alexander  路  3Comments

Docjones picture Docjones  路  5Comments

Nalha picture Nalha  路  5Comments

ctoestreich picture ctoestreich  路  5Comments

malijagadish picture malijagadish  路  5Comments