【发布时间】:2016-01-25 23:02:59
【问题描述】:
在 spring-cloud Angel.SR3 版本中,我遵循了 https://github.com/spring-cloud-samples/sso 中的示例,并且在 spring-boot 1.2.6.RELEASE 中一切正常。
但是在 spring-boot 1.3.0.RC1 中,oauth2 的内容已经移入 spring-boot 本身,并且下面的代码无法编译,因为类 OAuth2SsoConfigurerAdapter 不再存在。
创建等效配置的 spring-boot 唯一方法是什么?
public static void main(String[] args) {
SpringApplication.run(MainAppApplication.class, args);
}
...
@Component
public static class LoginConfigurer extends OAuth2SsoConfigurerAdapter {
@Override
public void match(RequestMatchers matchers) {
matchers.antMatchers("/dashboard/**");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.antMatcher("/dashboard/**").authorizeRequests().anyRequest()
.authenticated().and().csrf()
.csrfTokenRepository(csrfTokenRepository()).and()
.addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
}
private Filter csrfHeaderFilter() {
return new OncePerRequestFilter() {
...
};
}
...
}
【问题讨论】:
-
您必须同时配置授权和资源服务器。您的 LoginConfigurer 是资源服务器应该是的那种。看看this例子
-
我已经配置了授权服务器和资源服务器。我正在寻找的是 OAuth2SsoConfigurerAdapter 类的 Spring-Boot 1.3 等效项(它曾经在 Spring-cloud 的 Angel.SR3 版本中,但从 Brixton.M1 中删除)
标签: java spring spring-security spring-boot spring-cloud