这是解决问题的方法。看一下这个示例
Groovy类:
@Configuration@EnableResourceServerclass ResourceServer extends ResourceServerConfigurerAdapter { @Value('${oauth.resourceId}') private String resourceId @Override public void configure(HttpSecurity http) throws Exception { http.csrf().disable() http.httpBasic().disable() http.requestMatchers().antMatchers('/admin/**', '/uaa/**') .and().authorizeRequests() .antMatchers('/uaa/authenticated/**').authenticated() .antMatchers('/uaa/register/**').permitAll() .antMatchers('/uaa/activate/**').permitAll() .antMatchers('/uaa/password/**').permitAll() .antMatchers('/uaa/auth/**').permitAll() .antMatchers('/uaa/account/**').hasAuthority('ADMIN') .antMatchers('/admin/**').hasAuthority('ADMIN') .anyRequest().authenticated() http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) } @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception { resources.resourceId(resourceId); }}基本上,要将OAuth2.0身份验证与Web表单身份验证并行运行,您必须
http.requestMatchers().antMatchers('/path/1/**', '/path/2/**')配置类。我以前的配置没有考虑到这一重要部分,因此只有OAuth2.0参与了身份验证过程。



