我在WebSecurityConfigurerAdaptor
如下:啓用春天的OAuth2 ResourceServer禁用UsernamePasswordAuthenticationFilter
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寫的),並得到一個有效的訪問令牌,然後才能被重定向到/登錄。
然後我試着讓我的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
,和去/登錄返回HTTP 404錯誤。
我讀了很多次Spring OAuth2應用程序sparklr2和tonr2的示例,但我無法弄清楚我的代碼有什麼問題。