现在任何连接都要经过网关,所以在网关校验access_token的正确性,当access_token正确后,才转发到相应的服务。
当获取access_token后,每次前端访问都要带上这个access_token。
依次启动服务,eureka---->user------>oauth---------->zull顺序启动服务
现在我们访问127.0.0.1:9999/user/hello 这个接口
到现在为止无论带不带access_token都可以访问这个接口,并返回结果。显然这不是我想要的。
所以接下来要改造,只有携带了access_token,并且正确后才能访问这个接口。
在网关zuul加入oauth2的包
<!--oauth-->
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
</dependency>
然后添加配置类ResourceServerConfiguration.ja