spring cloud oauth2 客户端

1.网关服务 承担了 spring cloud oauth2 客户端角色;

2. @EnableOAuth2Sso 注解 为开启客户端功能;

3.客户端用@EnableOAuth2Sso  开启注解有两种情况,使用默认配置或者自定义配置,并且 两种只能选择一种:

第1种,通过 @EnableOAuth2Sso 注解开启,全部使用默认的配置。

第2种,使用 @EnableOAuth2Sso 注解标记一个 WebSecurityConfigurerAdapter 类,如下所示。

@Component
@EnableOAuth2Sso
public static class SecurityConfig extends WebSecurityConfigurerAdapter {
一句话概括:只有继承WebSecurityConfigurerAdapter的类上带 @EnableOAuth2Sso注解时,这个配置最后生成的过滤器链中才会有 oauth2 的过滤器
 OAuth2ClientAuthenticationProcessingFilter。
在WebSecurityConfigurerAdapter 配置中的 http.antMatcher("xxx")会决定某个请求能否被这些过滤器链进行处理。假设 oauth2 登录的请求 url 
被别的配置拦截时,由于那个配置的拦截器链中没有 oauth2 的拦截器,因此就没法跳转到认证服务器。

4.客户端可以配置 登陆地址(但是 在spring cloud 体系 前后端分离 不需要配置)

在 application.properties或 yml 配置文件中配置 oauth2 的登录地址:

security.oauth2.sso.login-path=/dashboard/login

参考博客:https://blog.csdn.net/isea533/article/details/78078101


猜你喜欢

转载自blog.csdn.net/feiteyizu/article/details/80606091