Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot app - server context Path

I've generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.

Technologies used:

Spring Boot 2.0.0.M6 , Java 8, maven

Here my security config

   @Override
    protected void configure(HttpSecurity http) throws Exception {

        final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
        if (activeProfiles.contains("dev")) {
            http.csrf().disable();
            http.headers().frameOptions().disable();
        }

        http
                .authorizeRequests()
                .antMatchers(publicMatchers()).permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/iberia/list")
                .failureUrl("/login?error").permitAll()
                .and()
                .logout().permitAll();
    }

in my application.properties

server.contextPath=/iberiaWebUtils
server.port=1234

But when I run the app at http://localhost:1234/iberiaWebUtils, instead of going to http://localhost:1234/iberiaWebUtils/login, the app. redirects to http://localhost:1234/login

I also tried with

server.context-path=/iberiaWebUtils

with the same result

like image 370
en Lopes Avatar asked Dec 08 '22 16:12

en Lopes


2 Answers

Starting from Spring Boot 2.0.0 M1 servlet-specific server properties were moved to server.servlet:

enter image description here Spring Boot 2.0.0 M1 Release Notes

Therefore, you should use the server.servlet.context-path property.

like image 81
Andrew Tobilko Avatar answered Dec 29 '22 04:12

Andrew Tobilko


Try adding .loginProcessingUrl("/iberiaWebUtils/login") after loginPage("/login")

    http
            .authorizeRequests()
            .antMatchers(publicMatchers()).permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin().loginPage("/login")    
            .loginProcessingUrl("/iberiaWebUtils/login")
            .defaultSuccessUrl("/iberia/list")
            .failureUrl("/login?error").permitAll()
            .and()
            .logout().permitAll();
like image 22
Serg Vasylchak Avatar answered Dec 29 '22 03:12

Serg Vasylchak