Безопасность загрузки Spring, чтобы разрешить все конечные точки, кроме одной - PullRequest
1 голос
/ 20 июня 2020

Для проекта без пружинной защиты. Все контроллеры (GET / POST) проекта не защищены и не должны быть защищены. Но теперь у меня есть новый контроллер, и я хочу защитить его путь (/private), вложенные пути и параметры. Только этот единственный путь должен быть защищен с помощью Basi c Authentication. Почему мой код не работает?

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/**").permitAll()
                .antMatchers("/private**").hasAuthority("ADMIN").and().httpBasic();

    }
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("user")
                .password("{noop}pass")
                .roles("ADMIN");
    }

}

1 Ответ

1 голос
/ 20 июня 2020
        http.csrf()
                .disable()
            .authorizeRequests()
                .antMatchers("/private").hasRole("ADMIN")
                .antMatchers("/private/**").hasRole("ADMIN")
                .antMatchers("/**").permitAll()
                .and()
            .httpBasic();

или

        http.csrf()
                .disable()
            .authorizeRequests()
                .antMatchers("/private").hasRole("ADMIN")
                .antMatchers("/private/**").hasRole("ADMIN")
                .anyRequest().permitAll()
                .and()
            .httpBasic();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...