1

I am trying to login to the client UI through zuul api-gateway. I have two modules api-gateway running on port 8000(i.e http://localhost:8000) and erp-service running on 8010 port(i.e http://localhost:8010)

Following configuration I have added in api-gateway application.yml

zuul:  
  sensitive-headers: Cookie,Set-Cookie
  ignoredServices: '*' 
  admin-services:
    path: /_v/**
    sensitiveHeaders: Cookie,Set-Cookie
    serviceId: erp-service
    stripPrefix: false

and in erp-service application.yml

server:
   port: 8010
   servlet:
     contextPath: /_v

I am using spring security formLogin and login page feature. below is my spring security configuration

@Configuration
@EnableWebSecurity
@EnableScheduling
public class SpringSecurtiyConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AccessDeniedHandler accessDeniedHandler;

    @Autowired
    private AlphaUserDetailsService userDetailsService;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;


    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/bootstrap/**").antMatchers("/dist/**").antMatchers("/plugins/**");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().antMatchers("/bootstrap/**").permitAll().antMatchers("/dist/**").permitAll()
                .antMatchers("/install/role").permitAll().antMatchers("/plugins/**").permitAll().antMatchers("/login").permitAll()
                .anyRequest().authenticated().and().csrf().disable()
                .formLogin().loginPage("/login").failureUrl("/login?error=true")
                .defaultSuccessUrl("/home", true)
                .usernameParameter("email").passwordParameter("password")
                .and()
                .logout().permitAll().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/")
                .invalidateHttpSession(true).deleteCookies("JSESSIONID").and().exceptionHandling()
                .accessDeniedPage("/access-denied").accessDeniedHandler(accessDeniedHandler);
        http.headers().frameOptions().sameOrigin();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
    }

}

and Controller

@Controller
public class RootController {

    @GetMapping(value = {"/", "/login"})
    public String getLandingPage() {        
        if(!SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(AlphaConstants.ANONYMOUS_USER)) {  
            return "redirect:/home";
        }
        return "login";
    }

    @GetMapping(value = "/home")
    public String getHomePage() {
        if(!SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(AlphaConstants.ANONYMOUS_USER)) {
            return "home";
        }
        return "login";
    }
}

I am able to load the login page in browser http://localhost:8000/_v/login

after entering credentials and click login the url in browser http://localhost:8000/_v/login is changing to http://localhost:8010/_v/login which is erp-service url but I want to it should be remain to api-gateway url with home page like http://localhost:8000/_v/home

I had gone through below links but it did not worked for me.
Zuul Routing on Root Path
Spring Cloud: default redirecting from Gateway to UI
https://github.com/spring-cloud/spring-cloud-netflix/issues/2787

No error in development tool console.
please help.

Ganaraj
  • 11
  • 3

0 Answers0