【发布时间】:2016-01-15 01:56:18
【问题描述】:
我的WebSecurityConfigurerAdaptor 中有以下内容:
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login.jsp").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.accessDeniedPage("/login.jsp?authorization_error=true")
.and()
.csrf()
.disable()
.formLogin()
.loginProcessingUrl("/login")
.loginPage("/login.jsp")
.failureUrl("/login.jsp?authentication_error=true");
}
我有一个 OAuth2 客户端(用 PHP 编写),可以在获得有效的访问令牌之前重定向到 /login。
然后我尝试启用我的ResourceServerConfigurerAdapter:
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources)
throws Exception {
resources.resourceId("myResource").stateless(false);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and()
.requestMatchers()
.antMatchers("/me")
.and()
.authorizeRequests()
.antMatchers("/me").access("#oauth2.hasScope('email')");
}
}
一旦启用ResourceServer,UsernamePasswordAuthenticationFilter 就永远不会被调用,并且转到 /login 会返回 HTTP 404 错误。
我多次阅读示例 Spring OAuth2 应用程序 sparklr2 和 tonr2,但我无法弄清楚我的代码有什么问题。
【问题讨论】:
标签: authentication spring-security spring-security-oauth2