Поставщик множественной аутентификации для определенного URL - Spring Boot Security - PullRequest
1 голос
/ 18 марта 2019

В безопасности Spring я хочу использовать обычную аутентификацию для URL, начинающуюся с api / ** LDAP Rest Authentication для URL, начинающуюся с / ldap / .Текущий код, который я имею, также позволяет ldap / с базовой аутентификацией.

Вопрос возникает, даже если я использую их в качестве отдельных провайдеров аутентификации, таких как LdapAuthProvider и BasicAuthProvider, как я могу использовать их для указания на конкретные URL-адреса

    @Configuration
    @EnableWebSecurity    
    public class WebSecurityConfig {


        @Configuration
        @Order(1)
        public class BasicAuthenticationProvider extends WebSecurityConfigurerAdapter {


            @Override
            protected void configure(HttpSecurity http) throws Exception {
                http.authorizeRequests().antMatchers("/swagger-ui*", "/info", "/health").permitAll()
                .and().authorizeRequests().antMatchers("/order/**").fullyAuthenticated()
                .and().httpBasic().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().csrf().disable()
                .anonymous().disable();
            }

            @Override
            protected void configure(AuthenticationManagerBuilder auth) throws Exception {
                auth.userDetailsService(inMemoryUserDetailsManager());
            }
        }

        @Configuration
        @Order(2)
        public class LdapAuthenticationProvider extends WebSecurityConfigurerAdapter {


            @Override
            protected void configure(HttpSecurity http) throws Exception {
                http.authorizeRequests().antMatchers("/ldap/**").fullyAuthenticated().and().httpBasic()
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf().disable();            
            }

            @Override
            protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.ldapAuthentication() code here......
            }      
        }    
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...