使用Oauth2和LDAP的Spring安全性

使用Oauth2和LDAP的Spring安全性,spring,oauth-2.0,spring-boot,spring-security-oauth2,Spring,Oauth 2.0,Spring Boot,Spring Security Oauth2,现在,我的web应用程序使用spring引导和spring安全性没有问题,但我需要使用Oauth2导出rest服务身份验证 当用户访问我的web系统时,他将通过使用spring security和Active Directory的表单登录进行身份验证 当另一个系统尝试使用我们的Rest服务时,我希望将Oauth2与相同的Active Directory一起使用 我该怎么做?我的带有表单登录和Active directory的配置工作正常,但我们不知道如何使用Oauth2进行身份验证 我的Web安

现在,我的web应用程序使用spring引导和spring安全性没有问题,但我需要使用Oauth2导出rest服务身份验证

当用户访问我的web系统时,他将通过使用spring security和Active Directory的表单登录进行身份验证

当另一个系统尝试使用我们的Rest服务时,我希望将Oauth2与相同的Active Directory一起使用

我该怎么做?我的带有表单登录和Active directory的配置工作正常,但我们不知道如何使用Oauth2进行身份验证

我的Web安全配置是:

@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);

    }
}

如何仅为我的Rest服务插入Oauth2身份验证(此服务将通过路径../Rest/serviceName提供)

您需要配置另一个筛选器链以在资源服务器中拦截,以仅通过OAuth保护端点

请看我对类似问题的回答