Spring Boot Management Port and Spring Security

雨燕双飞 提交于 2019-12-08 10:15:46

问题


I have a spring boot web application with security configurations to forward all unauthorized requests to /login. I set up a spring boot management port different from my application port. When I go to the management port and try to access /health, it tries to send me to /login on that port and I get this response:

''' {"timestamp":1435680239995,"status":404,"error":"Not Found","message":"No message available","path":"/login"} '''

I found this question but I couldn't make it work in my application: Spring Boot Management security works differently with port set

What's the right way of making this pretty basic Spring Security config work with Spring Boot when trying to set a separate management port??

Here is the pertinent part of my spring security configs:

```

@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
    http
        .csrf().disable()       //temporary
        .authorizeRequests()
        .antMatchers("/public/**").permitAll()
        .antMatchers("/private*/**").access("hasRole('ADMIN')")
        .antMatchers("/**").access("hasRole('USER')");

    http
      .formLogin().failureUrl("/login?error")
      .defaultSuccessUrl("/")
      .loginPage("/login")
      .permitAll()
      .and()
      .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login")
      .permitAll();
}
}

```

Thank you!

UPDATE:

I couldn't make the solution above to work but I found a workaround by putting my management endpoints under what spring security thinks is the public (permitAll) route. Then exposed that behind a different port. This works for my purposes which was to be able to expose a health check to my ELB on a port that is only exposed to the ELB.

management: port: 8081 context-path: /public security: enabled: false

来源:https://stackoverflow.com/questions/31143703/spring-boot-management-port-and-spring-security

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!