Spring-безопасность с Oauth2 и LDAP

В настоящее время мое веб-приложение без проблем работает с весенней загрузкой и безопасностью Spring, но мне нужно экспортировать аутентификацию службы отдыха с использованием Oauth2.

Когда пользователь получает доступ к моей веб-системе, он аутентифицируется с помощью формы входа в систему с безопасностью Spring и Active Directory.

Когда другая система пытается использовать нашу службу отдыха, я хотел бы использовать Oauth2 с той же Active Directory.

Как я могу это сделать? Моя конфигурация с входом в форму и Active Directory работает нормально, но мы не знаем, как пройти аутентификацию с помощью Oauth2.

Мой WebSecurityConfig:

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

    @Autowired
    private LogoutHandler logoutHandler;

    @Autowired
    private AuthenticationSuccessHandler authenticationSuccessHandler;

    @Autowired
    private AccessDeniedHandler accessDeniedHandler;

    @Autowired
    private AuthenticationFailureHandler authenticationFailureHandler;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .authorizeRequests()
            .antMatchers("/rest/public/**").permitAll()
            .and().csrf().ignoringAntMatchers("/rest/public/**").and()
        .authorizeRequests()
            .antMatchers("/public/**").permitAll()
            .antMatchers("/error/**").permitAll()
            .and()
        .authorizeRequests()
            .antMatchers("/adm/**").hasAnyRole(Role.ROOT,Role.ADM)
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .successHandler(authenticationSuccessHandler)
            .failureHandler(authenticationFailureHandler)
            .defaultSuccessUrl("/home",true)
            .permitAll()
            .and()
        .logout()
            .logoutSuccessUrl("/login")
            .permitAll()
            .addLogoutHandler(logoutHandler)
            .and()
         .exceptionHandling()
            .accessDeniedHandler(accessDeniedHandler);

    }
}

Как я могу вставить аутентификацию Oauth2 только для моих сервисов Rest (эта служба будет предоставляться по пути ../rest/serviceName


person Anderson Rossi    schedule 10.01.2016    source источник


Ответы (1)


Вам необходимо настроить другую цепочку фильтров для перехвата на вашем сервере ресурсов для защиты ваших конечных точек только через OAuth.

См. Мой ответ на аналогичный вопрос здесь

person ejazazeem    schedule 09.10.2018