All Projects → johntostring → Spring Boot Shiro

johntostring / Spring Boot Shiro

Licence: apache-2.0
Apache Shiro integration with Spring Boot.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Spring Boot Shiro

Shirojwt
API SpringBoot + Shiro + Java-Jwt + Redis(Jedis)
Stars: ✭ 503 (+184.18%)
Mutual labels:  spring-boot, shiro
Spring Boot Plus
🔥 Spring-Boot-Plus is a easy-to-use, high-speed, high-efficient,feature-rich, open source spring boot scaffolding. 🚀
Stars: ✭ 2,198 (+1141.81%)
Mutual labels:  spring-boot, shiro
Febs Shiro
Spring Boot 2.4.2,Shiro1.6.0 & Layui 2.5.6 权限管理系统。预览地址:http://47.104.70.138:8080/login
Stars: ✭ 5,655 (+3094.92%)
Mutual labels:  spring-boot, shiro
Spring Boot Demo
spring boot demo 是一个Spring Boot、Spring Cloud的项目示例,根据市场主流的后端技术,共集成了30+个demo,未来将持续更新。该项目包含helloworld(快速入门)、web(ssh项目快速搭建)、aop(切面编程)、data-redis(redis缓存)、quartz(集群任务实现)、shiro(权限管理)、oauth2(四种认证模式)、shign(接口参数防篡改重放)、encoder(用户密码设计)、actuator(服务监控)、cloud-config(配置中心)、cloud-gateway(服务网关)等模块
Stars: ✭ 323 (+82.49%)
Mutual labels:  spring-boot, shiro
Jeesite4
Java EE 企业级快速开发平台,基于经典技术组合(Spring Boot、Spring MVC、Apache Shiro、MyBatis、Beetl、Bootstrap、AdminLTE),在线代码生成功能,包括核心模块如:组织机构、角色用户、菜单及按钮授权、数据权限、系统参数、内容管理、工作流等。采用松耦合设计;界面无刷新,一键换肤;众多账号安全设置,密码策略;在线定时任务配置;支持集群,支持SAAS;支持多数据源
Stars: ✭ 1,563 (+783.05%)
Mutual labels:  spring-boot, shiro
Springall
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc
Stars: ✭ 22,375 (+12541.24%)
Mutual labels:  spring-boot, shiro
Javaquarkbbs
基于Spring Boot实现的一个简易的Java社区
Stars: ✭ 755 (+326.55%)
Mutual labels:  spring-boot, shiro
Febs Vue
SpringBoot,Shiro,JWT,Vue & Ant Design 前后端分离权限管理系统(精力有限,停止维护)
Stars: ✭ 2,079 (+1074.58%)
Mutual labels:  spring-boot, shiro
Eams
高校学生评优评奖系统
Stars: ✭ 106 (-40.11%)
Mutual labels:  spring-boot, shiro
Oneplatform
onePlatform定位是企业级应用网关,提供提供服务路由、SSO、统一认证授权、统一日志、全局事件以及模块化管理等基础能力。基于Spring cloud、开箱即用、无额外学习成本、无缝对接老系统。→提供配套视频教程(Q群: 61859839)
Stars: ✭ 105 (-40.68%)
Mutual labels:  spring-boot, shiro
Hope Boot
🌱 Hope-Boot 一款现代化的脚手架项目
Stars: ✭ 3,241 (+1731.07%)
Mutual labels:  spring-boot, shiro
Spring Boot Study
about learning Spring Boot via examples. 基于 spring boot 2.x 的学习教程简洁易懂
Stars: ✭ 131 (-25.99%)
Mutual labels:  spring-boot, shiro
Easyee
开源 JavaEE 企业级快速开发平台。提供了 Spring Boot, Struts2, Hibernate, MyBatis, Shiro, EasyUI 等技术,包含完整的权限管理系统等。提供自动化代码生成器。 Open source JaveEE enterprise-class rapid development of the basic platform. Integration of Spring Boot, Struts2, Hibernate, MyBatis, Shiro, EasyUI and other technologies, including the integrity of the rights management. Provides an automated code generator.
Stars: ✭ 275 (+55.37%)
Mutual labels:  spring-boot, shiro
Jeecg Boot
「企业级低代码平台」前后端分离架构SpringBoot 2.x,SpringCloud,Ant Design&Vue,Mybatis-plus,Shiro,JWT。强大的代码生成器让前后端代码一键生成,无需写任何代码! 引领新的开发模式OnlineCoding->代码生成->手工MERGE,帮助Java项目解决70%重复工作,让开发更关注业务,既能快速提高效率,帮助公司节省成本,同时又不失灵活性。
Stars: ✭ 26,432 (+14833.33%)
Mutual labels:  spring-boot, shiro
Ueboot
springboot2.2、spring-data-jpa、iView4、Vue2 、代码生成器、shiro权限管理、前后端分离、java后台管理系统快速开发框架,通过该框架可以在分钟级别内完成单表的前后端增删改查功能。脚手架工程: https://github.com/ueboot/ueboot-starter ,基于这个工程可以直接开发
Stars: ✭ 270 (+52.54%)
Mutual labels:  spring-boot, shiro
Oneblog
👽 OneBlog,一个简洁美观、功能强大并且自适应的Java博客
Stars: ✭ 678 (+283.05%)
Mutual labels:  spring-boot, shiro
Ruoyi
基于SpringBoot2.1的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。直接运行即可用
Stars: ✭ 991 (+459.89%)
Mutual labels:  spring-boot, shiro
Ibase4j
Spring,SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 1,548 (+774.58%)
Mutual labels:  spring-boot, shiro
Okhelper Service
OK帮 云进销存 (SpringBoot Restful 全家桶)
Stars: ✭ 146 (-17.51%)
Mutual labels:  spring-boot, shiro
Pac4j
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 2,097 (+1084.75%)
Mutual labels:  shiro

Apache Shiro integration with Spring Boot

Build Status

Github:https://github.com/johntostring/spring-boot-shiro

Usage

首先安装到本地仓库。

分支v2.0下为2.0.0版本,主要将Spring Boot升级到2.0.4.RELEASE,Shiro 升级到 1.4.0

mvn clean install

pom.xml

<dependency>
    <groupId>com.millinch</groupId>
    <artifactId>spring-boot-shiro-starter</artifactId>
    <version>1.0.0</version>
</dependency>

QuickStart

官方推荐采用YAML的方式配置,这里我也建议使用YAML来配置,一方面是因为在配置filter-chain-definitions时,通常我们是希望保证顺序的,使用properties的方式无法保证顺序(继承自Hashtable)。 后面将会列出配置的默认约定,按照你的需要,你只需要配置你想要修改的项就可以了。 关于SpringBoot详细使用方式,你可以查看官方文档,或者通过Github开源地址查看一些示例项目。

首先,默认提供JdbcRealm 配置,不能满足需求的情况下再配置自定义Realm:

shiro:
  realm-class:  #默认空,指定类全名com.your.company.YourRealm

1. 配置DataSource

以MySQL为例,添加好JDBC驱动依赖后,这是 Spring Boot 默认提供的方式配置DataSource:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/yourdbname
    username: #you know
    password: #you know
    driver-class-name: com.mysql.jdbc.Driver

2. 开启JdbcRealm

首先设shiro.realm.jdbc.enabled为true,否则就会查找自定义的realm-class,最后配置好SQL查询语句。

默认配置及描述:

shiro:
  realm:
    jdbc:
      enabled: true
      authentication-query: SELECT password FROM sys_user where user_name = ? #根据用户名获取密码
      salt: no_salt #可选值:no_salt, crypt(源码中未实现), column(上面这个SQL中第二列中获取salt), external(需继承JdbcRealm重写getSaltForUser()方法)
      user-roles-query: SELECT r.code
                        FROM sys_user_role ur
                        LEFT JOIN sys_role r ON r.id = ur.role_id
                        LEFT JOIN sys_user u ON ur.user_id = u.id AND u.user_name = ? #根据用户名获取角色
      permissions-query: SELECT re.permission
                         FROM sys_role_resource rr
                         LEFT JOIn sys_resource re ON rr.resource_id = re.id
                         LEFT JOIN sys_role r ON rr.role_id = r.id
                         WHERE r.code = ? #根据角色获取权限
  login-url: /login #登录入口URL
  success-url: /index #登录成功跳转URL
  unauthorized-url: /unauthorized #当访问未授权页面时跳转至该URL,将为filter chain中的每个AuthorizationFilter设置跳转URL(如果目标没有指定)
  sign-in:
    user-param: username #用户名参数名称
    password-param: password #密码参数名称
    remember-me-param: rememberMe #记住我参数名称
  hash-iterations: 1 #加密迭代次数,强制设为至少1次(即使设置0或负数)
  hash-algorithm-name: MD5 #加密算法名称,如:MD2/SHA-1/SHA-256/SHA-384/SHA-512
  filters:
    demo: your.packagepath.to.DemoFilter
  filter-chain-definitions: #默认为空,一般如下配置
    /login: authc
    /logout: logout
    /favicon.ico: anon
    /index: anon
    /assets/**: anon
    /**: authc

注意:在升级到Spring Boot 2+时我才发现filter-chain-definitions的配置中,key如果包含特殊字符会被强行去除掉,需要如下写法才可以:

filter-chain-definitions:
  '[/sayHi]': authc, demo

参考:https://stackoverflow.com/questions/34070987/escaping-a-dot-in-a-map-key-in-yaml-in-spring-boot/42285949

Cookie

shiro.cookie.cipher-key= #对称加密时使用(默认),为空则Shrio自动提供一个
shiro.cookie.decryption-cipher-key= #非对称加密时必需
shiro.cookie.encryption-cipher-key= #非对称加密时必需
shiro.cookie.name=rememberMe
shiro.cookie.http-only=true #建议开启
shiro.cookie.max-age=31536000 #1年
shiro.cookie.secure=false #安全传输cookie
shiro.cookie.version=-1

Session

shiro.session.active-sessions-cache-name=shiro-acciveSessionCache
shiro.session.delete-invalid-sessions=true
shiro.session.global-session-timeout=36000 #Session超时时长,默认1小时
shiro.session.id-generator=org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator #可指定自定义的实现
shiro.session.validation-interval=36000 #每隔1小时验证Session
shiro.session.validation-scheduler-enabled=true #是否开启定时验证Session

关于SessionValidationScheduler

默认配置ExecutorServiceSessionValidationScheduler,这是一个JDK的并发包API的实现。 若在classpath发现Quartz,则自动使用QuartzSessionValidationScheduler。即添加dependency:

<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-quartz</artifactId>
    <version>${shiro.version}</version>
</dependency>

最后,你也可以配置一个自定义的SessionValidationScheduler实现:

@Bean(name = "sessionValidationScheduler")
public SessionValidationScheduler yourSessionValidationScheduler() {
    return new YourSessionValidationScheduler();
}

Cache

shiro.ehcache.cache-manager-config-file=classpath:org/apache/shiro/cache/ehcache/ehcache.xml #开启Ehcache时可指定

CacheManager

默认配置MemoryConstrainedCacheManager,不建议用于生产。 若在classpath发现org.apache.shiro.cache.ehcache.EhCacheManager,则自动使用EhCacheManager。即添加dependency:

<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-ehcache</artifactId>
    <version>${shiro.version}</version>
</dependency>

同样地,CacheManager也可以配置自定义的实现,比如Redis等分布式缓存的实现,来覆盖默认配置,其他的如Realm、CredentialsMatcher、SessionDAO同样可配置Bean来覆盖默认配置。

最后,会继续完善的,Demo也会抽时间做一个。有不足的地方请及时指出。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].