首页 文章

使用Oauth2和LDAP进行Spring安全性

提问于
浏览
1

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

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

当其他系统尝试使用我们的Rest服务时,我想将Oauth2与相同的Active Directory一起使用 .

我怎么能这样做?使用表单登录和Active目录的配置工作正常,但我们不知道如何使用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);

    }
}

我如何只为我的Rest服务插入Oauth2身份验证(此服务将由路径../rest/serviceName提供

1 回答

  • 1

    您需要在资源服务器中配置另一个过滤器链以拦截,以便仅通过OAuth保护您的终端 .

    看到我对类似问题的回答here

相关问题