Spring Security блокирует исходящие запросы. Время соединения истекло - PullRequest
0 голосов
/ 06 марта 2019

Я использую Spring security в своем приложении и вижу, что Spring Security блокирует некоторые исходящие запросы

Мой весенний конфиг выглядит следующим образом:

    @Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
                .and()
                .formLogin()
                .failureHandler(authenticationFailureHandler())
                .and()
                .httpBasic()
                .and()
                .antMatcher("/**");
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }

    @Bean
    public AuthenticationFailureHandler authenticationFailureHandler() {
        return new SimpleUrlAuthenticationFailureHandler();
    }

    @Bean
    public LogoutSuccessHandler logoutSuccessHandler() {
        return new SimpleUrlLogoutSuccessHandler();
    }

}

Я вижу, что мой запрос на отдых обслуживаетответьте

 I/O error on POST request for "https://someserver.com/api/v1/public/createUser": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect

Когда я пытаюсь вызвать эти службы отдыха без Spring Security (Spring Spring отключена), он работает нормально.

Вот мой конфиг, если RestTemplate

 public CustomRestTemplateContructor() {
        super();
        this.restTemplate = new RestTemplate();
        this.restTemplate.getMessageConverters().add(0, new 
        StringHttpMessageConverter(Charset.forName("UTF-8")));
    }

Класс, в котором у меня есть собственная реализация RestTemplate, выглядит следующим образом:

@Configurable
public abstract class CustomRestTemplateContructor extends TestDataBase implements Runnable  {


    public static final Logger log = LoggerFactory.getLogger(CustomRestTemplateContructor.class);

    private String testEnviroment;

    @Autowired
    private ITestDataService iTestDataService;

    private static final Object lockForAddingValueToSharedStorage = new Object();

    private String name;
    private String profileId;
    private final RestTemplate restTemplate;


    protected ThreadLocal<WorkerExecutionStatusThreadLocal> workerExecutionStatus = new ThreadLocal<>();



    public CustomRestTemplateContructor() {
        super();
        this.restTemplate = new RestTemplate();
        this.restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    }


    public ITestDataService getiTestDataService() {return iTestDataService; }
    public void setiTestDataService(ITestDataService iTestDataService) { this.iTestDataService = iTestDataService; }

    public String getTestEnviroment() { return testEnviroment; }
    public void setTestEnviroment(String testEnviroment) { this.testEnviroment = testEnviroment; }

    public void setName(String name) {
        this.name = name;
    }
    public String getName() { return name; }

    public String getProfileId() {
        return profileId;
    }
    public void setProfileId(String profileId) {
        this.profileId = profileId;
    }

    public RestTemplate getRestTemplate() { return restTemplate; }

Затем я расширяю свой CustomRestTemplateContructor, чтобы получить функциональность Spring RestTemplate и другие дополнительные функции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...