diff --git a/README.md b/README.md index ff8d0fa..232e2e2 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,37 @@ -# springboot-shiro +## :closed_lock_with_key::busts_in_silhouette: 一个简洁优美的权限管理系统 -#### 项目介绍 -Springboot + shiro权限管理。这或许是流程最详细、代码最干净、配置最简单的shiro上手项目了。 +### 项目简介 +*:sparkles: 如你所见 : 这或许是流程最清晰、代码最干净、注释最详细、配置最简单的 Shiro 项目啦 ! 非常适合进阶学习 SpringBoot 与 Shiro 的同学,是一个非常具有参考与学习价值的权限管理项目啦~* -#### 开发环境 -| 工具 | 版本或描述 | -| ----- | -------------------- | -| OS | Windows 7 | -| JDK | 1.7+ | -| IDE | IntelliJ IDEA 2017.3 | -| Maven | 3.3.1 | -| MySQL | 5.6.4 | +### 开发环境 -#### 模块划分 +| 工具 | 版本或描述 | +| ------- | ----------------------------- | +| `OS` | Windows 7 / 10 | +| `JDK` | 1.7+ / 11+ | +| `IDE` | IntelliJ IDEA 2017.3 / 2019.1 | +| `Maven` | 3.3.1 / 3.6.0 | +| `MySQL` | 5.6.4 / 8.0.0+ | -| 模块 | 释义 | -| ---------- | ----------------------- | -| shiro-core | 核心业务类模块,提供基本的数据操作、工具处理等 | -| shiro-admin | 后台管理模块 | -#### SQL Model -![sql model](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/sql-model.png?v=1.0) +### 项目模块划分 -#### 使用说明 +| 模块 | 释义 | +| ------------- | ------------------------------------------ | +| `shiro-core` | 核心业务类模块,提供基本的数据操作、工具处理等 | +| `shiro-admin` | 后台管理模块 | -1. 使用IDE导入本项目 + + +### 数据库模型 +![sql model](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/sql-model.png) + + + +### 使用说明 +1. 使用`IDE`导入本项目 2. 新建数据库`CREATE DATABASE shiro;` 3. 导入数据库`docs/db/shiro.sql` 4. 修改(`resources/application.yml`)配置文件 @@ -38,59 +43,295 @@ Springboot + shiro权限管理。这或许是流程最详细、代码最干净 3. 直接运行`ShiroAdminApplication.java` 6. 浏览器访问`http://127.0.0.1:8080` -**用户密码** +#### 用户密码 +> 超级管理员 : 账号:`root` , 密码 : `123456` + +> 普通管理员 : 账号:`admin` , 密码 : `123456` + +#### Druid监控 +> 链接 : `http://127.0.0.1:8080/druid/index.html` + +> 用户名 : `zyd-druid` , 密码 : `zyd-druid` + + + +### 项目结构 +``` +│ .gitignore +│ LICENSE +│ pom.xml +│ README.md +│ +├─docs +│ ├─db +│ │ shiro.sql +│ │ +│ └─img +│ admin-resource.PNG +│ admin-role.PNG +│ admin-user.PNG +│ db-datasource.PNG +│ db-login.PNG +│ index.PNG +│ login.PNG +│ role-role[admin].PNG +│ root-resource.PNG +│ root-role-[root].PNG +│ root-role.PNG +│ root-user.PNG +│ sql-model.png +│ +├─shiro-admin +│ │ .gitignore +│ │ pom.xml +│ │ +│ └─src +│ ├─main +│ │ ├─java +│ │ │ └─com +│ │ │ └─zyd +│ │ │ └─shiro +│ │ │ │ ShiroAdminApplication.java +│ │ │ │ +│ │ │ └─controller +│ │ │ ErrorPagesController.java +│ │ │ ExceptionHandleController.java +│ │ │ PassportController.java +│ │ │ RenderController.java +│ │ │ RestResourcesController.java +│ │ │ RestRoleController.java +│ │ │ RestUserController.java +│ │ │ +│ │ └─resources +│ │ │ application.yml +│ │ │ logback.xml +│ │ │ +│ │ ├─static +│ │ │ └─assets +│ │ │ ├─css +│ │ │ │ zhyd.core.css +│ │ │ │ +│ │ │ ├─images +│ │ │ │ default-portrait.png +│ │ │ │ favicon.ico +│ │ │ │ loading.gif +│ │ │ │ +│ │ │ └─js +│ │ │ jquery-form.js +│ │ │ validator.js +│ │ │ zhyd.core.js +│ │ │ zyd.table.js +│ │ │ zyd.tool.js +│ │ │ +│ │ └─templates +│ │ │ index.ftl +│ │ │ login.ftl +│ │ │ +│ │ ├─error +│ │ │ 401.ftl +│ │ │ 403.ftl +│ │ │ 404.ftl +│ │ │ 500.ftl +│ │ │ +│ │ ├─layout +│ │ │ footer.ftl +│ │ │ header.ftl +│ │ │ setting.ftl +│ │ │ sidebar.ftl +│ │ │ +│ │ ├─resources +│ │ │ list.ftl +│ │ │ +│ │ ├─role +│ │ │ list.ftl +│ │ │ +│ │ └─user +│ │ list.ftl +│ │ +│ └─test +│ └─java +│ └─com +│ └─zyd +│ └─shiro +│ ShiroAdminApplicationTests.java +│ +└─shiro-core + │ .gitignore + │ pom.xml + │ + └─src + ├─main + │ ├─java + │ │ └─com + │ │ └─zyd + │ │ └─shiro + │ │ ├─business + │ │ │ ├─consts + │ │ │ │ CommonConst.java + │ │ │ │ SessionConst.java + │ │ │ │ + │ │ │ ├─entity + │ │ │ │ Resources.java + │ │ │ │ Role.java + │ │ │ │ RoleResources.java + │ │ │ │ User.java + │ │ │ │ UserRole.java + │ │ │ │ + │ │ │ ├─enums + │ │ │ │ ResourceTypeEnum.java + │ │ │ │ ResponseStatus.java + │ │ │ │ UserGenderEnum.java + │ │ │ │ UserStatusEnum.java + │ │ │ │ UserTypeEnum.java + │ │ │ │ + │ │ │ ├─service + │ │ │ │ │ ShiroService.java + │ │ │ │ │ SysResourcesService.java + │ │ │ │ │ SysRoleResourcesService.java + │ │ │ │ │ SysRoleService.java + │ │ │ │ │ SysUserRoleService.java + │ │ │ │ │ SysUserService.java + │ │ │ │ │ + │ │ │ │ └─impl + │ │ │ │ ShiroServiceImpl.java + │ │ │ │ SysResourcesServiceImpl.java + │ │ │ │ SysRoleResourcesServiceImpl.java + │ │ │ │ SysRoleServiceImpl.java + │ │ │ │ SysUserRoleServiceImpl.java + │ │ │ │ SysUserServiceImpl.java + │ │ │ │ + │ │ │ ├─shiro + │ │ │ │ ├─credentials + │ │ │ │ │ CredentialsMatcher.java + │ │ │ │ │ RetryLimitCredentialsMatcher.java + │ │ │ │ │ + │ │ │ │ └─realm + │ │ │ │ ShiroRealm.java + │ │ │ │ + │ │ │ └─vo + │ │ │ ResourceConditionVO.java + │ │ │ RoleConditionVO.java + │ │ │ UserConditionVO.java + │ │ │ + │ │ ├─framework + │ │ │ ├─config + │ │ │ │ DruidConfig.java + │ │ │ │ ErrorPagesConfig.java + │ │ │ │ FreeMarkerConfig.java + │ │ │ │ MybatisConfig.java + │ │ │ │ RedisConfig.java + │ │ │ │ ShiroConfig.java + │ │ │ │ WebMvcConfig.java + │ │ │ │ + │ │ │ ├─exception + │ │ │ │ ZhydException.java + │ │ │ │ + │ │ │ ├─holder + │ │ │ │ RequestHolder.java + │ │ │ │ SpringContextHolder.java + │ │ │ │ + │ │ │ ├─interceptor + │ │ │ │ RememberAuthenticationInterceptor.java + │ │ │ │ + │ │ │ ├─object + │ │ │ │ AbstractBO.java + │ │ │ │ AbstractDO.java + │ │ │ │ AbstractService.java + │ │ │ │ BaseConditionVO.java + │ │ │ │ PageResult.java + │ │ │ │ ResponseVO.java + │ │ │ │ + │ │ │ ├─property + │ │ │ │ DruidProperties.java + │ │ │ │ RedisProperties.java + │ │ │ │ + │ │ │ ├─redis + │ │ │ │ CustomRedisManager.java + │ │ │ │ + │ │ │ ├─runner + │ │ │ │ BlogApplicationRunner.java + │ │ │ │ + │ │ │ └─tag + │ │ │ CustomTagDirective.java + │ │ │ + │ │ ├─persistence + │ │ │ ├─beans + │ │ │ │ SysResources.java + │ │ │ │ SysRole.java + │ │ │ │ SysRoleResources.java + │ │ │ │ SysUser.java + │ │ │ │ SysUserRole.java + │ │ │ │ + │ │ │ └─mapper + │ │ │ SysResourceMapper.java + │ │ │ SysRoleMapper.java + │ │ │ SysRoleResourcesMapper.java + │ │ │ SysUserMapper.java + │ │ │ SysUserRoleMapper.java + │ │ │ + │ │ ├─plugin + │ │ │ BaseMapper.java + │ │ │ + │ │ └─util + │ │ AesUtil.java + │ │ IpUtil.java + │ │ Md5Util.java + │ │ PasswordUtil.java + │ │ ResultUtil.java + │ │ SessionUtil.java + │ │ + │ └─resources + │ └─mybatis + │ SysResourceMapper.xml + │ SysRoleMapper.xml + │ SysUserMapper.xml + │ SysUserRoleMapper.xml + │ + └─test + └─java + └─com + └─zyd + └─shiro + ListUtilTest.java + ShiroCoreApplicationTests.java +``` + -_超级管理员_: 账号:root 密码:123456 -_普通管理员_: 账号:admin 密码:123456 +### 图片预览 +*:camera_flash: 用户登录页* -**Druid监控** +![用户登录](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/login.PNG) -_链接_: `http://127.0.0.1:8080/druid/index.html` +*:camera_flash: 系统首页* -用户名:zyd-druid 密码:zyd-druid +![首页](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/index.PNG) +*:camera_flash: 资源管理页* -#### 参与贡献 +![资源管理](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/root-resource.PNG) -1. Fork 本项目 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +*:camera_flash: 角色管理页* -#### 参考资料 +![角色管理](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/root-role.PNG) -1. 本项目部分代码参考自网络文章。[查看原文链接](http://blog.csdn.net/poorcoder_/article/details/71374002) -2. 前端模板来源自开源模板。[查看模板链接](https://colorlib.com/polygon/gentelella/index.html),[查看开源项目](https://github.com/puikinsh/gentelella) -3. 部分js实现参考自本人开源项目。[查看开源项目](https://gitee.com/yadong.zhang/DBlog) +*:camera_flash: 为角色分配资源* -感谢无私的网友,如果其他问题,欢迎各位朋友指正。 +![角色分配资源](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/root-role-%5Broot%5D.PNG) -#### 图片预览 +*:camera_flash: 用户管理页* -![首页](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/index.png?v=1.0) -![资源管理](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/root-resource.png?v=1.0) -![角色管理](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/root-role.png?v=1.0) -![角色分配资源](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/root-role[root].png?v=1.0) -![用户管理](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/root-user.png?v=1.0) -![用户分配角色](https://gitee.com/yadong.zhang/shiro/raw/master/docs/img/root-user[role].png?v=1.0) +![用户管理](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/root-user.PNG) -_注:以上图片是以`root`用户登录,`admin`用户的界面请参考`docs/img`下的图片_ +*:camera_flash: 为用户分配角色* -#### 生命不息,折腾不止! 更多信息,请关注: - 1. [我的博客](https://www.zhyd.me) - 2. [我的微博](http://weibo.com/211230415) - 3. [我的头条号](http://www.toutiao.com/c/user/3286958681/) - 4. [我的imooc](http://www.imooc.com/u/1175248/articles) - 4. [我的CSDN](https://blog.csdn.net/u011197448) +![用户分配角色](https://raw.githubusercontent.com/YUbuntu0109/springboot-shiro/master/docs/img/root-user%5Brole%5D.PNG) -#### 有任何问题可以 -- [给我留言](https://www.zhyd.me/guestbook) +> 注 : 以上图片为`root`用户登录后的部分截屏,`admin`用户的界面请参考`docs/img`下的图片哟~ -| 微信(备注:加群) | 公众号 | -| :------------: | :------------: | -| | | -#### 开源协议 - [MIT](https://gitee.com/yadong.zhang/DBlog/blob/master/LICENSE) +### 参考资料 +1. *本项目部分代码参考自网络文章 : [查看原文链接](http://blog.csdn.net/poorcoder_/article/details/71374002)* +2. *前端模板来源自开源模板 : [查看模板链接](https://colorlib.com/polygon/gentelella/index.html),[查看开源项目](https://github.com/puikinsh/gentelella)* +3. 部分js实现参考开源项目 : [查看开源项目](https://gitee.com/yadong.zhang/DBlog) diff --git a/docs/img/admin-resource.PNG b/docs/img/admin-resource.PNG new file mode 100644 index 0000000..05ccda2 Binary files /dev/null and b/docs/img/admin-resource.PNG differ diff --git a/docs/img/admin-resource.png b/docs/img/admin-resource.png deleted file mode 100644 index af04354..0000000 Binary files a/docs/img/admin-resource.png and /dev/null differ diff --git a/docs/img/admin-role.PNG b/docs/img/admin-role.PNG new file mode 100644 index 0000000..0cd1204 Binary files /dev/null and b/docs/img/admin-role.PNG differ diff --git a/docs/img/admin-role.png b/docs/img/admin-role.png deleted file mode 100644 index d69393d..0000000 Binary files a/docs/img/admin-role.png and /dev/null differ diff --git a/docs/img/admin-user.PNG b/docs/img/admin-user.PNG new file mode 100644 index 0000000..49eeac1 Binary files /dev/null and b/docs/img/admin-user.PNG differ diff --git a/docs/img/admin-user.png b/docs/img/admin-user.png deleted file mode 100644 index 09e3ee3..0000000 Binary files a/docs/img/admin-user.png and /dev/null differ diff --git a/docs/img/db-datasource.PNG b/docs/img/db-datasource.PNG new file mode 100644 index 0000000..9407116 Binary files /dev/null and b/docs/img/db-datasource.PNG differ diff --git a/docs/img/db-login.PNG b/docs/img/db-login.PNG new file mode 100644 index 0000000..fa95153 Binary files /dev/null and b/docs/img/db-login.PNG differ diff --git a/docs/img/index.PNG b/docs/img/index.PNG new file mode 100644 index 0000000..4489588 Binary files /dev/null and b/docs/img/index.PNG differ diff --git a/docs/img/index.png b/docs/img/index.png deleted file mode 100644 index 9d2d6b9..0000000 Binary files a/docs/img/index.png and /dev/null differ diff --git a/docs/img/login.PNG b/docs/img/login.PNG new file mode 100644 index 0000000..2c4d9c5 Binary files /dev/null and b/docs/img/login.PNG differ diff --git a/docs/img/role-role[admin].PNG b/docs/img/role-role[admin].PNG new file mode 100644 index 0000000..9c54f52 Binary files /dev/null and b/docs/img/role-role[admin].PNG differ diff --git a/docs/img/root-resource.PNG b/docs/img/root-resource.PNG new file mode 100644 index 0000000..2af8b64 Binary files /dev/null and b/docs/img/root-resource.PNG differ diff --git a/docs/img/root-resource.png b/docs/img/root-resource.png deleted file mode 100644 index 79abba4..0000000 Binary files a/docs/img/root-resource.png and /dev/null differ diff --git a/docs/img/root-role-[root].PNG b/docs/img/root-role-[root].PNG new file mode 100644 index 0000000..62f1f94 Binary files /dev/null and b/docs/img/root-role-[root].PNG differ diff --git a/docs/img/root-role.PNG b/docs/img/root-role.PNG new file mode 100644 index 0000000..1c35aa3 Binary files /dev/null and b/docs/img/root-role.PNG differ diff --git a/docs/img/root-role.png b/docs/img/root-role.png deleted file mode 100644 index cd43bd2..0000000 Binary files a/docs/img/root-role.png and /dev/null differ diff --git a/docs/img/root-role[admin].png b/docs/img/root-role[admin].png deleted file mode 100644 index 94faf83..0000000 Binary files a/docs/img/root-role[admin].png and /dev/null differ diff --git a/docs/img/root-role[root].png b/docs/img/root-role[root].png deleted file mode 100644 index 52d12d9..0000000 Binary files a/docs/img/root-role[root].png and /dev/null differ diff --git a/docs/img/root-user.PNG b/docs/img/root-user.PNG new file mode 100644 index 0000000..866f794 Binary files /dev/null and b/docs/img/root-user.PNG differ diff --git a/docs/img/root-user.png b/docs/img/root-user.png deleted file mode 100644 index 2f14b4f..0000000 Binary files a/docs/img/root-user.png and /dev/null differ diff --git a/docs/img/root-user[role].PNG b/docs/img/root-user[role].PNG new file mode 100644 index 0000000..d36b158 Binary files /dev/null and b/docs/img/root-user[role].PNG differ diff --git a/docs/img/root-user[role].png b/docs/img/root-user[role].png deleted file mode 100644 index 7146446..0000000 Binary files a/docs/img/root-user[role].png and /dev/null differ diff --git a/pom.xml b/pom.xml index 7fc9ede..b1f2449 100644 --- a/pom.xml +++ b/pom.xml @@ -8,18 +8,22 @@ 0.0.1-SNAPSHOT pom + shiro-core + shiro-admin shiro - Demo project for Spring Boot + A simpele authority management system + https://github.com/YUbuntu0109/springboot-shiro + org.springframework.boot spring-boot-starter-parent 2.0.1.RELEASE - + @@ -38,11 +42,13 @@ + org.projectlombok lombok true + org.springframework.boot spring-boot-starter-test @@ -55,4 +61,5 @@ test + diff --git a/shiro-admin/pom.xml b/shiro-admin/pom.xml index 4706cae..b8aa2a6 100644 --- a/shiro-admin/pom.xml +++ b/shiro-admin/pom.xml @@ -1,41 +1,40 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - shiro-admin - 0.0.1-SNAPSHOT - jar + shiro-admin + 0.0.1-SNAPSHOT + jar - shiro-admin - Demo project for Spring Boot + shiro-admin + 后台管理模块 - - com.zyd.shiro - shiro - 0.0.1-SNAPSHOT - + + com.zyd.shiro + shiro + 0.0.1-SNAPSHOT + - - - com.zyd.shiro - shiro-core - 0.0.1-SNAPSHOT - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - com.zyd.shiro.ShiroAdminApplication - JAR - - - - + + + com.zyd.shiro + shiro-core + 0.0.1-SNAPSHOT + + + + + + org.springframework.boot + spring-boot-maven-plugin + + com.zyd.shiro.ShiroAdminApplication + JAR + + + + diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/ErrorPagesController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/ErrorPagesController.java index 8050b4d..2631e42 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/ErrorPagesController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/ErrorPagesController.java @@ -39,18 +39,12 @@ import java.util.Map; /** - * 重写BasicErrorController,主要负责系统的异常页面的处理以及错误信息的显示 - *

- * 此处指需要记录 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - *

- * 要注意,这个类里面的代码一定不能有异常或者潜在异常发生,否则可能会让程序陷入死循环。 - *

- * @since 1.0 + * @project: springboot-shiro + * @description: 重写BasicErrorController, 主要负责系统的异常页面的处理以及错误信息的显示 + * 注意: 这个类里面的代码一定不能有异常或者潜在异常发生,否则可能会让程序陷入死循环 + * @date: 2019-08-15 7:42 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j @Controller @@ -64,9 +58,10 @@ public class ErrorPagesController implements ErrorController { private ServerProperties serverProperties; /** - * 初始化ExceptionController - * - * @param errorAttributes + * @description: 初始化ExceptionController + * @param: errorAttributes + * @date: 2019-08-15 8:10 PM + * @return: */ @Autowired public ErrorPagesController(ErrorAttributes errorAttributes) { @@ -74,6 +69,14 @@ public ErrorPagesController(ErrorAttributes errorAttributes) { this.errorAttributes = errorAttributes; } + /** + * @description: 404:指网页或文件未找到错误 + * @param: request + * @param: response + * @param: webRequest + * @date: 2019-08-15 8:10 PM + * @return: org.springframework.web.servlet.ModelAndView + */ @RequestMapping("/404") public ModelAndView errorHtml404(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest) { response.setStatus(HttpStatus.NOT_FOUND.value()); @@ -82,10 +85,18 @@ public ModelAndView errorHtml404(HttpServletRequest request, HttpServletResponse return new ModelAndView("error/404", model); } + /** + * @description: 403:资源不可用错误 + * @param: request + * @param: response + * @param: webRequest + * @date: 2019-08-15 8:11 PM + * @return: org.springframework.web.servlet.ModelAndView + */ @RequestMapping("/403") public ModelAndView errorHtml403(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest) { response.setStatus(HttpStatus.FORBIDDEN.value()); - // 404拦截规则,如果是静态文件发生的404则不记录到DB + // 404拦截规则,如果是静态文件发生的404则不记录到DB Map model = getErrorAttributes(webRequest, isIncludeStackTrace(request, MediaType.TEXT_HTML)); if (!String.valueOf(model.get("path")).contains(".")) { model.put("status", HttpStatus.FORBIDDEN.value()); @@ -93,6 +104,14 @@ public ModelAndView errorHtml403(HttpServletRequest request, HttpServletResponse return new ModelAndView("error/403", model); } + /** + * @description: 400:访问的页面域名不存在或者请求错误 + * @param: request + * @param: response + * @param: webRequest + * @date: 2019-08-15 8:11 PM + * @return: org.springframework.web.servlet.ModelAndView + */ @RequestMapping("/400") public ModelAndView errorHtml400(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest) { response.setStatus(HttpStatus.BAD_REQUEST.value()); @@ -100,6 +119,14 @@ public ModelAndView errorHtml400(HttpServletRequest request, HttpServletResponse return new ModelAndView("error/400", model); } + /** + * @description: 401:未经授权错误 + * @param: request + * @param: response + * @param: webRequest + * @date: 2019-08-15 8:12 PM + * @return: org.springframework.web.servlet.ModelAndView + */ @RequestMapping("/401") public ModelAndView errorHtml401(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest) { response.setStatus(HttpStatus.UNAUTHORIZED.value()); @@ -107,6 +134,14 @@ public ModelAndView errorHtml401(HttpServletRequest request, HttpServletResponse return new ModelAndView("error/401", model); } + /** + * @description: 500:服务器端发生异常 + * @param: request + * @param: response + * @param: webRequest + * @date: 2019-08-15 8:12 PM + * @return: org.springframework.web.servlet.ModelAndView + */ @RequestMapping("/500") public ModelAndView errorHtml500(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); @@ -121,8 +156,7 @@ public ModelAndView errorHtml500(HttpServletRequest request, HttpServletResponse * @param produces the media type produced (or {@code MediaType.ALL}) * @return if the stacktrace attribute should be included */ - protected boolean isIncludeStackTrace(HttpServletRequest request, - MediaType produces) { + protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) { ErrorProperties.IncludeStacktrace include = this.serverProperties.getError().getIncludeStacktrace(); if (include == ErrorProperties.IncludeStacktrace.ALWAYS) { return true; @@ -132,22 +166,21 @@ protected boolean isIncludeStackTrace(HttpServletRequest request, /** - * 获取错误的信息 - * - * @param webRequest - * @param includeStackTrace - * @return + * @description: 获取错误信息 + * @param: webRequest + * @param: includeStackTrace + * @date: 2019-08-15 8:13 PM + * @return: java.util.Map */ - private Map getErrorAttributes(WebRequest webRequest, - boolean includeStackTrace) { + private Map getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) { return this.errorAttributes.getErrorAttributes(webRequest, includeStackTrace); } /** - * 是否包含trace - * - * @param request - * @return + * @description: 判断是否包含trace + * @param: request + * @date: 2019-08-15 8:13 PM + * @return: boolean */ private boolean getTraceParameter(HttpServletRequest request) { String parameter = request.getParameter("trace"); @@ -155,10 +188,10 @@ private boolean getTraceParameter(HttpServletRequest request) { } /** - * 获取错误编码 - * - * @param request - * @return + * @description: (never used)获取错误编码 + * @param: request + * @date: 2019-08-15 8:14 PM + * @return: org.springframework.http.HttpStatus */ private HttpStatus getStatus(HttpServletRequest request) { Integer statusCode = (Integer) request @@ -175,9 +208,10 @@ private HttpStatus getStatus(HttpServletRequest request) { } /** - * 实现错误路径,暂时无用 - * - * @return + * @description: 实现错误路径, 暂时无用 + * @param: + * @date: 2019-08-15 8:14 PM + * @return: java.lang.String */ @Override public String getErrorPath() { diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/ExceptionHandleController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/ExceptionHandleController.java index da193bf..587e60f 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/ExceptionHandleController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/ExceptionHandleController.java @@ -32,14 +32,11 @@ import java.lang.reflect.UndeclaredThrowableException; /** - * 统一异常处理类
- * 捕获程序所有异常,针对不同异常,采取不同的处理方式 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 统一异常处理类:捕获程序所有异常,针对不同异常,采取不同的处理方式 + * @date: 2019-08-15 7:38 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j @ControllerAdvice @@ -59,7 +56,7 @@ public ResponseVO handle(Throwable e) { log.error(responseStatus.getMessage()); return ResultUtil.error(responseStatus.getCode(), responseStatus.getMessage()); } - e.printStackTrace(); // 打印异常栈 + e.printStackTrace(); //打印异常栈 return ResultUtil.error(CommonConst.DEFAULT_ERROR_CODE, ResponseStatus.ERROR.getMessage()); } diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/PassportController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/PassportController.java index aabea05..d9fff0d 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/PassportController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/PassportController.java @@ -35,33 +35,39 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; /** - * 登录相关 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 登录模块的控制器 + * @date: 2019-08-15 7:25 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j @Controller @RequestMapping(value = "/passport") public class PassportController { - @GetMapping("/login") + /** + * @description: 跳转到用户登录页 + * @param: model + * @date: 2019-08-15 7:26 PM + * @return: org.springframework.web.servlet.ModelAndView + */ + @GetMapping("/login")//the parameter is never used public ModelAndView login(Model model) { return ResultUtil.view("/login"); } /** - * 登录 - * - * @param username - * @param password - * @return + * @description: 验证用户登录信息 + * @param: username + * @param: password + * @param: rememberMe + * @param: kaptcha + * @date: 2019-08-15 7:26 PM + * @return: com.zyd.shiro.framework.object.ResponseVO */ @PostMapping("/signin") - @ResponseBody + @ResponseBody//the parameter of 'kaptcha' is never used public ResponseVO submitLogin(String username, String password, boolean rememberMe, String kaptcha) { UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe); //获取当前的Subject @@ -80,17 +86,16 @@ public ResponseVO submitLogin(String username, String password, boolean remember } /** - * 使用权限管理工具进行用户的退出,跳出登录,给出提示信息 - * - * @param redirectAttributes - * @return + * @description: 使用权限管理工具完成用户的退出, 跳出登录, 给出提示信息 + * @param: redirectAttributes + * @date: 2019-08-15 7:30 PM + * @return: org.springframework.web.servlet.ModelAndView */ @GetMapping("/logout") public ModelAndView logout(RedirectAttributes redirectAttributes) { - // http://www.oschina.net/question/99751_91561 - // 此处有坑: 退出登录,其实不用实现任何东西,只需要保留这个接口即可,也不可能通过下方的代码进行退出 + // 问题: http://www.oschina.net/question/99751_91561 + // 解答: 退出登录代码其实不用实现,只需要保留这个接口即可,因为注销功能是由Shiro默认实现的,既而以下用于注销的代码可省略哟 // SecurityUtils.getSubject().logout(); - // 因为退出操作是由Shiro控制的 redirectAttributes.addFlashAttribute("message", "您已安全退出"); return ResultUtil.redirect("index"); } diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/RenderController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/RenderController.java index 72025de..e6da4d6 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/RenderController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/RenderController.java @@ -19,16 +19,6 @@ */ package com.zyd.shiro.controller; -/** - * 页面渲染相关 -- 页面跳转 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 - */ - import com.zyd.shiro.util.ResultUtil; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -37,13 +27,11 @@ import org.springframework.web.servlet.ModelAndView; /** - * 页面跳转类 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 控制页面的渲染与跳转 + * @date: 2019-08-15 7:21 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Controller public class RenderController { diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/RestResourcesController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/RestResourcesController.java index 23848bd..e3c84ba 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/RestResourcesController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/RestResourcesController.java @@ -19,7 +19,6 @@ */ package com.zyd.shiro.controller; -import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.zyd.shiro.business.entity.Resources; import com.zyd.shiro.business.enums.ResponseStatus; @@ -38,13 +37,11 @@ import org.springframework.web.bind.annotation.RestController; /** - * 系统资源管理 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 系统资源管理模块的控制器 + * @date: 2019-08-15 6:51 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @RestController @RequestMapping("/resources") @@ -55,6 +52,12 @@ public class RestResourcesController { @Autowired private ShiroService shiroService; + /** + * @description: 分页显示系统资源信息 + * @param: vo + * @date: 2019-08-15 7:11 PM + * @return: com.zyd.shiro.framework.object.PageResult + */ @RequiresPermissions("resources") @PostMapping("/list") public PageResult getAll(ResourceConditionVO vo) { @@ -62,12 +65,24 @@ public PageResult getAll(ResourceConditionVO vo) { return ResultUtil.tablePage(pageInfo); } + /** + * @description: 获取所选择系统资源信息 + * @param: rid + * @date: 2019-08-15 7:12 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("role:allotResource") @PostMapping("/resourcesWithSelected") public ResponseVO resourcesWithSelected(Long rid) { return ResultUtil.success(null, resourcesService.queryResourcesListWithSelected(rid)); } + /** + * @description: 添加新系统资源信息 + * @param: resources + * @date: 2019-08-15 7:12 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("resource:add") @PostMapping(value = "/add") public ResponseVO add(Resources resources) { @@ -77,6 +92,12 @@ public ResponseVO add(Resources resources) { return ResultUtil.success("成功"); } + /** + * @description: 删除系统资源信息 + * @param: ids 以","分隔的资源id字符串 + * @date: 2019-08-15 7:13 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions(value = {"resource:batchDelete", "resource:delete"}, logical = Logical.OR) @PostMapping(value = "/remove") public ResponseVO remove(Long[] ids) { @@ -86,18 +107,29 @@ public ResponseVO remove(Long[] ids) { for (Long id : ids) { resourcesService.removeByPrimaryKey(id); } - //更新权限 shiroService.updatePermission(); return ResultUtil.success("成功删除 [" + ids.length + "] 个资源"); } + /** + * @description: 获取指定的系统资源信息 + * @param: id + * @date: 2019-08-15 7:14 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("resource:edit") @PostMapping("/get/{id}") public ResponseVO get(@PathVariable Long id) { return ResultUtil.success(null, this.resourcesService.getByPrimaryKey(id)); } + /** + * @description: 更新系统资源信息 + * @param: resources + * @date: 2019-08-15 7:15 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("resource:edit") @PostMapping("/edit") public ResponseVO edit(Resources resources) { diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/RestRoleController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/RestRoleController.java index ea0c58f..138f019 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/RestRoleController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/RestRoleController.java @@ -41,17 +41,16 @@ import java.util.List; /** - * 系统角色管理 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 系统角色管理模块的控制器 + * @date: 2019-08-15 6:51 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @RestController @RequestMapping("/roles") public class RestRoleController { + @Autowired private SysRoleService roleService; @Autowired @@ -59,6 +58,12 @@ public class RestRoleController { @Autowired private ShiroService shiroService; + /** + * @description: 分页显示系统角色信息 + * @param: vo + * @date: 2019-08-15 6:51 PM + * @return: com.zyd.shiro.framework.object.PageResult + */ @RequiresPermissions("roles") @PostMapping("/list") public PageResult getAll(RoleConditionVO vo) { @@ -66,12 +71,25 @@ public PageResult getAll(RoleConditionVO vo) { return ResultUtil.tablePage(pageInfo); } + /** + * @description: 显示所选择的系统角色信息 + * @param: uid + * @date: 2019-08-15 6:52 PM + * @return: com.zyd.shiro.framework.object.ResponseVO> + */ @RequiresPermissions("user:allotRole") @PostMapping("/rolesWithSelected") public ResponseVO> rolesWithSelected(Integer uid) { return ResultUtil.success(null, roleService.queryRoleListWithSelected(uid)); } + /** + * @description: 更新指定角色所拥有的资源信息 + * @param: roleId + * @param: resourcesId + * @date: 2019-08-15 6:53 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("role:allotResource") @PostMapping("/saveRoleResources") public ResponseVO saveRoleResources(Long roleId, String resourcesId) { @@ -84,6 +102,12 @@ public ResponseVO saveRoleResources(Long roleId, String resourcesId) { return ResultUtil.success("成功"); } + /** + * @description: 添加新系统角色信息 + * @param: role + * @date: 2019-08-15 6:54 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("role:add") @PostMapping(value = "/add") public ResponseVO add(Role role) { @@ -91,6 +115,12 @@ public ResponseVO add(Role role) { return ResultUtil.success("成功"); } + /** + * @description: 删除系统角色信息 + * @param: ids 以","分隔的角色id字符串 + * @date: 2019-08-15 6:55 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions(value = {"role:batchDelete", "role:delete"}, logical = Logical.OR) @PostMapping(value = "/remove") public ResponseVO remove(Long[] ids) { @@ -104,12 +134,24 @@ public ResponseVO remove(Long[] ids) { return ResultUtil.success("成功删除 [" + ids.length + "] 个角色"); } + /** + * @description: 获取指定的系统角色信息 + * @param: id + * @date: 2019-08-15 6:56 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("role:edit") @PostMapping("/get/{id}") public ResponseVO get(@PathVariable Long id) { return ResultUtil.success(null, this.roleService.getByPrimaryKey(id)); } + /** + * @description: 更新系统角色信息 + * @param: role + * @date: 2019-08-15 6:57 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("role:edit") @PostMapping("/edit") public ResponseVO edit(Role role) { diff --git a/shiro-admin/src/main/java/com/zyd/shiro/controller/RestUserController.java b/shiro-admin/src/main/java/com/zyd/shiro/controller/RestUserController.java index 6ee93ea..7899dd7 100644 --- a/shiro-admin/src/main/java/com/zyd/shiro/controller/RestUserController.java +++ b/shiro-admin/src/main/java/com/zyd/shiro/controller/RestUserController.java @@ -39,22 +39,27 @@ import org.springframework.web.bind.annotation.RestController; /** - * 用户管理 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户管理模块的控制器 + * @date: 2019-08-15 6:36 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @RestController @RequestMapping("/user") public class RestUserController { + @Autowired private SysUserService userService; @Autowired private SysUserRoleService userRoleService; + /** + * @description: 分页显示用户信息 + * @param: vo + * @date: 2019-08-15 6:37 PM + * @return: com.zyd.shiro.framework.object.PageResult + */ @RequiresPermissions("users") @PostMapping("/list") public PageResult list(UserConditionVO vo) { @@ -63,13 +68,11 @@ public PageResult list(UserConditionVO vo) { } /** - * 保存用户角色 - * - * @param userId - * @param roleIds - * 用户角色 - * 此处获取的参数的角色id是以 “,” 分隔的字符串 - * @return + * @description: 更新用户角色信息 + * @param: userId + * @param: roleIds 以","分隔的角色id字符串 + * @date: 2019-08-15 6:38 PM + * @return: com.zyd.shiro.framework.object.ResponseVO */ @RequiresPermissions("user:allotRole") @PostMapping("/saveUserRoles") @@ -81,6 +84,12 @@ public ResponseVO saveUserRoles(Long userId, String roleIds) { return ResultUtil.success("成功"); } + /** + * @description: 添加新用户 + * @param: user + * @date: 2019-08-15 6:40 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("user:add") @PostMapping(value = "/add") public ResponseVO add(User user) { @@ -98,6 +107,12 @@ public ResponseVO add(User user) { } } + /** + * @description: 删除用户信息 + * @param: ids 以","分隔的用户id字符串 + * @date: 2019-08-15 6:43 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions(value = {"user:batchDelete", "user:delete"}, logical = Logical.OR) @PostMapping(value = "/remove") public ResponseVO remove(Long[] ids) { @@ -111,12 +126,24 @@ public ResponseVO remove(Long[] ids) { return ResultUtil.success("成功删除 [" + ids.length + "] 个用户"); } + /** + * @description: 获取指定的用户信息 + * @param: id + * @date: 2019-08-15 6:45 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("user:edit") @PostMapping("/get/{id}") public ResponseVO get(@PathVariable Long id) { return ResultUtil.success(null, this.userService.getByPrimaryKey(id)); } + /** + * @description: 更新用户信息 + * @param: user + * @date: 2019-08-15 6:47 PM + * @return: com.zyd.shiro.framework.object.ResponseVO + */ @RequiresPermissions("user:edit") @PostMapping("/edit") public ResponseVO edit(User user) { diff --git a/shiro-admin/src/main/resources/application.yml b/shiro-admin/src/main/resources/application.yml index dad3efe..eae4cb4 100644 --- a/shiro-admin/src/main/resources/application.yml +++ b/shiro-admin/src/main/resources/application.yml @@ -1,7 +1,7 @@ # Server settings server: port: 8080 - # HTTP请求和响应头的最大量,以字节为单位,默认值为4096字节,超过此长度的部分不予处理,一般8K。解决java.io.EOFException: null问题 + # HTTP请求和响应头的最大量,以字节为单位,默认值为4096字节,超过此长度的部分不予处理,一般8K. 解决java.io.EOFException: null问题 max-http-header-size: 8192 use-forward-headers: true compression: @@ -14,14 +14,14 @@ server: port-header: X-Forwarded-Port uri-encoding: UTF-8 basedir: /var/tmp/website-app -# SPRING PROFILES +# Spring profiles spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/shiro?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false - username: root - password: root + username: + password: application: name: shiro-admin freemarker: @@ -65,59 +65,59 @@ spring: # redis缓存服务配置 session: store-type: redis - # Redis数据库索引(默认为0) + # Redis数据库索引(默认为0) redis: database: 1 # Redis服务器地址 host: 127.0.0.1 # Redis服务器连接端口 port: 6379 - # Redis服务器连接密码(默认为空) - password: qwe!@#123 - # 连接池最大连接数(使用负值表示没有限制) + # Redis服务器连接密码(默认为空) + password: + # 连接池最大连接数(使用负值表示没有限制) pool: maxActive: 8 - # 连接池最大阻塞等待时间(使用负值表示没有限制) + # 连接池最大阻塞等待时间(使用负值表示没有限制) maxWait: -1 # 连接池中的最大空闲连接 maxIdle: 8 # 连接池中的最小空闲连接 minIdle: 0 - # 连接超时时间(毫秒) + # 连接超时时间(毫秒) timeout: 0 - # 默认的数据过期时间,主要用于shiro权限管理 + # 默认的数据过期时间,主要用于shiro权限管理 expire: 2592000 # MyBatis mybatis: type-aliases-package: com.zyd.shiro.persistence.beans mapper-locations: classpath:/mybatis/*.xml -# mapper +# Mapper mapper: mappers: - com.zyd.shiro.plugin.BaseMapper not-empty: false identity: MYSQL -# pagehelper +# PageHelper pagehelper: helper-dialect: mysql reasonable: true support-methods-arguments: true params: count=countSql +# Banner banner: charset: UTF-8 - -################################### 程序自定义配置 ################################### +# 程序自定义配置 zyd: druid: - # druid访问用户名(默认:zyd-druid) + # druid访问用户名(默认:zyd-druid) username: zyd-druid - # druid访问密码(默认:zyd-druid) + # druid访问密码(默认:zyd-druid) password: zyd-druid - # druid访问地址(默认:/druid/*) + # druid访问地址(默认:/druid/*) servletPath: /druid/* - # 启用重置功能(默认false) + # 启用重置功能(默认false) resetEnable: false - # 白名单(非必填), list + # 白名单(非必填), list allowIps[0]: - # 黑名单(非必填), list + # 黑名单(非必填), list denyIps[0]: diff --git a/shiro-admin/src/main/resources/static/assets/css/zhyd.core.css b/shiro-admin/src/main/resources/static/assets/css/zhyd.core.css index 5d79959..7dc79c1 100644 --- a/shiro-admin/src/main/resources/static/assets/css/zhyd.core.css +++ b/shiro-admin/src/main/resources/static/assets/css/zhyd.core.css @@ -421,7 +421,7 @@ .nav-md .container.body .col-md-3.left_col { min-height: 100%; - width: 230px; + width: 250px; padding: 0; position: absolute; display: -ms-flexbox; @@ -440,11 +440,11 @@ body .container.body .right_col { .nav-md .container.body .right_col { padding: 10px 20px 0; - margin-left: 230px + margin-left: 250px } .nav_title { - width: 230px; + width: 250px; float: left; background: #2A3F54; border-radius: 0; @@ -607,7 +607,7 @@ body { .main_container .top_nav { display: block; - margin-left: 230px + margin-left: 250px } .no-padding { @@ -1873,7 +1873,7 @@ span.right { display: block; padding: 5px 0 0; position: fixed; - width: 230px; + width: 250px; background: #2A3F54; z-index: 999 } diff --git a/shiro-admin/src/main/resources/static/assets/images/default-portrait.png b/shiro-admin/src/main/resources/static/assets/images/default-portrait.png new file mode 100644 index 0000000..79cd837 Binary files /dev/null and b/shiro-admin/src/main/resources/static/assets/images/default-portrait.png differ diff --git a/shiro-admin/src/main/resources/static/assets/images/favicon.ico b/shiro-admin/src/main/resources/static/assets/images/favicon.ico new file mode 100644 index 0000000..4ebbd63 Binary files /dev/null and b/shiro-admin/src/main/resources/static/assets/images/favicon.ico differ diff --git a/shiro-admin/src/main/resources/static/assets/images/favicon.jpg b/shiro-admin/src/main/resources/static/assets/images/favicon.jpg deleted file mode 100644 index fbfb371..0000000 Binary files a/shiro-admin/src/main/resources/static/assets/images/favicon.jpg and /dev/null differ diff --git a/shiro-admin/src/main/resources/templates/index.ftl b/shiro-admin/src/main/resources/templates/index.ftl index 6196d6f..fac418d 100644 --- a/shiro-admin/src/main/resources/templates/index.ftl +++ b/shiro-admin/src/main/resources/templates/index.ftl @@ -20,31 +20,43 @@

  • +
    +

    拥抱该项目~ 提高代码可读性ing

    + +

    Stay hungray, Stay foolish. -- Steve Jobs

    +
    +
    +
  • +
  • +
    +

    添加Druid监控

    -

    Talk is cheap, show me the code. -- Linus Torvalds

    +

    Talk is cheap, show me the code. -- Linus Torvalds

  • 完善代码、流程,测试角色权限

    -

    Talk is cheap, show me the code. -- Linus Torvalds

    +

    Talk is cheap, show me the code. -- Linus Torvalds

  • 项目提交到Gitee

    diff --git a/shiro-admin/src/main/resources/templates/layout/header.ftl b/shiro-admin/src/main/resources/templates/layout/header.ftl index 6d11afb..2a276b1 100644 --- a/shiro-admin/src/main/resources/templates/layout/header.ftl +++ b/shiro-admin/src/main/resources/templates/layout/header.ftl @@ -6,7 +6,7 @@ Shiro权限管理系统 - + @@ -32,10 +32,10 @@
    - ... + ...
    - 早上好, + 早上好 ~

    尊敬的管理员

    diff --git a/shiro-core/pom.xml b/shiro-core/pom.xml index acd485e..062fc36 100644 --- a/shiro-core/pom.xml +++ b/shiro-core/pom.xml @@ -8,7 +8,7 @@ jar shiro-core - Demo project for Spring Boot + 核心业务类模块:提供基本的数据操作、工具处理等 com.zyd.shiro @@ -21,11 +21,12 @@ org.springframework.boot spring-boot-starter + org.springframework.boot spring-boot-starter-web - + org.springframework.boot spring-boot-starter-data-redis @@ -40,21 +41,23 @@ + redis.clients jedis + org.springframework.boot spring-boot-starter-freemarker - - + + org.springframework.boot spring-boot-starter-jdbc - + org.mybatis.spring.boot mybatis-spring-boot-starter @@ -66,7 +69,7 @@ - + tk.mybatis mapper-spring-boot-starter @@ -78,35 +81,38 @@ - + com.github.pagehelper pagehelper-spring-boot-starter ${pagehelper.version} - + mysql mysql-connector-java runtime - + + com.alibaba fastjson ${fastjson.version} - + com.alibaba druid-spring-boot-starter ${druid.version} + org.apache.shiro shiro-spring ${shiro.spring.version} + org.crazycake shiro-redis @@ -118,6 +124,7 @@ + net.mingsoft shiro-freemarker-tags diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/consts/CommonConst.java b/shiro-core/src/main/java/com/zyd/shiro/business/consts/CommonConst.java index 9ab106d..652c69a 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/consts/CommonConst.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/consts/CommonConst.java @@ -20,28 +20,20 @@ package com.zyd.shiro.business.consts; /** - * 程序中公用的常量类 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 程序中公用的常量类 + * @date: 2019-08-15 9:22 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class CommonConst { - /** - * 安全密码(UUID生成),作为盐值用于用户密码的加密 - */ + // TODO: 8/15/2019 安全密码(由UUID生成),作为盐值用于用户密码的加密 public static final String ZYD_SECURITY_KEY = "929123f8f17944e8b0a531045453e1f1"; - /** - * 程序默认的错误状态码 - */ + // TODO: 8/15/2019 程序默认的错误状态码 public static final int DEFAULT_ERROR_CODE = 500; - /** - * 程序默认的成功状态码 - */ + // TODO: 8/15/2019 程序默认的成功状态码 public static final int DEFAULT_SUCCESS_CODE = 200; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/consts/SessionConst.java b/shiro-core/src/main/java/com/zyd/shiro/business/consts/SessionConst.java index 92f0a4f..4ad7453 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/consts/SessionConst.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/consts/SessionConst.java @@ -20,15 +20,14 @@ package com.zyd.shiro.business.consts; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 程序中公用的Session常量类 + * @date: 2019-08-15 9:30 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class SessionConst { - /** - * User 的 session key;k - */ + + // TODO: 8/15/2019 User 的 session-key public static final String USER_SESSION_KEY = "user"; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/entity/Resources.java b/shiro-core/src/main/java/com/zyd/shiro/business/entity/Resources.java index 4561360..ae18118 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/entity/Resources.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/entity/Resources.java @@ -26,11 +26,11 @@ import java.util.List; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 资源信息 + * @date: 2019-08-15 9:36 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class Resources { private SysResources sysResources; @@ -161,4 +161,3 @@ public void setNodes(List nodes) { this.sysResources.setNodes(nodes); } } - diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/entity/Role.java b/shiro-core/src/main/java/com/zyd/shiro/business/entity/Role.java index 6295b72..7dc5753 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/entity/Role.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/entity/Role.java @@ -24,11 +24,11 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 角色信息 + * @date: 2019-08-15 9:36 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class Role { private SysRole sysRole; @@ -96,4 +96,3 @@ public void setUpdateTime(Date updateTime) { } } - diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/entity/RoleResources.java b/shiro-core/src/main/java/com/zyd/shiro/business/entity/RoleResources.java index 3a2cd90..460d667 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/entity/RoleResources.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/entity/RoleResources.java @@ -24,11 +24,11 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 连接角色与资源信息的桥梁 + * @date: 2019-08-15 9:41 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class RoleResources { diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/entity/User.java b/shiro-core/src/main/java/com/zyd/shiro/business/entity/User.java index 9086f89..8ce0fa8 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/entity/User.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/entity/User.java @@ -19,7 +19,9 @@ */ package com.zyd.shiro.business.entity; -import com.zyd.shiro.business.enums.*; +import com.zyd.shiro.business.enums.UserGenderEnum; +import com.zyd.shiro.business.enums.UserStatusEnum; +import com.zyd.shiro.business.enums.UserTypeEnum; import com.zyd.shiro.framework.object.AbstractBO; import com.zyd.shiro.persistence.beans.SysUser; import com.zyd.shiro.util.PasswordUtil; @@ -28,11 +30,11 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户信息 + * @date: 2019-08-15 9:34 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class User extends AbstractBO { private SysUser sysUser; diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/entity/UserRole.java b/shiro-core/src/main/java/com/zyd/shiro/business/entity/UserRole.java index 42241fe..6376155 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/entity/UserRole.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/entity/UserRole.java @@ -24,11 +24,11 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 连接用户与角色信息的桥梁 + * @date: 2019-08-15 9:40 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class UserRole { diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResourceTypeEnum.java b/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResourceTypeEnum.java index e2c4058..c846a97 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResourceTypeEnum.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResourceTypeEnum.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,14 +24,15 @@ package com.zyd.shiro.business.enums; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 资源类型 + * @date: 2019-08-15 10:14 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public enum ResourceTypeEnum { - menu("菜单"), button("按钮"); + menu("菜单"), + button("按钮"); private final String info; diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResponseStatus.java b/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResponseStatus.java index f2b7817..f6437a5 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResponseStatus.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/enums/ResponseStatus.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,11 +24,11 @@ package com.zyd.shiro.business.enums; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 错误操作的提示信息 + * @date: 2019-08-15 10:08 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public enum ResponseStatus { @@ -52,6 +52,12 @@ public enum ResponseStatus { this.message = message; } + /** + * @description: 获取错误操作的响应状态 + * @param: message + * @date: 2019-08-15 10:11 AM + * @return: com.zyd.shiro.business.enums.ResponseStatus + */ public static ResponseStatus getResponseStatus(String message) { for (ResponseStatus ut : ResponseStatus.values()) { if (ut.getMessage() == message) { diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserGenderEnum.java b/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserGenderEnum.java index f3c1b5f..83b9f53 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserGenderEnum.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserGenderEnum.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,11 +24,11 @@ package com.zyd.shiro.business.enums; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户性别信息 + * @date: 2019-08-15 10:05 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public enum UserGenderEnum { MALE(1, "男"), FEMALE(0, "女"), UNKNOW(-1, ""); @@ -40,6 +40,12 @@ public enum UserGenderEnum { this.desc = desc; } + /** + * @description: (never used)通过code码获取用户的性别信息 + * @param: code + * @date: 2019-08-15 10:05 AM + * @return: com.zyd.shiro.business.enums.UserGenderEnum + */ public static UserGenderEnum getUserSex(Integer code) { if (code == null) { return UNKNOW; @@ -52,14 +58,20 @@ public static UserGenderEnum getUserSex(Integer code) { return UNKNOW; } + /** + * @description: (never used)通过字符code获取用户性别信息 + * @param: code + * @date: 2019-08-15 10:06 AM + * @return: com.zyd.shiro.business.enums.UserGenderEnum + */ public static UserGenderEnum getUserSex(String code) { if (code == null) { return UNKNOW; } - if("m".equals(code)){ + if ("m".equals(code)) { return MALE; } - if("f".equals(code)){ + if ("f".equals(code)) { return FEMALE; } return UNKNOW; @@ -69,6 +81,7 @@ public int getCode() { return code; } + //the method is never used public String getDesc() { return desc; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserStatusEnum.java b/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserStatusEnum.java index ffb68af..243f938 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserStatusEnum.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserStatusEnum.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,11 +24,11 @@ package com.zyd.shiro.business.enums; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户状态信息 + * @date: 2019-08-15 9:56 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public enum UserStatusEnum { NORMAL(1, "正常"), @@ -41,6 +41,12 @@ public enum UserStatusEnum { this.desc = desc; } + /** + * @description: 获取用户的状态(是否可使用) + * @param: code + * @date: 2019-08-15 10:00 AM + * @return: com.zyd.shiro.business.enums.UserStatusEnum + */ public static UserStatusEnum get(Integer code) { if (null == code) { return NORMAL; @@ -58,6 +64,7 @@ public Integer getCode() { return code; } + //the method is never used public String getDesc() { return desc; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserTypeEnum.java b/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserTypeEnum.java index a8faab2..86697b7 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserTypeEnum.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/enums/UserTypeEnum.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,11 +26,11 @@ import org.springframework.util.StringUtils; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户的身份类型信息 + * @date: 2019-08-15 9:51 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public enum UserTypeEnum { ROOT("超级管理员"), @@ -43,6 +43,12 @@ public enum UserTypeEnum { this.desc = desc; } + /** + * @description: 获取用户的身份类型 + * @param: type + * @date: 2019-08-15 9:55 AM + * @return: com.zyd.shiro.business.enums.UserTypeEnum + */ public static UserTypeEnum getByType(String type) { if (StringUtils.isEmpty(type)) { return UserTypeEnum.UNKNOW; @@ -55,6 +61,7 @@ public static UserTypeEnum getByType(String type) { return UserTypeEnum.UNKNOW; } + //the method is never used public String getDesc() { return desc; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/ShiroService.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/ShiroService.java index 7bc1d66..352249d 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/ShiroService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/ShiroService.java @@ -24,37 +24,43 @@ import java.util.Map; /** - * Shiro-权限相关的业务处理 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/25 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: Shiro-权限相关的业务处理 + * @date: 2019-08-14 3:57 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface ShiroService { /** - * 初始化权限 + * @description: 初始化权限 + * @param: + * @date: 2019-08-14 3:53 PM + * @return: java.util.Map */ Map loadFilterChainDefinitions(); /** - * 重新加载权限 + * @description: 重新加载权限 + * @param: + * @date: 2019-08-14 3:53 PM + * @return: void */ void updatePermission(); /** - * 重新加载用户权限 - * - * @param user + * @description: 重新加载用户权限 + * @param: user + * @date: 2019-08-14 3:54 PM + * @return: void */ void reloadAuthorizingByUserId(User user); /** - * 重新加载所有拥有roleId角色的用户的权限 - * - * @param roleId + * @description: 重新加载所有拥有roleId角色的用户的权限 + * @param: roleId + * @date: 2019-08-14 3:54 PM + * @return: void */ void reloadAuthorizingByRoleId(Long roleId); diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysResourcesService.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysResourcesService.java index e197ff5..d77958f 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysResourcesService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysResourcesService.java @@ -28,66 +28,67 @@ import java.util.Map; /** - * 系统资源 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 系统资源相关的业务处理 + * @date: 2019-08-14 4:05 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface SysResourcesService extends AbstractService { /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询资源列表 + * @param: vo + * @date: 2019-08-14 4:05 PM + * @return: com.github.pagehelper.PageInfo */ PageInfo findPageBreakByCondition(ResourceConditionVO vo); /** - * 获取用户的资源列表 - * - * @param map - * @return + * @description: 获取用户所拥有的资源列表 + * @param: map + * @date: 2019-08-14 4:06 PM + * @return: java.util.List */ List listUserResources(Map map); /** - * 获取ztree使用的资源列表 - * - * @param rid - * @return + * @description: 通过角色id获取ztree使用的资源列表 + * @param: rid + * @date: 2019-08-14 4:06 PM + * @return: java.util.List> */ List> queryResourcesListWithSelected(Long rid); /** - * 获取资源的url和permission - * - * @return + * @description: 获取资源的url和Permission + * @param: + * @date: 2019-08-14 4:07 PM + * @return: java.util.List */ List listUrlAndPermission(); /** - * 获取所有可用的菜单资源 - * - * @return + * @description: 获取所有可用的菜单资源 + * @param: + * @date: 2019-08-14 4:07 PM + * @return: java.util.List */ List listAllAvailableMenu(); /** - * 获取父级资源下所有menu资源 - * - * @return + * @description: (never used)获取父级资源下所有menu资源 + * @param: pid + * @date: 2019-08-14 4:08 PM + * @return: java.util.List> */ List> listChildMenuByPid(Long pid); /** - * 获取用户关联的所有资源 - * - * @param userId - * @return + * @description: 通过用户id获取用户关联的所有资源 + * @param: userId + * @date: 2019-08-14 4:08 PM + * @return: java.util.List */ List listByUserId(Long userId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleResourcesService.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleResourcesService.java index 91f473b..68df668 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleResourcesService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleResourcesService.java @@ -24,28 +24,28 @@ import com.zyd.shiro.framework.object.AbstractService; /** - * 角色资源 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 角色资源相关的业务处理 + * @date: 2019-08-14 4:01 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface SysRoleResourcesService extends AbstractService { /** - * 添加角色资源 - * - * @param roleId - * @param resourcesIds + * @description: 添加角色资源 + * @param: roleId + * @param: resourcesIds + * @date: 2019-08-14 4:13 PM + * @return: void */ void addRoleResources(Long roleId, String resourcesIds); /** - * 通过角色id批量删除 - * - * @param roleId + * @description: 通过角色id批量删除 + * @param: roleId + * @date: 2019-08-14 4:13 PM + * @return: void */ void removeByRoleId(Long roleId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleService.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleService.java index de1a759..60387a9 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleService.java @@ -29,37 +29,35 @@ import java.util.Map; /** - * 角色 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 角色相关的业务处理 + * @date: 2019-08-14 4:01 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface SysRoleService extends AbstractService { /** - * 获取ztree使用的角色列表 - * - * @param uid - * @return + * @description: 通过用户id获取ztree使用的角色列表 + * @param: uid + * @date: 2019-08-14 4:02 PM + * @return: java.util.List> */ List> queryRoleListWithSelected(Integer uid); /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询角色列表 + * @param: vo + * @date: 2019-08-14 4:02 PM + * @return: com.github.pagehelper.PageInfo */ PageInfo findPageBreakByCondition(RoleConditionVO vo); /** - * 获取用户的角色 - * - * @param userId - * @return + * @description: 通过用户id获取用户所拥有的角色信息 + * @param: userId + * @date: 2019-08-14 4:03 PM + * @return: java.util.List */ List listRolesByUserId(Long userId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserRoleService.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserRoleService.java index 5519ec8..20db7f6 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserRoleService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserRoleService.java @@ -24,28 +24,28 @@ import com.zyd.shiro.framework.object.AbstractService; /** - * 用户角色 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户角色相关的业务处理 + * @date: 2019-08-14 4:10 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface SysUserRoleService extends AbstractService { /** - * 添加用户角色 - * - * @param userId - * @param roleIds + * @description: 添加用户角色 + * @param: userId + * @param: roleIds + * @date: 2019-08-14 4:10 PM + * @return: void */ void addUserRole(Long userId, String roleIds); /** - * 根据用户ID删除用户角色 - * - * @param userId + * @description: 根据用户id删除用户角色 + * @param: userId + * @date: 2019-08-14 4:10 PM + * @return: void */ void removeByUserId(Long userId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserService.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserService.java index 9933a1e..9bb3c55 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserService.java @@ -28,45 +28,43 @@ import java.util.List; /** - * 用户 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户相关的业务处理 + * @date: 2019-08-14 3:57 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface SysUserService extends AbstractService { /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询用户信息 + * @param: vo + * @date: 2019-08-14 3:58 PM + * @return: com.github.pagehelper.PageInfo */ PageInfo findPageBreakByCondition(UserConditionVO vo); /** - * 更新用户最后一次登录的状态信息 - * - * @param user - * @return + * @description: (never used)更新用户最后一次登录的状态信息 + * @param: user + * @date: 2019-08-14 3:59 PM + * @return: com.zyd.shiro.business.entity.User */ User updateUserLastLoginInfo(User user); /** - * 根据用户名查找 - * - * @param userName - * @return + * @description: 根据用户名查找指定的用户信息 + * @param: userName + * @date: 2019-08-14 4:00 PM + * @return: com.zyd.shiro.business.entity.User */ User getByUserName(String userName); /** - * 通过角色Id获取用户列表 - * - * @param roleId - * @return + * @description: 通过角色id获取用户列表 + * @param: roleId + * @date: 2019-08-14 4:00 PM + * @return: java.util.List */ List listByRoleId(Long roleId); diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/ShiroServiceImpl.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/ShiroServiceImpl.java index 80d269c..09d7da9 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/ShiroServiceImpl.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/ShiroServiceImpl.java @@ -45,13 +45,11 @@ import java.util.Map; /** - * Shiro-权限相关的业务处理 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/25 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: 实现Shiro权限相关的业务处理 + * @date: 2019-08-17 12:55 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j @Service @@ -63,18 +61,21 @@ public class ShiroServiceImpl implements ShiroService { private SysUserService userService; /** - * 初始化权限 + * @description: 初始化权限 + * @param: + * @date: 2019-08-17 1:06 PM + * @return: java.util.Map */ @Override public Map loadFilterChainDefinitions() { /* 配置访问权限 - anon:所有url都都可以匿名访问 - - authc: 需要认证才能进行访问(此处指所有非匿名的路径都需要登陆才能访问) + - authc: 需要认证才能进行访问(此处指所有非匿名的路径都需要登陆才能访问) - user:配置记住我或认证通过可以访问 */ Map filterChainDefinitionMap = new LinkedHashMap(); - // 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了 + // 配置退出过滤器(注:其中的具体的注销代码Shiro已经替我们实现咯) filterChainDefinitionMap.put("/passport/logout", "logout"); filterChainDefinitionMap.put("/passport/login", "anon"); filterChainDefinitionMap.put("/passport/signin", "anon"); @@ -89,13 +90,17 @@ public Map loadFilterChainDefinitions() { filterChainDefinitionMap.put(resources.getUrl(), permission); } } - // 本例子中并不存在什么特别关键的操作,所以直接使用user认证。如果有朋友是参考本例子的shiro开发其他安全功能(比如支付等)时,建议针对这类操作使用authc权限 by yadong.zhang + // 本项目中并不存在什么特别关键的操作,所以直接使用user认证 + // 如果有朋友是参考本例子的shiro开发其他安全功能(比如支付等)时,建议针对这类操作使用authc权限 by yadong.zhang filterChainDefinitionMap.put("/**", "user"); return filterChainDefinitionMap; } /** - * 重新加载权限 + * @description: 重新加载权限 + * @param: + * @date: 2019-08-17 1:10 PM + * @return: void */ @Override public void updatePermission() { @@ -107,14 +112,13 @@ public void updatePermission() { } catch (Exception e) { throw new RuntimeException("get ShiroFilter from shiroFilterFactoryBean error!"); } - PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver(); DefaultFilterChainManager manager = (DefaultFilterChainManager) filterChainResolver.getFilterChainManager(); // 清空老的权限控制 manager.getFilterChains().clear(); - shirFilter.getFilterChainDefinitionMap().clear(); + // 重新初始化过滤链 shirFilter.setFilterChainDefinitionMap(loadFilterChainDefinitions()); // 重新构建生成 Map chains = shirFilter.getFilterChainDefinitionMap(); @@ -127,9 +131,10 @@ public void updatePermission() { } /** - * 重新加载用户权限 - * - * @param user + * @description: 重新加载用户权限 + * @param: user + * @date: 2019-08-17 1:11 PM + * @return: void */ @Override public void reloadAuthorizingByUserId(User user) { @@ -147,9 +152,10 @@ public void reloadAuthorizingByUserId(User user) { } /** - * 重新加载所有拥有roleId角色的用户的权限 - * - * @param roleId + * @description: 重新加载所有拥有roleId角色的用户的权限 + * @param: roleId + * @date: 2019-08-17 1:11 PM + * @return: void */ @Override public void reloadAuthorizingByRoleId(Long roleId) { diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysResourcesServiceImpl.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysResourcesServiceImpl.java index 050dd40..69990a1 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysResourcesServiceImpl.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysResourcesServiceImpl.java @@ -34,13 +34,11 @@ import java.util.*; /** - * 系统资源 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 实现系统资源相关的业务处理 + * @date: 2019-08-17 11:45 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Service public class SysResourcesServiceImpl implements SysResourcesService { @@ -49,10 +47,10 @@ public class SysResourcesServiceImpl implements SysResourcesService { private SysResourceMapper resourceMapper; /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询系统资源信息 + * @param: vo + * @date: 2019-08-17 11:45 AM + * @return: com.github.pagehelper.PageInfo */ @Override public PageInfo findPageBreakByCondition(ResourceConditionVO vo) { @@ -71,10 +69,10 @@ public PageInfo findPageBreakByCondition(ResourceConditionVO vo) { } /** - * 获取用户的资源列表 - * - * @param map - * @return + * @description: 获取用户所拥有的资源列表 + * @param: map + * @date: 2019-08-17 12:27 PM + * @return: java.util.List */ @Override public List listUserResources(Map map) { @@ -90,10 +88,10 @@ public List listUserResources(Map map) { } /** - * 获取ztree使用的资源列表 - * - * @param rid - * @return + * @description: 获取ztree使用的资源列表 + * @param: rid + * @date: 2019-08-17 12:28 PM + * @return: java.util.List> */ @Override public List> queryResourcesListWithSelected(Long rid) { @@ -115,9 +113,10 @@ public List> queryResourcesListWithSelected(Long rid) { } /** - * 获取资源的url和permission - * - * @return + * @description: 获取资源的url和permission + * @param: + * @date: 2019-08-17 12:29 PM + * @return: java.util.List */ @Override public List listUrlAndPermission() { @@ -126,9 +125,10 @@ public List listUrlAndPermission() { } /** - * 获取所有可用的菜单资源 - * - * @return + * @description: 获取所有可用的菜单资源 + * @param: + * @date: 2019-08-17 12:29 PM + * @return: java.util.List */ @Override public List listAllAvailableMenu() { @@ -137,15 +137,15 @@ public List listAllAvailableMenu() { } /** - * 获取父级资源下所有menu资源 - * - * @param pid - * @return + * @description: 获取父级资源下所有的menu资源 + * @param: pid + * @date: 2019-08-17 12:30 PM + * @return: java.util.List> */ @Override public List> listChildMenuByPid(Long pid) { List sysResources = resourceMapper.listMenuResourceByPid(pid); - if(CollectionUtils.isEmpty(sysResources)){ + if (CollectionUtils.isEmpty(sysResources)) { return null; } List> result = new LinkedList<>(); @@ -160,10 +160,10 @@ public List> listChildMenuByPid(Long pid) { } /** - * 获取用户关联的所有资源 - * - * @param userId - * @return + * @description: 获取用户关联的所有资源 + * @param: userId + * @date: 2019-08-17 12:31 PM + * @return: java.util.List */ @Override public List listByUserId(Long userId) { @@ -172,10 +172,10 @@ public List listByUserId(Long userId) { } /** - * 保存一个实体,null的属性不会保存,会使用数据库默认值 - * - * @param entity - * @return + * @description: 保存一个实体, null的属性不会保存(会使用数据库默认值) + * @param: entity + * @date: 2019-08-17 12:31 PM + * @return: com.zyd.shiro.business.entity.Resources */ @Override public Resources insert(Resources entity) { @@ -187,9 +187,10 @@ public Resources insert(Resources entity) { } /** - * 批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 - * - * @param entities + * @description: 批量插入:支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 + * @param: entities + * @date: 2019-08-17 12:31 PM + * @return: void */ @Override public void insertList(List entities) { @@ -204,10 +205,10 @@ public void insertList(List entities) { } /** - * 根据主键字段进行删除,方法参数必须包含完整的主键属性 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 + * @param: primaryKey + * @date: 2019-08-17 12:32 PM + * @return: boolean */ @Override public boolean removeByPrimaryKey(Long primaryKey) { @@ -215,10 +216,10 @@ public boolean removeByPrimaryKey(Long primaryKey) { } /** - * 根据主键更新实体全部字段,null值会被更新 - * - * @param entity - * @return + * @description: 根据主键更新实体全部字段(null值也会被更新) + * @param: entity + * @date: 2019-08-17 12:32 PM + * @return: boolean */ @Override public boolean update(Resources entity) { @@ -228,10 +229,10 @@ public boolean update(Resources entity) { } /** - * 根据主键更新属性不为null的值 - * - * @param entity - * @return + * @description: 根据主键更新属性不为null的值 + * @param: entity + * @date: 2019-08-17 12:33 PM + * @return: boolean */ @Override public boolean updateSelective(Resources entity) { @@ -241,10 +242,10 @@ public boolean updateSelective(Resources entity) { } /** - * 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 + * @param: primaryKey + * @date: 2019-08-17 12:33 PM + * @return: com.zyd.shiro.business.entity.Resources */ @Override public Resources getByPrimaryKey(Long primaryKey) { @@ -254,10 +255,10 @@ public Resources getByPrimaryKey(Long primaryKey) { } /** - * 根据实体中的属性进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 12:34 PM + * @return: com.zyd.shiro.business.entity.Resources */ @Override public Resources getOneByEntity(Resources entity) { @@ -267,9 +268,10 @@ public Resources getOneByEntity(Resources entity) { } /** - * 查询全部结果,listByEntity(null)方法能达到同样的效果 - * - * @return + * @description: 查询全部结果, listByEntity(null)方法能达到同样的效果 + * @param: + * @date: 2019-08-17 12:34 PM + * @return: java.util.List */ @Override public List listAll() { @@ -278,10 +280,10 @@ public List listAll() { } /** - * 根据实体中的属性值进行查询,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性值进行查询, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 12:34 PM + * @return: java.util.List */ @Override public List listByEntity(Resources entity) { @@ -290,6 +292,12 @@ public List listByEntity(Resources entity) { return getResources(sysResources); } + /** + * @description: 抽取所有系统资源信息 + * @param: sysResources + * @date: 2019-08-17 12:35 PM + * @return: java.util.List + */ private List getResources(List sysResources) { if (CollectionUtils.isEmpty(sysResources)) { return null; diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleResourcesServiceImpl.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleResourcesServiceImpl.java index a54dca6..ca5ff63 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleResourcesServiceImpl.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleResourcesServiceImpl.java @@ -37,24 +37,23 @@ import java.util.List; /** - * 角色资源 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 实现角色资源相关的业务处理 + * @date: 2019-08-17 12:55 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Service public class SysRoleResourcesServiceImpl implements SysRoleResourcesService { + @Autowired private SysRoleResourcesMapper resourceMapper; /** - * 保存一个实体,null的属性不会保存,会使用数据库默认值 - * - * @param entity - * @return + * @description: 保存一个实体, null的属性不会保存(使用数据库默认值) + * @param: entity + * @date: 2019-08-17 12:55 PM + * @return: com.zyd.shiro.business.entity.RoleResources */ @Override public RoleResources insert(RoleResources entity) { @@ -66,9 +65,10 @@ public RoleResources insert(RoleResources entity) { } /** - * 批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 - * - * @param entities + * @description: 批量插入:支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 + * @param: entities + * @date: 2019-08-17 12:55 PM + * @return: void */ @Override public void insertList(List entities) { @@ -85,11 +85,12 @@ public void insertList(List entities) { resourceMapper.insertList(sysRoleResources); } + /** - * 根据主键字段进行删除,方法参数必须包含完整的主键属性 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 + * @param: primaryKey + * @date: 2019-08-17 12:56 PM + * @return: boolean */ @Override public boolean removeByPrimaryKey(Long primaryKey) { @@ -97,10 +98,10 @@ public boolean removeByPrimaryKey(Long primaryKey) { } /** - * 根据主键更新实体全部字段,null值会被更新 - * - * @param entity - * @return + * @description: 根据主键更新实体全部字段(null值也会被更新) + * @param: entity + * @date: 2019-08-17 12:56 PM + * @return: boolean */ @Override public boolean update(RoleResources entity) { @@ -110,10 +111,10 @@ public boolean update(RoleResources entity) { } /** - * 根据主键更新属性不为null的值 - * - * @param entity - * @return + * @description: 根据主键更新属性不为null的值 + * @param: entity + * @date: 2019-08-17 12:57 PM + * @return: boolean */ @Override public boolean updateSelective(RoleResources entity) { @@ -123,10 +124,10 @@ public boolean updateSelective(RoleResources entity) { } /** - * 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 + * @param: primaryKey + * @date: 2019-08-17 12:57 PM + * @return: com.zyd.shiro.business.entity.RoleResources */ @Override public RoleResources getByPrimaryKey(Long primaryKey) { @@ -136,10 +137,10 @@ public RoleResources getByPrimaryKey(Long primaryKey) { } /** - * 根据实体中的属性进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 12:58 PM + * @return: com.zyd.shiro.business.entity.RoleResources */ @Override public RoleResources getOneByEntity(RoleResources entity) { @@ -149,9 +150,10 @@ public RoleResources getOneByEntity(RoleResources entity) { } /** - * 查询全部结果,listByEntity(null)方法能达到同样的效果 - * - * @return + * @description: 查询全部结果, listByEntity(null)方法能达到同样的效果 + * @param: + * @date: 2019-08-17 12:58 PM + * @return: java.util.List */ @Override public List listAll() { @@ -160,10 +162,10 @@ public List listAll() { } /** - * 根据实体中的属性值进行查询,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性值进行查询, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 12:58 PM + * @return: java.util.List */ @Override public List listByEntity(RoleResources entity) { @@ -172,23 +174,13 @@ public List listByEntity(RoleResources entity) { return getRoleResources(sysRoleResources); } - private List getRoleResources(List sysRoleResources) { - if (CollectionUtils.isEmpty(sysRoleResources)) { - return null; - } - List rr = new ArrayList<>(); - for (SysRoleResources r : sysRoleResources) { - rr.add(new RoleResources(r)); - } - return rr; - } /** - * 添加角色资源 - * 该节代码参考自http://blog.csdn.net/poorcoder_/article/details/71374002 - * - * @param roleId - * @param resourcesIds + * @description: 添加角色资源, 该节代码参考自: http://blog.csdn.net/poorcoder_/article/details/71374002 + * @param: roleId + * @param: resourcesIds + * @date: 2019-08-17 1:04 PM + * @return: void */ @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) @@ -223,9 +215,10 @@ public void addRoleResources(Long roleId, String resourcesIds) { } /** - * 通过角色id批量删除 - * - * @param roleId + * @description: 通过角色id批量删除 + * @param: roleId + * @date: 2019-08-17 1:04 PM + * @return: void */ @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) @@ -236,4 +229,21 @@ public void removeByRoleId(Long roleId) { criteria.andEqualTo("roleId", roleId); resourceMapper.deleteByExample(example); } + + /** + * @description: 抽取所有角色资源信息 + * @param: sysRoleResources + * @date: 2019-08-17 12:59 PM + * @return: java.util.List + */ + private List getRoleResources(List sysRoleResources) { + if (CollectionUtils.isEmpty(sysRoleResources)) { + return null; + } + List rr = new ArrayList<>(); + for (SysRoleResources r : sysRoleResources) { + rr.add(new RoleResources(r)); + } + return rr; + } } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleServiceImpl.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleServiceImpl.java index 01b4c77..c0cfc83 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleServiceImpl.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysRoleServiceImpl.java @@ -34,13 +34,11 @@ import java.util.*; /** - * 角色 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 实现角色相关的业务处理 + * @date: 2019-08-17 11:29 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Service public class SysRoleServiceImpl implements SysRoleService { @@ -49,10 +47,10 @@ public class SysRoleServiceImpl implements SysRoleService { private SysRoleMapper roleMapper; /** - * 获取ztree使用的角色列表 - * - * @param userId - * @return + * @description: 获取ztree使用的角色列表 + * @param: userId + * @date: 2019-08-17 11:30 AM + * @return: java.util.List> */ @Override public List> queryRoleListWithSelected(Integer userId) { @@ -74,10 +72,10 @@ public List> queryRoleListWithSelected(Integer userId) { } /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询系统角色信息 + * @param: vo + * @date: 2019-08-17 11:30 AM + * @return: com.github.pagehelper.PageInfo */ @Override public PageInfo findPageBreakByCondition(RoleConditionVO vo) { @@ -96,10 +94,10 @@ public PageInfo findPageBreakByCondition(RoleConditionVO vo) { } /** - * 获取用户的角色 - * - * @param userId - * @return + * @description: 获取用户所拥有的角色信息 + * @param: userId + * @date: 2019-08-17 11:32 AM + * @return: java.util.List */ @Override public List listRolesByUserId(Long userId) { @@ -115,10 +113,10 @@ public List listRolesByUserId(Long userId) { } /** - * 保存一个实体,null的属性不会保存,会使用数据库默认值 - * - * @param entity - * @return + * @description: 保存一个实体, null的属性不会保存(会使用数据库默认值) + * @param: entity + * @date: 2019-08-17 11:33 AM + * @return: com.zyd.shiro.business.entity.Role */ @Override public Role insert(Role entity) { @@ -130,9 +128,10 @@ public Role insert(Role entity) { } /** - * 批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 - * - * @param entities + * @description: 批量插入:支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 + * @param: entities + * @date: 2019-08-17 11:34 AM + * @return: void */ @Override public void insertList(List entities) { @@ -146,11 +145,11 @@ public void insertList(List entities) { roleMapper.insertList(sysRole); } - /** - * 根据主键字段进行删除,方法参数必须包含完整的主键属性 - * - * @param primaryKey - * @return + /*** + *@description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 + *@param: primaryKey + *@date: 2019-08-17 11:36 AM + *@return: boolean */ @Override public boolean removeByPrimaryKey(Long primaryKey) { @@ -158,10 +157,10 @@ public boolean removeByPrimaryKey(Long primaryKey) { } /** - * 根据主键更新实体全部字段,null值会被更新 - * - * @param entity - * @return + * @description: 根据主键更新实体全部字段, null值会被更新 + * @param: entity + * @date: 2019-08-17 11:36 AM + * @return: boolean */ @Override public boolean update(Role entity) { @@ -171,10 +170,10 @@ public boolean update(Role entity) { } /** - * 根据主键更新属性不为null的值 - * - * @param entity - * @return + * @description: 根据主键更新属性不为null的值 + * @param: entity + * @date: 2019-08-17 11:36 AM + * @return: boolean */ @Override public boolean updateSelective(Role entity) { @@ -184,10 +183,10 @@ public boolean updateSelective(Role entity) { } /** - * 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 + * @param: primaryKey + * @date: 2019-08-17 11:37 AM + * @return: com.zyd.shiro.business.entity.Role */ @Override public Role getByPrimaryKey(Long primaryKey) { @@ -197,10 +196,10 @@ public Role getByPrimaryKey(Long primaryKey) { } /** - * 根据实体中的属性进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 11:37 AM + * @return: com.zyd.shiro.business.entity.Role */ @Override public Role getOneByEntity(Role entity) { @@ -210,9 +209,10 @@ public Role getOneByEntity(Role entity) { } /** - * 查询全部结果,listByEntity(null)方法能达到同样的效果 - * - * @return + * @description: 获取所有角色信息, listByEntity(null)方法能达到同样的效果 + * @param: + * @date: 2019-08-17 11:38 AM + * @return: java.util.List */ @Override public List listAll() { @@ -221,10 +221,10 @@ public List listAll() { } /** - * 根据实体中的属性值进行查询,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性值进行查询, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 11:40 AM + * @return: java.util.List */ @Override public List listByEntity(Role entity) { @@ -233,6 +233,12 @@ public List listByEntity(Role entity) { return getRole(sysRole); } + /*** + *@description: 抽取所用角色信息 + *@param: sysRole + *@date: 2019-08-17 11:40 AM + *@return: java.util.List + */ private List getRole(List sysRole) { if (CollectionUtils.isEmpty(sysRole)) { return null; @@ -243,4 +249,5 @@ private List getRole(List sysRole) { } return roleList; } + } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserRoleServiceImpl.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserRoleServiceImpl.java index 9a24443..892b212 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserRoleServiceImpl.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserRoleServiceImpl.java @@ -37,13 +37,11 @@ import java.util.List; /** - * 用户角色 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 实现用户角色相关的业务处理 + * @date: 2019-08-17 12:37 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Service public class SysUserRoleServiceImpl implements SysUserRoleService { @@ -52,10 +50,10 @@ public class SysUserRoleServiceImpl implements SysUserRoleService { private SysUserRoleMapper resourceMapper; /** - * 保存一个实体,null的属性不会保存,会使用数据库默认值 - * - * @param entity - * @return + * @description: 保存一个实体, null的属性不会保存(使用数据库默认值) + * @param: entity + * @date: 2019-08-17 12:37 PM + * @return: com.zyd.shiro.business.entity.UserRole */ @Override public UserRole insert(UserRole entity) { @@ -67,9 +65,10 @@ public UserRole insert(UserRole entity) { } /** - * 批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 - * - * @param entities + * @description: 批量插入:支持批量插入的数据库可以使用, 例如MySQL, H2等, 另外该接口限制实体包含id属性并且必须为自增列 + * @param: entities + * @date: 2019-08-17 12:38 PM + * @return: void */ @Override public void insertList(List entities) { @@ -87,10 +86,10 @@ public void insertList(List entities) { } /** - * 根据主键字段进行删除,方法参数必须包含完整的主键属性 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 + * *@param: primaryKey + * @date: 2019-08-17 12:38 PM + * @return: boolean */ @Override public boolean removeByPrimaryKey(Long primaryKey) { @@ -98,10 +97,10 @@ public boolean removeByPrimaryKey(Long primaryKey) { } /** - * 根据主键更新实体全部字段,null值会被更新 - * - * @param entity - * @return + * @description: 根据主键更新实体全部字段(null值也会被更新) + * @param: entity + * @date: 2019-08-17 12:38 PM + * @return: boolean */ @Override public boolean update(UserRole entity) { @@ -111,10 +110,10 @@ public boolean update(UserRole entity) { } /** - * 根据主键更新属性不为null的值 - * - * @param entity - * @return + * @description: 根据主键更新属性不为null的值 + * @param: entity + * @date: 2019-08-17 12:39 PM + * @return: boolean */ @Override public boolean updateSelective(UserRole entity) { @@ -124,10 +123,10 @@ public boolean updateSelective(UserRole entity) { } /** - * 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 + * @param: primaryKey + * @date: 2019-08-17 12:40 PM + * @return: com.zyd.shiro.business.entity.UserRole */ @Override public UserRole getByPrimaryKey(Long primaryKey) { @@ -137,10 +136,10 @@ public UserRole getByPrimaryKey(Long primaryKey) { } /** - * 根据实体中的属性进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 12:40 PM + * @return: com.zyd.shiro.business.entity.UserRole */ @Override public UserRole getOneByEntity(UserRole entity) { @@ -150,9 +149,10 @@ public UserRole getOneByEntity(UserRole entity) { } /** - * 查询全部结果,listByEntity(null)方法能达到同样的效果 - * - * @return + * @description: 查询全部结果, listByEntity(null)方法能达到同样的效果 + * @param: + * @date: 2019-08-17 12:41 PM + * @return: java.util.List */ @Override public List listAll() { @@ -161,10 +161,10 @@ public List listAll() { } /** - * 根据实体中的属性值进行查询,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性值进行查询, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 12:41 PM + * @return: java.util.List */ @Override public List listByEntity(UserRole entity) { @@ -173,23 +173,13 @@ public List listByEntity(UserRole entity) { return getUserRole(sysUserRole); } - private List getUserRole(List sysUserRole) { - if (CollectionUtils.isEmpty(sysUserRole)) { - return null; - } - List urList = new ArrayList<>(); - for (SysUserRole r : sysUserRole) { - urList.add(new UserRole(r)); - } - return urList; - } /** - * 添加用户角色 - * 该节代码参考自http://blog.csdn.net/poorcoder_/article/details/71374002 - * - * @param userId - * @param roleIds + * @description: 添加用户角色, 该节代码参考自: http://blog.csdn.net/poorcoder_/article/details/71374002 + * @param: userId + * @param: roleIds + * @date: 2019-08-17 12:44 PM + * @return: void */ @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) @@ -216,9 +206,10 @@ public void addUserRole(Long userId, String roleIds) { } /** - * 根据用户ID删除用户角色 - * - * @param userId + * @description: 根据用户id删除指定的用户角色 + * @param: userId + * @date: 2019-08-17 12:45 PM + * @return: void */ @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) @@ -228,4 +219,21 @@ public void removeByUserId(Long userId) { criteria.andEqualTo("userId", userId); resourceMapper.deleteByExample(example); } + + /** + * @description: 抽取所有的用户角色信息 + * @param: sysUserRole + * @date: 2019-08-17 12:42 PM + * @return: java.util.List + */ + private List getUserRole(List sysUserRole) { + if (CollectionUtils.isEmpty(sysUserRole)) { + return null; + } + List urList = new ArrayList<>(); + for (SysUserRole r : sysUserRole) { + urList.add(new UserRole(r)); + } + return urList; + } } diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserServiceImpl.java b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserServiceImpl.java index b0845e9..5892bfb 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserServiceImpl.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/service/impl/SysUserServiceImpl.java @@ -45,13 +45,11 @@ import java.util.List; /** - * 用户 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 实现用户相关的业务处理 + * @date: 2019-08-17 8:36 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j @Service @@ -61,8 +59,14 @@ public class SysUserServiceImpl implements SysUserService { private SysUserMapper sysUserMapper; @Autowired - private SysRoleService roleService; + private SysRoleService roleService; //never accessed + /** + * @description: 添加新用户信息 + * @param: user + * @date: 2019-08-17 8:38 AM + * @return: com.zyd.shiro.business.entity.User + */ @Override @Transactional(rollbackFor = Exception.class) public User insert(User user) { @@ -75,6 +79,12 @@ public User insert(User user) { return user; } + /** + * @description: 批量插入:支持批量插入的数据库可以使用, 例如MySQL, H2等. 另外该接口限制实体包含id属性并且必须为自增列 + * @param: users + * @date: 2019-08-17 8:45 AM + * @return: void + */ @Override @Transactional(rollbackFor = Exception.class) public void insertList(List users) { @@ -91,10 +101,10 @@ public void insertList(List users) { } /** - * 根据主键字段进行删除,方法参数必须包含完整的主键属性 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 + * @param: primaryKey + * @date: 2019-08-17 9:01 AM + * @return: boolean */ @Override @Transactional(rollbackFor = Exception.class) @@ -102,6 +112,12 @@ public boolean removeByPrimaryKey(Long primaryKey) { return sysUserMapper.deleteByPrimaryKey(primaryKey) > 0; } + /** + * @description: 更新用户信息 + * @param: user + * @date: 2019-08-17 9:02 AM + * @return: boolean + */ @Override @Transactional(rollbackFor = Exception.class) public boolean update(User user) { @@ -117,6 +133,12 @@ public boolean update(User user) { return sysUserMapper.updateByPrimaryKey(user.getSysUser()) > 0; } + /** + * @description: 选择性地更新用户信息 + * @param: user + * @date: 2019-08-17 9:04 AM + * @return: boolean + */ @Override @Transactional(rollbackFor = Exception.class) public boolean updateSelective(User user) { @@ -136,12 +158,11 @@ public boolean updateSelective(User user) { } /** - * 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 + * @param: primaryKey + * @date: 2019-08-17 9:08 AM + * @return: com.zyd.shiro.business.entity.User */ - @Override public User getByPrimaryKey(Long primaryKey) { Assert.notNull(primaryKey, "PrimaryKey不可为空!"); @@ -150,10 +171,10 @@ public User getByPrimaryKey(Long primaryKey) { } /** - * 根据实体中的属性进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 + * @param: entity + * @date: 2019-08-17 11:02 AM + * @return: com.zyd.shiro.business.entity.User */ @Override public User getOneByEntity(User entity) { @@ -162,10 +183,15 @@ public User getOneByEntity(User entity) { return null == sysUser ? null : new User(sysUser); } + /** + * @description: 获取所有用户列表 + * @param: + * @date: 2019-08-17 11:02 AM + * @return: java.util.List + */ @Override public List listAll() { List sysUsers = sysUserMapper.selectAll(); - if (CollectionUtils.isEmpty(sysUsers)) { return null; } @@ -176,6 +202,12 @@ public List listAll() { return users; } + /** + * @description: 根据实体中的属性值进行查询, 查询条件使用等号 + * @param: user + * @date: 2019-08-17 11:03 AM + * @return: java.util.List + */ @Override public List listByEntity(User user) { Assert.notNull(user, "User不可为空!"); @@ -191,10 +223,10 @@ public List listByEntity(User user) { } /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询用户信息 + * @param: vo + * @date: 2019-08-17 11:05 AM + * @return: com.github.pagehelper.PageInfo */ @Override public PageInfo findPageBreakByCondition(UserConditionVO vo) { @@ -213,10 +245,10 @@ public PageInfo findPageBreakByCondition(UserConditionVO vo) { } /** - * 更新用户最后一次登录的状态信息 - * - * @param user - * @return + * @description: 更新用户最后一次登录的状态信息 + * @param: user + * @date: 2019-08-17 11:06 AM + * @return: com.zyd.shiro.business.entity.User */ @Override public User updateUserLastLoginInfo(User user) { @@ -231,10 +263,10 @@ public User updateUserLastLoginInfo(User user) { } /** - * 根据用户名查找 - * - * @param userName - * @return + * @description: 根据用户名获取指定的用户信息 + * @param: userName + * @date: 2019-08-17 11:08 AM + * @return: com.zyd.shiro.business.entity.User */ @Override public User getByUserName(String userName) { @@ -243,10 +275,10 @@ public User getByUserName(String userName) { } /** - * 通过角色Id获取用户列表 - * - * @param roleId - * @return + * @description: 通过角色id获取用户列表 + * @param: roleId + * @date: 2019-08-17 11:10 AM + * @return: java.util.List */ @Override public List listByRoleId(Long roleId) { diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/shiro/credentials/CredentialsMatcher.java b/shiro-core/src/main/java/com/zyd/shiro/business/shiro/credentials/CredentialsMatcher.java index a57dd2b..a2b24b6 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/shiro/credentials/CredentialsMatcher.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/shiro/credentials/CredentialsMatcher.java @@ -36,14 +36,22 @@ */ public class CredentialsMatcher extends SimpleCredentialsMatcher { + /** + * @description: 用户密码加密 + * @param: token 用户登录信息 + * @param: info 用户认证信息 + * @date: 2019-08-13 1:12 PM + * @return: boolean + */ @Override public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { UsernamePasswordToken utoken = (UsernamePasswordToken) token; //获得用户输入的密码:(可以采用加盐(salt)的方式去检验) String inPassword = new String(utoken.getPassword()); - //获得数据库中的密码 + //根据用户的认证信息获得数据库中的密码 String dbPassword = (String) info.getCredentials(); try { + //解密数据库中的用户密码 dbPassword = PasswordUtil.decrypt(dbPassword, utoken.getUsername()); } catch (Exception e) { e.printStackTrace(); diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/shiro/realm/ShiroRealm.java b/shiro-core/src/main/java/com/zyd/shiro/business/shiro/realm/ShiroRealm.java index eb9de16..88b484a 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/shiro/realm/ShiroRealm.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/shiro/realm/ShiroRealm.java @@ -62,7 +62,10 @@ public class ShiroRealm extends AuthorizingRealm { private SysRoleService roleService; /** - * 提供账户信息返回认证信息(用户的角色信息集合) + * @description: 登录认证:提供帐户信息,返回认证信息(用户的角色信息集合) + * @param: token + * @date: 2019-08-13 1:33 PM + * @return: org.apache.shiro.authc.AuthenticationInfo */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { @@ -86,21 +89,22 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) } /** - * 权限认证,为当前登录的Subject授予角色和权限(角色的权限信息集合) + * @description: 授权认证:提供用户信息(当前登录的Subject),返回权限信息(角色的权限信息集合) + * @param: principalCollection + * @date: 2019-08-13 1:34 PM + * @return: org.apache.shiro.authz.AuthorizationInfo */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { // 权限信息对象info,用来存放查出的用户的所有的角色(role)及权限(permission) SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); - + //获取用户id Long userId = (Long) SecurityUtils.getSubject().getPrincipal(); - // 赋予角色 List roleList = roleService.listRolesByUserId(userId); for (Role role : roleList) { info.addRole(role.getName()); } - // 赋予权限 List resourcesList = null; User user = userService.getByPrimaryKey(userId); diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/vo/ResourceConditionVO.java b/shiro-core/src/main/java/com/zyd/shiro/business/vo/ResourceConditionVO.java index 32a9e34..4481e1b 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/vo/ResourceConditionVO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/vo/ResourceConditionVO.java @@ -19,22 +19,19 @@ */ package com.zyd.shiro.business.vo; -import com.zyd.shiro.business.entity.Resources; import com.zyd.shiro.framework.object.BaseConditionVO; import lombok.Data; import lombok.EqualsAndHashCode; /** - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 资源信息 + * @date: 2019-08-15 10:26 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) public class ResourceConditionVO extends BaseConditionVO { private String type; } - diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/vo/RoleConditionVO.java b/shiro-core/src/main/java/com/zyd/shiro/business/vo/RoleConditionVO.java index 5f73865..9163148 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/vo/RoleConditionVO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/vo/RoleConditionVO.java @@ -25,16 +25,14 @@ import lombok.EqualsAndHashCode; /** - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 角色信息 + * @date: 2019-08-15 10:26 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) public class RoleConditionVO extends BaseConditionVO { private Role role; } - diff --git a/shiro-core/src/main/java/com/zyd/shiro/business/vo/UserConditionVO.java b/shiro-core/src/main/java/com/zyd/shiro/business/vo/UserConditionVO.java index ed9da8e..2dffc99 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/business/vo/UserConditionVO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/business/vo/UserConditionVO.java @@ -25,12 +25,11 @@ import lombok.EqualsAndHashCode; /** - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户信息 + * @date: 2019-08-15 10:20 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/DruidConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/DruidConfig.java index 1bc65ad..1cb96c1 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/DruidConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/DruidConfig.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -37,13 +37,11 @@ import java.util.List; /** - * Druid Monitor 配置 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2017/9/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: Druid Monitor的配置信息 + * @date: 2019-08-15 11:38 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration public class DruidConfig { @@ -55,29 +53,29 @@ public class DruidConfig { public ServletRegistrationBean druidStatViewServlet() { ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), druidProperties.getServletPath()); - // IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page. + // IP黑名单(存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry,you are not permitted to view this page. List denyIps = druidProperties.getDenyIps(); - if(!CollectionUtils.isEmpty(denyIps)){ + if (!CollectionUtils.isEmpty(denyIps)) { bean.addInitParameter("deny", StringUtils.collectionToDelimitedString(denyIps, ",")); } - // IP白名单 List allowIps = druidProperties.getAllowIps(); - if(!CollectionUtils.isEmpty(allowIps)){ + if (!CollectionUtils.isEmpty(allowIps)) { bean.addInitParameter("allow", StringUtils.collectionToDelimitedString(allowIps, ",")); } - - // 登录查看信息的账号密码. + // 登录查看信息的账号密码 bean.addInitParameter("loginUsername", druidProperties.getUsername()); bean.addInitParameter("loginPassword", druidProperties.getPassword()); - // 禁用HTML页面上的"Reset All"功能(默认false) + // 禁用HTML页面上的"Reset All"功能(默认false) bean.addInitParameter("resetEnable", String.valueOf(druidProperties.getResetEnable())); return bean; } /** - * Druid的StatFilter - * @return + * @description: 配置Druid的StatFilter + * @param: + * @date: 2019-08-15 11:39 AM + * @return: org.springframework.boot.web.servlet.FilterRegistrationBean */ @Bean public FilterRegistrationBean druidStatFilter() { @@ -85,7 +83,7 @@ public FilterRegistrationBean druidStatFilter() { // 添加过滤规则 bean.addUrlPatterns("/*"); // 排除的url - bean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); + bean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); return bean; } } diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/ErrorPagesConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/ErrorPagesConfig.java index cdbb4df..943a46d 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/ErrorPagesConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/ErrorPagesConfig.java @@ -31,21 +31,20 @@ import org.springframework.stereotype.Component; /** - * 自定义的异常页面配置 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 自定义异常页的配置类 + * @date: 2019-08-15 11:40 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Component public class ErrorPagesConfig { /** - * 自定义异常处理路径 - * - * @return + * @description: 自定义异常处理路径 + * @param: + * @date: 2019-08-15 11:40 AM + * @return: org.springframework.boot.web.server.WebServerFactoryCustomizer */ @Bean public WebServerFactoryCustomizer containerCustomizer() { diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/FreeMarkerConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/FreeMarkerConfig.java index c982544..7326605 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/FreeMarkerConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/FreeMarkerConfig.java @@ -28,12 +28,11 @@ import javax.annotation.PostConstruct; /** - * freemarker配置类 - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: FreeMarker配置类 + * @date: 2019-08-15 11:42 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration public class FreeMarkerConfig { @@ -44,7 +43,10 @@ public class FreeMarkerConfig { protected CustomTagDirective customTagDirective; /** - * 添加自定义标签 + * @description: 添加自定义标签 + * @param: + * @date: 2019-08-15 11:42 AM + * @return: void */ @PostConstruct public void setSharedVariable() { diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/MybatisConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/MybatisConfig.java index 18fcac7..efda77e 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/MybatisConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/MybatisConfig.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -27,12 +27,11 @@ import org.springframework.stereotype.Component; /** - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: MyBatis配置类 + * @date: 2019-08-15 11:42 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Component @MapperScan("com.zyd.shiro.persistence.mapper") diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/RedisConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/RedisConfig.java index 12255f7..0810668 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/RedisConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/RedisConfig.java @@ -43,20 +43,21 @@ /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: Redis配置类 + * @date: 2019-08-15 11:42 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration @EnableCaching public class RedisConfig extends CachingConfigurerSupport { /** - * 缓存数据时Key的生成器,可以依据业务和技术场景自行定制 - * - * @return + * @description: 缓存数据时Key的生成器, 可依据业务和技术场景自行定制 + * @param: + * @date: 2019-08-15 11:44 AM + * @return: org.springframework.cache.interceptor.KeyGenerator */ @Bean @Override @@ -77,7 +78,7 @@ public KeyGenerator keyGenerator() { @Bean public CacheManager cacheManager(RedisConnectionFactory factory) { return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(factory)) - // 默认缓存过期时间:天 + // 默认缓存过期时间:30天 .cacheDefaults(RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(30))) .transactionAware() .build(); diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/ShiroConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/ShiroConfig.java index 894ff2f..75c487f 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/ShiroConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/ShiroConfig.java @@ -48,13 +48,11 @@ import java.util.Map; /** - * Shiro配置类 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/24 14:37 - * @since 1.0 + * @project: springboot-shiro + * @description: Shiro配置类 + * @date: 2019-08-15 11:42 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration @Order(-1) @@ -65,38 +63,54 @@ public class ShiroConfig { @Autowired private RedisProperties redisProperties; + /** + * @description: 将Shiro安全管理器注入到Bean的实例 + * @param: securityManager + * @date: 2019-08-15 11:48 AM + * @return: org.springframework.beans.factory.config.MethodInvokingFactoryBean + */ @Bean - public MethodInvokingFactoryBean methodInvokingFactoryBean(SecurityManager securityManager){ + public MethodInvokingFactoryBean methodInvokingFactoryBean(SecurityManager securityManager) { MethodInvokingFactoryBean bean = new MethodInvokingFactoryBean(); bean.setStaticMethod("org.apache.shiro.SecurityUtils.setSecurityManager"); bean.setArguments(securityManager); return bean; } + /** + * @description: 生命周期处理器 + * @param: + * @date: 2019-08-15 11:48 AM + * @return: org.apache.shiro.spring.LifecycleBeanPostProcessor + */ @Bean(name = "lifecycleBeanPostProcessor") public static LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } + /* + * Filter Chain定义说明: + * 1、一个URL可以配置多个Filter,使用逗号分隔 + * 2、当设置多个过滤器时,全部验证通过,才视为通过 + * 3、部分过滤器可指定参数,如perms,roles + */ + /** - * ShiroFilterFactoryBean 处理拦截资源文件问题。 - * 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在 - * 初始化ShiroFilterFactoryBean的时候需要注入:SecurityManager - * Filter Chain定义说明 - * 1、一个URL可以配置多个Filter,使用逗号分隔 - * 2、当设置多个过滤器时,全部验证通过,才视为通过 - * 3、部分过滤器可指定参数,如perms,roles + * @description: 配置Shiro过滤器 + * @param: securityManager + * @date: 2019-08-15 11:49 AM + * @return: org.apache.shiro.spring.web.ShiroFilterFactoryBean */ @Bean(name = "shiroFilter") public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); - // 必须设置 SecurityManager + // 必须设置SecurityManager shiroFilterFactoryBean.setSecurityManager(securityManager); // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面 shiroFilterFactoryBean.setLoginUrl("/passport/login/"); - // 登录成功后要跳转的链接 + // 指定登录成功后要跳转的链接 shiroFilterFactoryBean.setSuccessUrl("/index"); - // 未授权界面; + // 指定未授权操作要跳转的链接 shiroFilterFactoryBean.setUnauthorizedUrl("/error/403"); // 配置数据库中的resource Map filterChainDefinitionMap = shiroService.loadFilterChainDefinitions(); @@ -104,6 +118,12 @@ public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { return shiroFilterFactoryBean; } + /** + * @description: 开启shiro注解模式(如果使用注解模式, 必须采用cglib针对类进行代理) + * @param: + * @date: 2019-08-15 11:50 AM + * @return: org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator + */ @Bean @DependsOn("lifecycleBeanPostProcessor") public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { @@ -112,33 +132,57 @@ public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { return creator; } + /** + * @description: 开启Shiro-aop注解支持(采用cglib针对类进行代理) + * @param: securityManager + * @date: 2019-08-15 11:54 AM + * @return: org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor + */ + @Bean + public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { + AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); + authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); + return authorizationAttributeSourceAdvisor; + } + + /** + * @description: 配置安全管理器 + * @param: authRealm + * @date: 2019-08-15 11:51 AM + * @return: org.apache.shiro.mgt.SecurityManager + */ @Bean(name = "securityManager") public SecurityManager securityManager(@Qualifier("shiroRealm") ShiroRealm authRealm) { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); - // 设置realm. + // 关联自定义realm securityManager.setRealm(authRealm); + // 关联安全管理器 securityManager.setCacheManager(redisCacheManager()); - // 自定义session管理 使用redis + // 自定义Session管理器 securityManager.setSessionManager(sessionManager()); - // 注入记住我管理器 + // 关联Cookie管理器 securityManager.setRememberMeManager(rememberMeManager()); return securityManager; } - @Bean(name = "shiroRealm") + /** + * @description: 配置自定义Realm + * @param: matcher + * @date: 2019-08-15 11:51 AM + * @return: com.zyd.shiro.business.shiro.realm.ShiroRealm + */ + @Bean(name = "shiroRealm")//the parameter is never used public ShiroRealm shiroRealm(@Qualifier("credentialsMatcher") RetryLimitCredentialsMatcher matcher) { ShiroRealm shiroRealm = new ShiroRealm(); - shiroRealm.setCredentialsMatcher(credentialsMatcher()); + shiroRealm.setCredentialsMatcher(credentialsMatcher()); //设置凭证匹配器 return shiroRealm; } /** - * 凭证匹配器 - * (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了 - * 所以我们需要修改下doGetAuthenticationInfo中的代码; - * ) - * - * @return + * @description: 自定义凭证匹配器 + * @param: + * @date: 2019-08-15 11:53 AM + * @return: com.zyd.shiro.business.shiro.credentials.RetryLimitCredentialsMatcher */ @Bean(name = "credentialsMatcher") public RetryLimitCredentialsMatcher credentialsMatcher() { @@ -147,24 +191,10 @@ public RetryLimitCredentialsMatcher credentialsMatcher() { /** - * 开启shiro aop注解支持. - * 使用代理方式;所以需要开启代码支持; - * - * @param securityManager - * @return - */ - @Bean - public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { - AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); - authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); - return authorizationAttributeSourceAdvisor; - } - - /** - * 配置shiro redisManager - * 使用的是shiro-redis开源插件 - * - * @return + * @description: Redis管理器(使用的是shiro - redis开源插件) + * @param: + * @date: 2019-08-15 11:54 AM + * @return: org.crazycake.shiro.RedisManager */ public RedisManager redisManager() { CustomRedisManager redisManager = new CustomRedisManager(); @@ -177,32 +207,36 @@ public RedisManager redisManager() { } /** - * cacheManager 缓存 redis实现 - * 使用的是shiro-redis开源插件 - * - * @return + * @description: Redis缓存管理器(使用的是shiro - redis开源插件) + * @param: + * @date: 2019-08-15 11:55 AM + * @return: org.crazycake.shiro.RedisCacheManager */ @Bean public RedisCacheManager redisCacheManager() { RedisCacheManager redisCacheManager = new RedisCacheManager(); - redisCacheManager.setRedisManager(redisManager()); + redisCacheManager.setRedisManager(redisManager()); //设置Redis管理器 return redisCacheManager; } /** - * RedisSessionDAO shiro sessionDao层的实现 通过redis - * 使用的是shiro-redis开源插件 + * @description: RedisSessionDAO:shiro sessionDao层的实现(使用的是shiro-redis开源插件) + * @param: + * @date: 2019-08-15 11:56 AM + * @return: org.crazycake.shiro.RedisSessionDAO */ -// @Bean public RedisSessionDAO redisSessionDAO() { RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); - redisSessionDAO.setRedisManager(redisManager()); + redisSessionDAO.setRedisManager(redisManager()); //设置Redis管理器 return redisSessionDAO; } /** - * shiro session的管理 + * @description: Session管理器 + * @param: + * @date: 2019-08-15 11:57 AM + * @return: org.apache.shiro.web.session.mgt.DefaultWebSessionManager */ @Bean public DefaultWebSessionManager sessionManager() { @@ -213,27 +247,29 @@ public DefaultWebSessionManager sessionManager() { } /** - * cookie对象; - * - * @return + * @description: 设置Cookie(RememberMe功能) + * @param: + * @date: 2019-08-15 11:58 AM + * @return: org.apache.shiro.web.servlet.SimpleCookie */ public SimpleCookie rememberMeCookie() { - // 这个参数是cookie的名称,对应前端的checkbox的name = rememberMe + // 这个参数是cookie的名称,对应前端的checkbox的name = rememberMe SimpleCookie simpleCookie = new SimpleCookie("rememberMe"); - // 记住我cookie生效时间30天 ,单位秒。 注释掉,默认永久不过期 2018-07-15 + // 记住我cookie生效时间30天,单位秒,默认情况下永不过期 simpleCookie.setMaxAge(redisProperties.getExpire()); return simpleCookie; } /** - * cookie管理对象;记住我功能 - * - * @return + * @description: Cookie管理器(开启RememberMe功能) + * @param: + * @date: 2019-08-15 11:58 AM + * @return: org.apache.shiro.web.mgt.CookieRememberMeManager */ public CookieRememberMeManager rememberMeManager() { CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager(); cookieRememberMeManager.setCookie(rememberMeCookie()); - //rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位) + //设置rememberMe cookie加密的密钥,建议每个项目都不一样,默认AES算法:密钥长度(128 256 512 位) cookieRememberMeManager.setCipherKey(Base64.decode("1QWLxg+NYmxraMoxAXu/Iw==")); return cookieRememberMeManager; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/config/WebMvcConfig.java b/shiro-core/src/main/java/com/zyd/shiro/framework/config/WebMvcConfig.java index 1724579..fc8c310 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/config/WebMvcConfig.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/config/WebMvcConfig.java @@ -26,11 +26,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/7/15 15:03 - * @since 1.0 + * @project: springboot-shiro + * @description: WebMVC配置类 + * @date: 2019-08-15 1:29 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration public class WebMvcConfig implements WebMvcConfigurer { diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/holder/RequestHolder.java b/shiro-core/src/main/java/com/zyd/shiro/framework/holder/RequestHolder.java index 71cd5bc..baf5fc3 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/holder/RequestHolder.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/holder/RequestHolder.java @@ -33,20 +33,20 @@ import javax.servlet.http.HttpSession; /** - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 请求层的基础支架 + * @date: 2019-08-16 2:07 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j public class RequestHolder { /** - * 获取request - * - * @return HttpServletRequest + * @description: 获取request + * @param: + * @date: 2019-08-16 2:09 PM + * @return: javax.servlet.http.HttpServletRequest */ public static HttpServletRequest getRequest() { log.debug("getRequest -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); @@ -58,9 +58,10 @@ public static HttpServletRequest getRequest() { } /** - * 获取Response - * - * @return HttpServletRequest + * @description: (never used)获取Response + * @param: + * @date: 2019-08-16 2:11 PM + * @return: javax.servlet.http.HttpServletResponse */ public static HttpServletResponse getResponse() { log.debug("getResponse -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); @@ -72,9 +73,10 @@ public static HttpServletResponse getResponse() { } /** - * 获取session - * - * @return HttpSession + * @description: (never used)获取session + * @param: + * @date: 2019-08-16 2:11 PM + * @return: javax.servlet.http.HttpSession */ public static HttpSession getSession() { log.debug("getSession -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); @@ -86,10 +88,10 @@ public static HttpSession getSession() { } /** - * 获取session的Attribute - * - * @param name session的key - * @return Object + * @description: 获取session中的Attribute + * @param: name + * @date: 2019-08-16 2:12 PM + * @return: java.lang.Object */ public static Object getSession(String name) { log.debug("getSession -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); @@ -101,10 +103,11 @@ public static Object getSession(String name) { } /** - * 添加session - * - * @param name - * @param value + * @description: 添加session + * @param: name + * @param: value + * @date: 2019-08-16 2:14 PM + * @return: void */ public static void setSession(String name, Object value) { log.debug("setSession -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); @@ -116,10 +119,10 @@ public static void setSession(String name, Object value) { } /** - * 清除指定session - * - * @param name - * @return void + * @description: 清除指定session + * @param: name + * @date: 2019-08-16 2:15 PM + * @return: void */ public static void removeSession(String name) { log.debug("removeSession -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); @@ -131,9 +134,10 @@ public static void removeSession(String name) { } /** - * 获取所有session key - * - * @return String[] + * @description: 获取所有的session key + * @param: + * @date: 2019-08-16 2:15 PM + * @return: java.lang.String[] */ public static String[] getSessionKeys() { log.debug("getSessionKeys -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName()); diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/holder/SpringContextHolder.java b/shiro-core/src/main/java/com/zyd/shiro/framework/holder/SpringContextHolder.java index 1c33792..55bf32f 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/holder/SpringContextHolder.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/holder/SpringContextHolder.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,11 +29,11 @@ import org.springframework.stereotype.Component; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: SpringContext的基础支架 + * @date: 2019-08-16 3:18 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Component public class SpringContextHolder implements ApplicationContextAware { @@ -41,10 +41,10 @@ public class SpringContextHolder implements ApplicationContextAware { private static ApplicationContext appContext = null; /** - * 通过name获取 Bean. - * - * @param name - * @return + * @description: (never used)通过name获取指定的Bean + * @param: name + * @date: 2019-08-16 3:20 PM + * @return: java.lang.Object */ public static Object getBean(String name) { return appContext.getBean(name); @@ -52,28 +52,32 @@ public static Object getBean(String name) { } /** - * 通过class获取Bean. - * - * @param clazz - * @param - * @return + * @description: 通过class获取指定的Bean + * @param: clazz + * @date: 2019-08-16 3:20 PM + * @return: T */ public static T getBean(Class clazz) { return appContext.getBean(clazz); } /** - * 通过name,以及Clazz返回指定的Bean - * - * @param name - * @param clazz - * @param - * @return + * @description: (never used)通过name及clazz获取指定的Bean + * @param: name + * @param: clazz + * @date: 2019-08-16 3:21 PM + * @return: T */ public static T getBean(String name, Class clazz) { return appContext.getBean(name, clazz); } + /** + * @description: 初始化applicationContext + * @param: applicationContext + * @date: 2019-08-16 3:21 PM + * @return: void + */ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (appContext == null) { diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractBO.java b/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractBO.java index 795ac71..02dc935 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractBO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractBO.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,11 +26,11 @@ import java.io.Serializable; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: (Business Object)业务对象 + * @date: 2019-08-16 3:37 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public abstract class AbstractBO implements Serializable { private static final long serialVersionUID = -3737736141782545763L; diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractDO.java b/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractDO.java index dce65ff..cfe517e 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractDO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractDO.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -33,22 +33,22 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: (Data Transfer Object)数据传输对象 + * @date: 2019-08-16 3:41 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) public abstract class AbstractDO implements Serializable { + /** * @fieldName: serialVersionUID * @fieldType: long */ private static final long serialVersionUID = 5088697673359856350L; - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractService.java b/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractService.java index 2fb2a74..8fb5f12 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractService.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractService.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,81 +26,83 @@ import java.util.List; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 通用的Service接口:提高代码的简洁及可维护性 + * @date: 2019-08-16 3:47 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface AbstractService { /** - * 保存一个实体,null的属性不会保存,会使用数据库默认值 - * - * @param entity - * @return + * @description: 保存一个实体, null的属性不会保存(使用数据库默认值) + * @param: entity + * @date: 2019-08-16 3:47 PM + * @return: T */ T insert(T entity); /** - * 批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 - * - * @param entities + * @description: 批量插入:既支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 + * @param: entities + * @date: 2019-08-16 4:05 PM + * @return: void */ void insertList(List entities); /** - * 根据主键字段进行删除,方法参数必须包含完整的主键属性 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 + * @param: primaryKey + * @date: 2019-08-16 4:06 PM + * @return: boolean */ boolean removeByPrimaryKey(PK primaryKey); /** - * 根据主键更新实体全部字段,null值会被更新 - * - * @param entity - * @return + * @description: 根据主键更新实体全部字段, null值也会被更新 + * @param: entity + * @date: 2019-08-16 4:07 PM + * @return: boolean */ boolean update(T entity); /** - * 根据主键更新属性不为null的值 - * - * @param entity - * @return + * @description: 根据主键更新属性不为null的值 + * @param: entity + * @date: 2019-08-16 4:08 PM + * @return: boolean */ boolean updateSelective(T entity); /** - * 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 - * - * @param primaryKey - * @return + * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 + * @param: primaryKey + * @date: 2019-08-16 4:09 PM + * @return: T */ T getByPrimaryKey(PK primaryKey); /** - * 根据实体中的属性进行查询,只能有一个返回值,有多个结果时抛出异常,查询条件使用等号 - * - * @param entity - * @return + * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 + * @param: entity + * @date: 2019-08-16 4:11 PM + * @return: T */ T getOneByEntity(T entity); /** - * 查询全部结果,listByEntity(null)方法能达到同样的效果 - * - * @return + * @description: 查询全部结果, 注:listByEntity(null)方法能达到同样的效果 + * @param: + * @date: 2019-08-16 4:12 PM + * @return: java.util.List */ List listAll(); /** - * 根据实体中的属性值进行查询,查询条件使用等号 - * - * @param entity - * @return + * @description: (never used)根据实体中的属性值进行查询, 查询条件使用等号 + * @param: entity + * @date: 2019-08-16 4:12 PM + * @return: java.util.List */ List listByEntity(T entity); -} \ No newline at end of file +} diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/object/BaseConditionVO.java b/shiro-core/src/main/java/com/zyd/shiro/framework/object/BaseConditionVO.java index f797155..9371c6c 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/object/BaseConditionVO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/object/BaseConditionVO.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -30,11 +30,11 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 基础的条件值对象(Value Object) + * @date: 2019-08-16 4:30 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) @@ -55,6 +55,7 @@ public int getPageSize() { return pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE; } + //the method is never used public int getPageStart() { return pageNumber > 0 ? (pageNumber - 1) * getPageSize() : 0; } diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/object/PageResult.java b/shiro-core/src/main/java/com/zyd/shiro/framework/object/PageResult.java index 1741cd9..e26d6a8 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/object/PageResult.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/object/PageResult.java @@ -25,13 +25,11 @@ import java.util.List; /** - * bootstrap table用到的返回json格式 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 分页结果:BootStrap table中需获取的json格式数据 + * @date: 2019-08-16 4:17 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) @@ -44,6 +42,7 @@ public PageResult(Long total, List rows) { this.rows = rows; } + //the constructor is never used public PageResult() { } } diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/object/ResponseVO.java b/shiro-core/src/main/java/com/zyd/shiro/framework/object/ResponseVO.java index 37aeeb5..f1b1d98 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/object/ResponseVO.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/object/ResponseVO.java @@ -29,13 +29,11 @@ import java.util.List; /** - * controller返回json - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: Controller层需返回的json格式数据 + * @date: 2019-08-16 4:17 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) @@ -50,10 +48,12 @@ public ResponseVO(Integer status, String message, T data) { this.data = data; } + //the constructor is never used public ResponseVO(ResponseStatus status, T data) { this(status.getCode(), status.getMessage(), data); } + //the method is never used public String toJson() { T t = this.getData(); if (t instanceof List || t instanceof Collection) { diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/property/DruidProperties.java b/shiro-core/src/main/java/com/zyd/shiro/framework/property/DruidProperties.java index c78c6c4..cd92787 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/property/DruidProperties.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/property/DruidProperties.java @@ -28,13 +28,11 @@ import java.util.List; /** - * druid属性 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/5/17 11:13 - * @since 1.0 + * @project: springboot-shiro + * @description: druid属性信息 + * @date: 2019-08-15 11:35 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration @ConfigurationProperties(prefix = "zyd.druid") diff --git a/shiro-core/src/main/java/com/zyd/shiro/framework/property/RedisProperties.java b/shiro-core/src/main/java/com/zyd/shiro/framework/property/RedisProperties.java index d6fe8f0..a6f407e 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/framework/property/RedisProperties.java +++ b/shiro-core/src/main/java/com/zyd/shiro/framework/property/RedisProperties.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -30,13 +30,11 @@ import org.springframework.core.annotation.Order; /** - * redis属性配置文件 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: redis属性信息 + * @date: 2019-08-15 11:37 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Configuration @ConfigurationProperties(prefix = "spring.redis") diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysResources.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysResources.java index ff2797a..3508bac 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysResources.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysResources.java @@ -27,11 +27,11 @@ import java.util.List; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 资源信息 + * @date: 2019-08-14 2:19 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRole.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRole.java index 0a07911..83b9911 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRole.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRole.java @@ -26,11 +26,11 @@ import javax.persistence.Transient; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 角色信息 + * @date: 2019-08-14 2:22 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRoleResources.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRoleResources.java index c5933f0..ab1d37f 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRoleResources.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRoleResources.java @@ -24,11 +24,11 @@ import lombok.EqualsAndHashCode; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 连接用户与资源信息的桥梁 + * @date: 2019-08-14 2:23 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUser.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUser.java index 0f6f653..f5c5c41 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUser.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUser.java @@ -26,11 +26,11 @@ import java.util.Date; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户信息 + * @date: 2019-08-14 1:56 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUserRole.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUserRole.java index c6b8860..2698c8a 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUserRole.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUserRole.java @@ -24,11 +24,11 @@ import lombok.EqualsAndHashCode; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 连接用户与角色信息的桥梁 + * @date: 2019-08-14 2:32 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Data @EqualsAndHashCode(callSuper = false) diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysResourceMapper.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysResourceMapper.java index bdc52ce..eca6aaa 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysResourceMapper.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysResourceMapper.java @@ -28,39 +28,68 @@ import java.util.Map; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 操控系统资源信息 + * @date: 2019-08-14 3:06 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Repository public interface SysResourceMapper extends BaseMapper { /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询系统资源 + * @param: vo + * @date: 2019-08-14 3:08 PM + * @return: java.util.List */ List findPageBreakByCondition(ResourceConditionVO vo); + /** + * @description: 获取用户的资源列表 + * @param: map + * @date: 2019-08-14 3:10 PM + * @return: java.util.List + */ List listUserResources(Map map); /** - * 该节代码参考自http://blog.csdn.net/poorcoder_/article/details/71374002 - * 感谢网友 - * - * @param rid - * @return + * @description: 根据角色id获取ztree使用的资源列表, 代码参考自 http://blog.csdn.net/poorcoder_/article/details/71374002 + * @param: rid + * @date: 2019-08-14 3:12 PM + * @return: java.util.List */ List queryResourcesListWithSelected(Long rid); + /** + * @description: 获取资源的url和Permission + * @param: + * @date: 2019-08-14 3:13 PM + * @return: java.util.List + */ List listUrlAndPermission(); + /** + * @description: 获取所有可用的菜单资源 + * @param: + * @date: 2019-08-14 3:15 PM + * @return: java.util.List + */ List listAllAvailableMenu(); + /** + * @description: 通过父级菜单id获取父级资源下所有menu资源 + * @param: pid + * @date: 2019-08-14 3:16 PM + * @return: java.util.List + */ List listMenuResourceByPid(Long pid); + /** + * @description: 通过用户id获取用户关联的所有资源 + * @param: userId + * @date: 2019-08-14 3:18 PM + * @return: java.util.List + */ List listByUserId(Long userId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleMapper.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleMapper.java index 4a9058b..56ab172 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleMapper.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleMapper.java @@ -27,31 +27,36 @@ import java.util.List; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 操控系统角色信息 + * @date: 2019-08-14 2:48 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Repository public interface SysRoleMapper extends BaseMapper { /** - * 分页查询 - * - * @param vo - * @return + * @description: 分页查询角色信息 + * @param: vo + * @date: 2019-08-14 2:49 PM + * @return: java.util.List */ List findPageBreakByCondition(RoleConditionVO vo); /** - * 该节代码参考自http://blog.csdn.net/poorcoder_/article/details/71374002 - * 感谢网友 - * - * @param userId - * @return + * @description: 通过用户id获取ztree使用的角色列表, 代码参考自 http://blog.csdn.net/poorcoder_/article/details/71374002 + * @param: userId + * @date: 2019-08-14 2:50 PM + * @return: java.util.List */ List queryRoleListWithSelected(Integer userId); + /** + * @description: 通过用户id获取用户所拥有的角色信息 + * @param: userId + * @date: 2019-08-14 2:51 PM + * @return: java.util.List + */ List listRolesByUserId(Long userId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleResourcesMapper.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleResourcesMapper.java index b2915e3..854248a 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleResourcesMapper.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleResourcesMapper.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,11 +28,11 @@ import org.springframework.stereotype.Repository; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 角色与资源信息的连表操作 + * @date: 2019-08-14 3:39 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Repository public interface SysRoleResourcesMapper extends BaseMapper { diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserMapper.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserMapper.java index 524d9bf..ad88f30 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserMapper.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserMapper.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,17 +31,29 @@ import java.util.List; /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 操控系统用户信息 + * @date: 2019-08-14 2:47 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Repository public interface SysUserMapper extends BaseMapper { + /** + * @description: 分页查询用户信息 + * @param: vo + * @date: 2019-08-14 2:34 PM + * @return: java.util.List + */ List findPageBreakByCondition(UserConditionVO vo); + /** + * @description: 通过角色Id获取用户列表 + * @param: roleId + * @date: 2019-08-14 2:34 PM + * @return: java.util.List + */ List listByRoleId(Long roleId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserRoleMapper.java b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserRoleMapper.java index 54a5fa2..55d5375 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserRoleMapper.java +++ b/shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserRoleMapper.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2018 yadong.zhang - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,14 +29,22 @@ import java.util.List; + /** - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 用户与角色信息的连表操作 + * @date: 2019-08-14 2:59 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Repository public interface SysUserRoleMapper extends BaseMapper { + + /** + * @description: (never used)通过角色id查询指定的用户信息 + * @param: roleId + * @date: 2019-08-14 3:04 PM + * @return: java.util.List + */ List findUserIdByRoleId(Integer roleId); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/plugin/BaseMapper.java b/shiro-core/src/main/java/com/zyd/shiro/plugin/BaseMapper.java index dcabc53..1170bdd 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/plugin/BaseMapper.java +++ b/shiro-core/src/main/java/com/zyd/shiro/plugin/BaseMapper.java @@ -23,14 +23,12 @@ import tk.mybatis.mapper.common.MySqlMapper; /** - * 公有Mapper - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 通用的Mapper接口:提高代码的简洁及可维护性 + * @date: 2019-08-16 3:51 PM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public interface BaseMapper extends Mapper, MySqlMapper { - // 特别注意,该接口不能被扫描到,否则会出错 + // 特别注意:该接口不能被扫描到,否则会出错 } diff --git a/shiro-core/src/main/java/com/zyd/shiro/util/AesUtil.java b/shiro-core/src/main/java/com/zyd/shiro/util/AesUtil.java index 84d6297..c9a3143 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/util/AesUtil.java +++ b/shiro-core/src/main/java/com/zyd/shiro/util/AesUtil.java @@ -29,83 +29,71 @@ import java.security.SecureRandom; /** - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @website https://www.zhyd.me - * @version 1.0 - * @date 2018/4/16 16:26 - * @since 1.0 + * @project: springboot-shiro + * @description: 加密工具类:AES(Advanced Encryption Standard),又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准 + * @date: 2019-08-15 10:35 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class AesUtil { private static final String KEY_ALGORITHM = "AES"; private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding"; /** - * AES加密 - * - * @param passwd - * 加密的密钥 - * @param content - * 需要加密的字符串 - * @return 返回Base64转码后的加密数据 - * @throws Exception + * @description: AES加密 + * @param: passwd 加密的密钥 + * @param: content 需要加密的字符串 + * @date: 2019-08-15 10:40 AM + * @return: java.lang.String 返回Base64转码后的加密数据 */ public static String encrypt(String passwd, String content) throws Exception { // 创建密码器 Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); - + // 指定待加密字符的编码格式 byte[] byteContent = content.getBytes("utf-8"); - // 初始化为加密模式的密码器 cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(passwd)); - // 加密 byte[] result = cipher.doFinal(byteContent); - //通过Base64转码返回 return Base64.encodeBase64String(result); } /** - * AES解密 - * - * @param passwd - * 加密的密钥 - * @param encrypted - * 已加密的密文 - * @return 返回解密后的数据 - * @throws Exception + * @description: AES解密 + * @param: passwd 加密的密钥 + * @param: encrypted 已加密的密文 + * @date: 2019-08-15 10:44 AM + * @return: java.lang.String 返回解密后的数据 */ public static String decrypt(String passwd, String encrypted) throws Exception { //实例化 Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); - - //使用密钥初始化,设置为解密模式 + //使用密钥初始化,设置为解密模式 cipher.init(Cipher.DECRYPT_MODE, getSecretKey(passwd)); - - //执行操作 + //解密 byte[] result = cipher.doFinal(Base64.decodeBase64(encrypted)); - + //返回解密后的数据 return new String(result, "utf-8"); } /** - * 生成加密秘钥 - * - * @return + * @description: 生成加密秘钥 + * @param: password + * @date: 2019-08-15 10:46 AM + * @return: javax.crypto.spec.SecretKeySpec */ private static SecretKeySpec getSecretKey(final String password) throws NoSuchAlgorithmException { - //返回生成指定算法密钥生成器的 KeyGenerator 对象 + // 获取生成指定算法密钥生成器的 KeyGenerator 对象 KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); - // javax.crypto.BadPaddingException: Given final block not properly padded解决方案 + // 异常:javax.crypto.BadPaddingException: Given final block not properly padded的解决方案如下 // https://www.cnblogs.com/zempty/p/4318902.html - 用此法解决的 // https://www.cnblogs.com/digdeep/p/5580244.html - 留作参考吧 SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(password.getBytes()); - //AES 要求密钥长度为 128 + // AES要求密钥长度为128 kg.init(128, random); - - //生成一个密钥 + // 生成一个密钥 SecretKey secretKey = kg.generateKey(); // 转换为AES专用密钥 return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM); diff --git a/shiro-core/src/main/java/com/zyd/shiro/util/IpUtil.java b/shiro-core/src/main/java/com/zyd/shiro/util/IpUtil.java index 7c9ed6b..ba61382 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/util/IpUtil.java +++ b/shiro-core/src/main/java/com/zyd/shiro/util/IpUtil.java @@ -24,21 +24,19 @@ import javax.servlet.http.HttpServletRequest; /** - * 获取IP的工具类 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/18 11:48 - * @since 1.0 + * @project: springboot-shiro + * @description: 获取IP的工具类 + * @date: 2019-08-15 10:55 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class IpUtil { /** - * 获取真实IP - * - * @param request - * @return + * @description: 获取真实的IP地址 + * @param: request + * @date: 2019-08-15 10:52 AM + * @return: java.lang.String */ public static String getRealIp(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); @@ -49,10 +47,10 @@ public static String getRealIp(HttpServletRequest request) { } /** - * 校验IP - * - * @param ip - * @return + * @description: 校验IP地址 + * @param: ip + * @date: 2019-08-15 10:53 AM + * @return: boolean */ private static boolean checkIp(String ip) { return !StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip); diff --git a/shiro-core/src/main/java/com/zyd/shiro/util/Md5Util.java b/shiro-core/src/main/java/com/zyd/shiro/util/Md5Util.java index 6e06bd5..09154a5 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/util/Md5Util.java +++ b/shiro-core/src/main/java/com/zyd/shiro/util/Md5Util.java @@ -24,33 +24,31 @@ import java.security.MessageDigest; /** - * MD5加密工具类 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/18 11:48 - * @since 1.0 + * @project: springboot-shiro + * @description: MD5加密工具类 + * @date: 2019-08-15 10:55 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ @Slf4j public class Md5Util { /** - * 通过盐值对字符串进行MD5加密 - * - * @param param 需要加密的字符串 - * @param salt 盐值 - * @return + * @description: (never used)通过盐值对字符串进行MD5加密 + * @param: param 需要加密的字符串 + * @param: salt 盐值 + * @date: 2019-08-15 10:56 AM + * @return: java.lang.String */ public static String MD5(String param, String salt) { return MD5(param + salt); } /** - * 加密字符串 - * - * @param s 字符串 - * @return + * @description: 加密字符串 + * @param: s + * @date: 2019-08-15 10:57 AM + * @return: java.lang.String */ public static String MD5(String s) { char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; diff --git a/shiro-core/src/main/java/com/zyd/shiro/util/PasswordUtil.java b/shiro-core/src/main/java/com/zyd/shiro/util/PasswordUtil.java index 80c566e..cf4f86d 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/util/PasswordUtil.java +++ b/shiro-core/src/main/java/com/zyd/shiro/util/PasswordUtil.java @@ -22,32 +22,33 @@ import com.zyd.shiro.business.consts.CommonConst; /** - * @author: yadong.zhang + * @project: springboot-shiro + * @description: 用户密码加密/解密工具 * @date: 2017/12/15 17:03 + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class PasswordUtil { /** - * AES 加密 - * @param password - * 未加密的密码 - * @param salt - * 盐值,默认使用用户名就可 - * @return * @throws Exception + * @description: AES 加密 + * @param: password 未加密的用户密码 + * @param: salt 默认使用用户名作为盐值 + * @date: 2019-08-13 1:15 PM + * @return: java.lang.String */ public static String encrypt(String password, String salt) throws Exception { return AesUtil.encrypt(Md5Util.MD5(salt + CommonConst.ZYD_SECURITY_KEY), password); } /** - * AES 解密 - * @param encryptPassword - * 加密后的密码 - * @param salt - * 盐值,默认使用用户名就可 - * @return * @throws Exception + * @description: AES 解密 + * @param: encryptPassword 加密后的用户密码 + * @param: salt 默认使用用户名作为盐值 + * @date: 2019-08-13 1:17 PM + * @return: java.lang.String */ public static String decrypt(String encryptPassword, String salt) throws Exception { return AesUtil.decrypt(Md5Util.MD5(salt + CommonConst.ZYD_SECURITY_KEY), encryptPassword); diff --git a/shiro-core/src/main/java/com/zyd/shiro/util/ResultUtil.java b/shiro-core/src/main/java/com/zyd/shiro/util/ResultUtil.java index 2145b5c..cebb166 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/util/ResultUtil.java +++ b/shiro-core/src/main/java/com/zyd/shiro/util/ResultUtil.java @@ -31,13 +31,11 @@ import java.util.Map; /** - * 接口返回工具类,支持ModelAndView、ResponseVO、PageResult - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/18 11:48 - * @since 1.0 + * @project: springboot-shiro + * @description: 接口返回工具类:支持ModelAndView、ResponseVO、PageResult + * @date: 2019-08-15 10:59 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class ResultUtil { @@ -45,6 +43,7 @@ public static ModelAndView view(String view) { return new ModelAndView(view); } + //the method is not used public static ModelAndView view(String view, Map model) { return new ModelAndView(view, model); } diff --git a/shiro-core/src/main/java/com/zyd/shiro/util/SessionUtil.java b/shiro-core/src/main/java/com/zyd/shiro/util/SessionUtil.java index d33116c..987bfae 100644 --- a/shiro-core/src/main/java/com/zyd/shiro/util/SessionUtil.java +++ b/shiro-core/src/main/java/com/zyd/shiro/util/SessionUtil.java @@ -26,66 +26,79 @@ import java.util.UUID; /** - * Session工具类 - * - * @author yadong.zhang (yadong.zhang0415(a)gmail.com) - * @version 1.0 - * @website https://www.zhyd.me - * @date 2018/4/18 11:48 - * @since 1.0 + * @project: springboot-shiro + * @description: Session工具类 + * @date: 2019-08-15 11:04 AM + * @version: 1.0 + * @website: https://yubuntu0109.github.io/ */ public class SessionUtil { /** - * 获取session中的用户信息 - * - * @return User + * @description: 获取session中的用户信息 + * @param: + * @date: 2019-08-15 11:04 AM + * @return: com.zyd.shiro.business.entity.User */ public static User getUser() { return (User) RequestHolder.getSession(SessionConst.USER_SESSION_KEY); } /** - * 添加session - * - * @param user + * @description: 将用户信息添加到session + * @param: user + * @date: 2019-08-15 11:05 AM + * @return: void */ public static void setUser(User user) { RequestHolder.setSession(SessionConst.USER_SESSION_KEY, user); } /** - * 删除session信息 + * @description: 删除session中的用户信息 + * @param: + * @date: 2019-08-15 11:05 AM + * @return: void */ public static void removeUser() { RequestHolder.removeSession(SessionConst.USER_SESSION_KEY); } /** - * 获取session中的Token信息 - * - * @return String + * @description: 获取session中的Token信息 + * @param: key + * @date: 2019-08-15 11:09 AM + * @return: java.lang.String */ public static String getToken(String key) { return (String) RequestHolder.getSession(key); } /** - * 添加Token + * @description: 将Token信息添加到session + * @param: key + * @date: 2019-08-15 11:09 AM + * @return: void */ public static void setToken(String key) { RequestHolder.setSession(key, UUID.randomUUID().toString()); } /** - * 删除Token信息 + * @description: 删除session中的Token信息 + * @param: key + * @date: 2019-08-15 11:10 AM + * @return: void */ public static void removeToken(String key) { RequestHolder.removeSession(key); } /** - * 删除所有的session信息 + * @description: 删除所有的session信息 + * @param: + * @date: 2019-08-15 11:11 AM + * @return: void */ public static void removeAllSession() { String[] keys = RequestHolder.getSessionKeys(); diff --git a/shiro-core/src/main/resources/mybatis/SysResourceMapper.xml b/shiro-core/src/main/resources/mybatis/SysResourceMapper.xml index af2afaa..1708a96 100644 --- a/shiro-core/src/main/resources/mybatis/SysResourceMapper.xml +++ b/shiro-core/src/main/resources/mybatis/SysResourceMapper.xml @@ -1,7 +1,10 @@ - + + @@ -14,6 +17,7 @@ + @@ -24,7 +28,9 @@ - + + @@ -36,163 +42,149 @@ + + + + + + SELECT re.id, + re.`name`, + re.parent_id, + re.url, + re.type, + re.icon, + ( + CASE + WHEN EXISTS( + SELECT 1 + FROM sys_role_resources rr + WHERE rr.resources_id = re.id + AND rr.role_id = #{rid} + ) + THEN + 'true' + ELSE + 'false' + END + ) AS checked + FROM sys_resources re + ORDER BY re.sort ASC + + + SELECT r.id, + r.`name`, + node.id AS node_id, + node.`name` AS node_name, + node.parent_id + FROM sys_resources r + LEFT JOIN sys_resources node ON ( + node.parent_id = r.id + AND node.available = 1 + AND node.type = 'menu' + ) + WHERE r.available = 1 + AND r.type = 'menu' + AND (r.url IS NULL OR r.url = '') + AND (r.permission IS NULL OR r.permission = '') + ORDER BY r.sort ASC, + node.sort ASC + + + ORDER BY re.sort ASC + + + SELECT re.id, + re.`name`, + re.parent_id, + re.url, + re.permission, + re.icon, + re.sort + FROM sys_resources re + INNER JOIN sys_role_resources rr ON re.id = rr.resources_id + INNER JOIN sys_user_role ur ON rr.role_id = ur.role_id + WHERE ur.user_id = #{userId} + AND re.available = 1 + ORDER BY re.parent_id ASC, + re.sort ASC + - diff --git a/shiro-core/src/main/resources/mybatis/SysRoleMapper.xml b/shiro-core/src/main/resources/mybatis/SysRoleMapper.xml index 52a5508..c7b0a6c 100644 --- a/shiro-core/src/main/resources/mybatis/SysRoleMapper.xml +++ b/shiro-core/src/main/resources/mybatis/SysRoleMapper.xml @@ -1,69 +1,65 @@ - + - - - - - - - - - + + + + + + + + - + + - - + + + + + diff --git a/shiro-core/src/main/resources/mybatis/SysUserMapper.xml b/shiro-core/src/main/resources/mybatis/SysUserMapper.xml index 7ba7326..7c410ca 100644 --- a/shiro-core/src/main/resources/mybatis/SysUserMapper.xml +++ b/shiro-core/src/main/resources/mybatis/SysUserMapper.xml @@ -1,88 +1,90 @@ - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + + - + + - diff --git a/shiro-core/src/main/resources/mybatis/SysUserRoleMapper.xml b/shiro-core/src/main/resources/mybatis/SysUserRoleMapper.xml index b77b764..2e13a97 100644 --- a/shiro-core/src/main/resources/mybatis/SysUserRoleMapper.xml +++ b/shiro-core/src/main/resources/mybatis/SysUserRoleMapper.xml @@ -1,6 +1,10 @@ + + @@ -8,13 +12,10 @@ - + - \ No newline at end of file +