【发布时间】:2016-04-15 03:43:08
【问题描述】:
现在我的 Web 应用程序可以毫无问题地使用 Spring Boot 和 Spring Security,但我需要导出一个使用 Oauth2 进行身份验证的 rest 服务。
当用户访问我的 web 系统时,他通过带有 spring security 和 Active Directory 的表单登录进行身份验证。
当其他系统尝试使用我们的 Rest Service 时,我想将 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 提供
【问题讨论】:
标签: spring oauth-2.0 spring-boot spring-security-oauth2