现在我的Web应用程序使用spring boot和Spring安全性没有问题,但是我需要使用Oauth2导出一个rest服务身份验证。
当用户访问我的Web系统时,他通过具有spring security和Active Directory的表单登录进行身份验证。
当其他系统尝试使用我们的Rest服务时,我想将Oauth2与相同的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);
}
}
如何仅为我的Rest服务插入Oauth2身份验证(此服务将由路径提供../ rest / serviceName