GithubHelp home page GithubHelp logo

shirosesison's Introduction

shiro多项目共享session的springboot+shiro+redis 实现项目

项目结构介绍

  如下图所示,我们是springboot+dubbo+zookeeper 的项目:

images
  关于上边的项目,master 项目即是我们的主项目,含有登录页,suiteonesuitetwo 即是我们的从项目。facade 项目是我们分布式项目中相当于公共引用项目 一样,而userservice 项目作为我们的服务接口发布者。我们项目的实际架构我也贴了一张简单的图,方便大家理解: images   实际上就是我们把我们常见的serviceImp 以及dao和数据库连接等等 这一部分抽到了zookeeper中右边service 项目里了,这里我是测试项目,就没有写suiteoneservicesuitetwoservice ,仅仅写了userservice 项目。   关于springboot+dubbo+zookeeper 项目的实现可以参考我的另一篇文章 spring boot配置dubbo(XML)   按照上面的图,大概了解到,redis 是与mastersuiteonesuitetwo 连接的。

项目配置介绍

(1)主从都添加了shiroredis 依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-redis</artifactId>
     <version>1.3.6.RELEASE</version>
 </dependency>
  <dependency>
     <groupId>org.apache.shiro</groupId>
     <artifactId>shiro-all</artifactId>
     <version>1.3.2</version>
 </dependency>

(2)主从项目里配置application.properties 文件

  master 项目配置如下:

shiro.loginUrl=/login
shiro.jessionid=sessionId
spring.redis.host=192.168.1.160
spring.redis.port=6379
spring.redis.password=znxd

   suite 项目配置如下:

#从项目在未登录的情况下访问的登录页,默认为主项目master的登录页
shiro.loginUrl=http://localhost:30000/login
#从项目的sessionId,名字必须与主项目的名字一致
shiro.jessionid=sessionId
#以下为redis的配置
spring.redis.host=192.168.1.160
spring.redis.port=6379
spring.redis.password=znxd

(3) 主从项目都放上相同的shiro 相关类,如下:   master 项目的配置: images   suite 项目的配置: images

  其实关于从项目的配置不需要跟主项目的相同,在本项目中我已经能去掉的都去掉了。
  因为我的数据库是用的sqlserver 你需要下载下来sql 文件,把它们改成合适的sql 导入到数据库中。
  然后修改userservice 中的数据库连接配置。
  启动顺序,先启动userservice项目 ,再启动master项目,最后启动suite项目
  注意,如果你已经有相关的用户那些类,你完全没必要去用我的,你只需要修改master 项目中的userRealmRetryLimitHashedCredentialsMatcher 类中关于UserServiceSysFuncService 接口的调用。
   如果你想添加额外的从项目,你只需要仿照suiteone 或者suitetwo 写的关于shiro 配置即可。
   我们是需要zookeeper ,如果你没有使用这些,你还可以把我的项目,master 项目与userservice 项目合并,并且在从项目中引用下User类,因为共享的Session 在反序列化时,需要User 类 。

shirosesison's People

Contributors

lingshufeng avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.