淘东电商项目(34)

编程入门 行业动态 更新时间:2024-10-18 23:28:39

淘东电商<a href=https://www.elefans.com/category/jswz/34/1771421.html style=项目(34)"/>

淘东电商项目(34)

引言

本文代码已提交至Github(版本号:be503769cbddd9c9fe7775956035923410e785ab),有兴趣的同学可以下载来看看:

阅读本文时,建议先阅读前面博客:

  • 《淘东电商项目(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-webfreemarker:cache: falsecharset: UTF-8check-template-location: truecontent-type: text/htmlexpose-request-attributes: trueexpose-session-attributes: truerequest-context-attribute: requestsuffix: .ftltemplate-loader-path:- classpath:/templatesredis:host: 127.0.0.1port: 6379jedis:pool:max-idle: 100min-idle: 1max-active: 1000max-wait: -1
xxl:sso:logout:path: /logoutserver: :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;@Beanpublic FilterRegistrationBean xxlSsoFilterRegistration() {// xxl-sso, redis initJedisUtil.init(String.format("redis://%s:%s", redisHost, port));// xxl-sso, filter initFilterRegistrationBean 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;}@Overridepublic void destroy() throws Exception {// xxl-sso, redis closeJedisUtil.close();}}

2. 聚合支付门户集成SSO Client

创建聚合支付门户模块taodong-shop-portal-pay-web,具体的代码不再详述,可以clone代码下来看,SSO Client方式与上面一样:

3. 测试

1.启动Eureka服务、SSO认证服务、会员服务、门户服务、聚合支付服务。

2.浏览器访问门户服务(注意:hosts文件已经配置了域名):8080/,浏览器自动跳转到登录界面:

3.输入登录信息,执行登录操作,登录成功,可以看到登录成功后,地址栏的url也发生改变了:8080/?xxl_sso_sessionid=27_7621bc6aeffe49feb58904ea5f3439d0:

同时,看下cookie信息,也把session id自动写入了浏览器的cookie:

4.访问聚合支付门户:8079/,可以看到直接就跳转到了聚合支付的首页了,而且浏览器的Session id与门户服务的session id一样:

总结

本文主要讲解SSO Client集成与测试。

更多推荐

淘东电商项目(34)

本文发布于:2024-02-04 20:35:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1673373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   东电

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!