Spring boot 2, включающий незащищенную конечную точку / работоспособность - PullRequest
0 голосов
/ 25 февраля 2019

У меня есть проект Spring Boot 2 с аутентификацией клиента и сервера, и я пытаюсь предоставить только конечную точку /actuator/health, поэтому для нее не требуется аутентификация.

Моя первоначальная WebSecurityConfigurerAdapter была:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
    private void configureWithSsl(@NotNull HttpSecurity http) throws Exception {
        LOG.info("configuring access with ssl");
        http
                .csrf().disable()
                .authorizeRequests()
                .anyRequest().authenticated()
                .and().x509()
                .and().userDetailsService(userDetailsService());
    }
...
}

и application.yaml

server:
  port: 8443
  ssl:
    enabled: true
    key-store: 'paht/to/kestore/keystore.jks'
    key-store-password: 123456
    key-store-type: JKS
    client-auth: need
    trust-store: 'paht/to/truststore/truststore.jks'
    trust-store-type: JKS
    trust-store-password: 123456
    protocol: TLS
    enabled-protocols: TLSv1.2

Я пытался: 1. Настройка «канала» как небезопасного для конечной точки

    private void configureWithSsl(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .requiresChannel().requestMatchers(EndpointRequest.to("health")).requiresInsecure()
                .and()
                .authorizeRequests()
                .anyRequest().authenticated()
                .and().x509()
                .and().userDetailsService(userDetailsService());
    }
  1. добавить сопоставления в конечную точку:
    private void configureWithSsl(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .requestMatchers(EndpointRequest.to("health")).permitAll()
                .anyRequest().authenticated()
                .and().x509()
                .and().userDetailsService(userDetailsService());
    }
  1. Добавить игнорирование в конечную точку:
@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().requestMatchers(EndpointRequest.to("health"));
}

Я пробовал все эти комбинации, и до сих порЯ получаю

curl -k  https://localhost:8443/actuator/health
curl: (35) error:1401E412:SSL routines:CONNECT_CR_FINISHED:sslv3 alert bad certificate
curl http://localhost:8443/actuator/health
Bad Request
This combination of host and port requires TLS.

Я хочу, чтобы только конечная точка работоспособности не была защищена, остальные конечные точки привода мне нужно было защитить, поэтому настройка management.server.ssl.enabled=false не решит проблему ...

РЕДАКТИРОВАТЬ:

Согласно ответу @Aritra Paul, я также пытался:

http
        .csrf().disable()
        .authorizeRequests()
        .antMatchers( "/actuator/health/**").permitAll()
        .antMatchers( "/**").authenticated()
        .and().x509()
        .and().userDetailsService(userDetailsService());

Но я все равно получаю тот же результат.

1 Ответ

0 голосов
/ 25 февраля 2019

Насколько я понимаю, вы хотите сделать actuator/health URL-адрес открытым для всех, а все остальные URL-адреса основаны на роли или авторизации.Если это так, вы можете попробовать, как показано ниже

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http
                .authorizeRequests()
                .antMatchers( "/actuator/health/**").permitAll()
                .antMatchers("/other-url/**").hasRole("your role")
                .authenticated();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...