【发布时间】:2016-03-02 17:01:00
【问题描述】:
我已经设置了一个授权和资源服务器,它们都在同一个应用程序中运行。使用 spring boot 1.2.6.RELEASE 和 spring security oauth2 2.0.7.RELEASE 设置运行良好。在更新到 spring boot 1.3.0.RELEASE(无论是 spring security oauth2 2.0.7.RELEASE 还是 2.0.8.RELEASE)后,/login 端点用于 POST请求被破坏。我得到了响应 405“方法不允许”。
我花了一天多没有成功。我还设置了一个额外的、直接的授权和资源服务器,它们都在同一个应用程序中运行。然而,这个轻量级的设置也有同样的问题。一旦我启用资源服务器,登录端点就不再工作。
在我的原始服务器的配置 sn-ps 下方。
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// ... some code
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf()
.requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize"))
.disable()
.logout()
.logoutUrl(logoutUrl)
.logoutSuccessHandler(logoutSuccessHandler)
.invalidateHttpSession(true)
.and()
.formLogin()
.permitAll()
.loginProcessingUrl(loginProcessingUrl)
.failureUrl(loginAuthenticationFailureUrl)
.loginPage(loginPage);
}
}
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
// ... some code
private static final String RESOURCE_SERVER_MAPPING_REGEX = "^(?!(\\/?login|\\/?logout|\\/?oauth)).*$";
// ...some code
@Override
public void configure(HttpSecurity http) throws Exception {
http
// Configure the endpoints wherefore the resource server is responsible or rather should bound to.
.requestMatchers().regexMatchers(RESOURCE_SERVER_MAPPING_REGEX)
.and()
.authorizeRequests().anyRequest().permitAll()
.and()
.headers().frameOptions().disable();
}
}
【问题讨论】:
标签: spring spring-security spring-boot spring-security-oauth2