淘东电商项目(34) -SSO单点登录(Client端集成)
引言
本文代码已提交至Github(版本号:
be503769cbddd9c9fe7775956035923410e785ab
),有兴趣的同学可以下载来看看:https://github.com/ylw-github/taodong-shop
阅读本文时,建议先阅读前面博客:
- 《淘东电商项目(31) -SSO单点登录(XXL-SSO案例)》
- 《淘东电商项目(32) -SSO单点登录(集成SSO认证服务)》
- 《淘东电商项目(33) -SSO单点登录(改造SSO认证服务登录界面)》
前面的文章已经把XXL-SSO服务集成到我们的「淘东电商」项目了,而且把登录界面也移植到了SSO服务,接下来我们集成SSO Client端。
本文目录结构:
l____引言
l____ 1. 首页门户集成SSO Client
l____ 2. 聚合支付门户集成SSO Client
l____ 3. 测试
l____总结
1. 首页门户集成SSO Client
1.Maven添加xxl-sso-core
模块:
<dependency>
<groupId>com.ylw</groupId>
<artifactId>taodong-shop-common-xxlsso-core</artifactId>
<version>1.0-RELEASE</version>
</dependency>
2.配置applicatoin.yml,完整内容如下(注意要在hosts文件里配置好域名):
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8100/eureka
server:
port: 8080
spring:
application:
name: app-portal-web
freemarker:
cache: false
charset: UTF-8
check-template-location: true
content-type: text/html
expose-request-attributes: true
expose-session-attributes: true
request-context-attribute: request
suffix: .ftl
template-loader-path:
- classpath:/templates
redis:
host: 127.0.0.1
port: 6379
jedis:
pool:
max-idle: 100
min-idle: 1
max-active: 1000
max-wait: -1
xxl:
sso:
logout:
path: /logout
server: http://taodong.ssoserver.com:8099
xxl-sso:
excluded:
paths: ''
3.添加配置文件:
/**
* description:
* create by: YangLinWei
* create time: 2020/3/19 10:10 上午
*/
@Configuration
public class XxlSsoConfig implements DisposableBean {
@Value("${xxl.sso.server}")
private String xxlSsoServer;
@Value("${xxl.sso.logout.path}")
private String xxlSsoLogoutPath;
@Value("${xxl-sso.excluded.paths}")
private String xxlSsoExcludedPaths;
@Value("${spring.redis.host}")
private String redisHost;
@Value("${spring.redis.port}")
private String port;
@Bean
public FilterRegistrationBean xxlSsoFilterRegistration() {
// xxl-sso, redis init
JedisUtil.init(String.format("redis://%s:%s", redisHost, port));
// xxl-sso, filter init
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setName("XxlSsoWebFilter");
registration.setOrder(1);
registration.addUrlPatterns("/*");
registration.setFilter(new XxlSsoWebFilter());
registration.addInitParameter(Conf.SSO_SERVER, xxlSsoServer);
registration.addInitParameter(Conf.SSO_LOGOUT_PATH, xxlSsoLogoutPath);
registration.addInitParameter(Conf.SSO_EXCLUDED_PATHS, xxlSsoExcludedPaths);
return registration;
}
@Override
public void destroy() throws Exception {
// xxl-sso, redis close
JedisUtil.close();
}
}
2. 聚合支付门户集成SSO Client
创建聚合支付门户模块taodong-shop-portal-pay-web
,具体的代码不再详述,可以clone代码下来看,SSO Client方式与上面一样:
3. 测试
1.启动Eureka服务、SSO认证服务、会员服务、门户服务、聚合支付服务。
2.浏览器访问门户服务(注意:hosts文件已经配置了域名)http://taodong.com:8080/,浏览器自动跳转到登录界面:
3.输入登录信息,执行登录操作,登录成功,可以看到登录成功后,地址栏的url也发生改变了http://taodong.com:8080/?xxl_sso_sessionid=27_7621bc6aeffe49feb58904ea5f3439d0:
同时,看下cookie信息,也把session id自动写入了浏览器的cookie:
4.访问聚合支付门户http://taodong.pay.com:8079/,可以看到直接就跳转到了聚合支付的首页了,而且浏览器的Session id与门户服务的session id一样:
总结
本文主要讲解SSO Client集成与测试。
相关文章
- PhpStorm 9.03 集成 开源中国(oschina.net)的Git项目,提交SVN时注意事项
- IntelliJ IDEA 14.x 与 Tomcat 集成,创建并运行Java Web项目
- EventBridge 集成云服务实践
- 基于 EventBridge 构建 SaaS 应用集成方案
- 项目实战之集成邮件开发
- 保利威视点播集成
- php5.6源码安装及php-fpm配置与nginx集成
- 基于EasyNVR二次开发实现业务需求:直接集成EasyNVR播放页面到自身项目
- Jenkins部署python-flask后端项目,持续集成(jinkins配置python虚拟环境)
- Jenkins 常用的项目构建工具集成 02 Gradle
- Jenkins 常用的项目构建工具集成 03 GO
- Jenkins 常用的项目构建工具集成 04 npm yarn
- Atitit springboot mybatis spring 集成 Springboot1.4 mybatis3.4.6 /springbootMybatis 目录 1.1. 设置map
- Atitit.你这些项目不都是模板吗?不是原创 集成和整合的方式大总结
- Atitit.mybatis的测试 以及spring与mybatis在本项目中的集成配置说明
- SAP UI5 应用开发教程之八十二 - 采用 OPA5 开发支持页面跳转的 SAP UI5 集成测试用例试读版
- 【项目实战】Spring Boot集成JavaMailSender发送邮件
- Spring MVC 学习总结(十)——Spring+Spring MVC+MyBatis框架集成(IntelliJ IDEA SSM集成)
- Spring+Ibatis集成开发实例
- k41.第十七章 K8s运维篇-DevOps 持续集成 持续部署 (一)
- Docker+Jenkins+Harbor+Rancher持续集成部署分布式项目
- Springboot怎么集成Thymeleaf模板引擎?
- Jenkins集成maven实现项目自动编译(十)