Конфигурация безопасности Spring Boot не работает - PullRequest
0 голосов
/ 04 апреля 2019

У меня есть два типа URL, один из которых защищен, а другой не защищен, например, регистрация и входи безопасность.

Ниже приведен мой код конфигурации безопасности, но он не работает.

  @EnableGlobalMethodSecurity(prePostEnabled = true)
  @EnableWebSecurity
  @Configuration
 public class AppSecurity extends WebSecurityConfigurerAdapter
 {

@Autowired
private CustomUserDetailsService userDetailsService;

@Autowired
TempTokenGenerator tempTokenGenerator;




  @Bean
   @Override
 public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {

     auth.userDetailsService(userDetailsService)
    .passwordEncoder(getPasswordEncoder());
}

public void configure(WebSecurity web) throws Exception {

    web.ignoring().antMatchers("notsecured/signin");
}



@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    http.authorizeRequests()

        .antMatchers("/","**secured/**").authenticated()

           .and().logout().permitAll()
           .and()
           .apply(new TempConfigurer(tempTokenGenerator));
 }

@Bean
CorsConfigurationSource corsConfigurationSource() {
  final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
  return source;
}

что мне не хватает?Что мне нужно сделать, чтобы включить «защищенные» URL-адреса в аутентификацию и фильтры, исключив «незащищенные» из аутентификации и фильтра.1014 *

 http.authorizeRequests() to make secured urls work.

и если я поставлю

.antMatchers("/","**/secured/**").authenticated()

с

.anyRequest().permitAll()

, это тоже не работает.

1 Ответ

0 голосов
/ 04 апреля 2019

используйте configure(HttpSecurity http) метод для защиты ваших конечных точек запроса

  http.csrf().disable()
        .cors().and()
        .authorizeRequests()
            .antMatchers("/notsecured/**").permitAll()
            .antMatchers("/secured/**").fullyAuthenticated()
        .and().sessionManagement...
        .and().formLogin()
         ...

используйте configure(WebSecurity web) метод для игнорирования статических ресурсов, таких как изображения, css, ...

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