资源服务器在获取到了客户端发送过来的token后,做的第一件事情就是校验该token的真伪性,如果token校验不通过,则不允许调用对应的接口。
当前Spring Cloud与OAth2.0整合的版本依赖为:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
第一种方式:在资源服务中采用配置类的方式校验Token
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframewo