Настройте Spring Security, чтобы разрешить связывание запросов

#spring #spring-security #spring-security-oauth2

#spring #spring-безопасность #spring-security-oauth2

Вопрос:

У меня есть эти ссылки, которые я хотел бы использовать для получения данных без аутентификации:

 GET http://localhost:8080/web_payment/wpf/3jeglsv7e5umcmz7e4b9wa6tq61v3q7a

POST http://localhost:8080/web_payment/en/payment/1234566666
  

Я пытался использовать эту конфигурацию Spring Security:

 @Configuration
@EnableWebSecurity
@Import(value = { Application.class, ContextDatasource.class })
@ComponentScan(basePackages = { "org.datalis.web.payment.server.*" })
public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private RestAuthEntryPoint authenticationEntryPoint;

    @Autowired
    MerchantAuthService myUserDetailsService;

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

    @Bean
    public DaoAuthenticationProvider authenticationProvider() {
        DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
        authenticationProvider.setUserDetailsService(myUserDetailsService);
        authenticationProvider.setPasswordEncoder(passwordEncoder());
        return authenticationProvider;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/*/payment/*").permitAll().anyRequest().permitAll();
        http.authorizeRequests().antMatchers("/wpf/*").permitAll().anyRequest().permitAll();
        http.httpBasic().authenticationEntryPoint(authenticationEntryPoint);
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
        http.csrf().disable();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }
}
  

Но когда я делаю запрос GET на http://localhost:8080/web_payment/wpf/3jeglsv7e5umcmz7e4b9wa6tq61v3q7a

Я получаю

 <?xml version='1.0' encoding='UTF-8'?>
<Map>
    <timestamp>1552646237152</timestamp>
    <status>401</status>
    <error>Unauthorized</error>
    <message>Unauthorized</message>
    <path>/web_payment/wpf/3jeglsv7e5umcmz7e4b9wa6tq61v3q7a</path>
</Map>
  

Знаете ли вы, какую конфигурацию мне нужно применить, чтобы применить доступ только к этим ссылкам?

Комментарии:

1. повторно проверьте синтаксис antmatchers. Я думаю, что проблема заключается в этом

2. Вы уверены, что ваша конфигурация выполнена? Добавьте точку останова в свой код и посмотрите, достигнута ли она.