Пружинный привод / конечная точка отключения запрещены - PullRequest
0 голосов
/ 05 июня 2018

Мой первый проход с моим приложением Spring Boot привод был незащищенным, поэтому было легко отключить его дистанционно через конечную точку / actator / shutdown.Недавно я защитил свой привод с помощью системы безопасности Spring, и он сработал.Теперь мне нужно предоставить базовые учетные данные http для доступа к конечным точкам, но теперь вызовы curl для конечной точки / actator / shutdown завершаются с ошибкой Forbidden.У меня где-то должна быть неправильная конфигурация.

Моя команда curl:

curl -XPOST -u привод: пароль http://host:port/actuator/shutdown -k

Я могу вызвать другие конечные точки, кажется, только конечная точка выключения запрещена.

Моя конфигурация:

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.info.git.mode=full
management.endpoint.shutdown.enabled=true
management.server.port=8081
spring.security.user.name=actuator
spring.security.user.roles=ACTUATOR
spring.security.user.password=password

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

    @Configuration
public static class ActuatorWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
                .anyRequest().hasRole("ACTUATOR")
                .and()
                .httpBasic();
    }
}

Ответы [ 2 ]

0 голосов
/ 27 сентября 2018

У меня была такая же проблема.Независимо от того, что я сделал, привод / отключение будет запрещено.Ответ выше с http.csrf().disable(); был единственным, что сработало.Пожалуйста, найдите ссылку: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-security-csrf

package com.broadridge.services.calendar2.security;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;

@Configuration
public class ApiSecurity extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().
        requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests().anyRequest().permitAll();
}

}
0 голосов
/ 05 июня 2018

Решением было отключить csrf в методе настройки WebSecurityConfigureAdapter.

http.csrf().disable();
...