-------------------------------------------------------------------------------- /shiro-admin/src/main/resources/templates/layout/setting.ftl: -------------------------------------------------------------------------------- 1 |
2 | 20 |
-------------------------------------------------------------------------------- /shiro-admin/src/main/resources/templates/layout/sidebar.ftl: -------------------------------------------------------------------------------- 1 | 2 | 31 | -------------------------------------------------------------------------------- /shiro-admin/src/main/resources/templates/login.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 登录 | Shiro权限管理系统 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 92 | 93 | -------------------------------------------------------------------------------- /shiro-admin/src/test/java/com/zyd/shiro/ShiroAdminApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.zyd.shiro; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShiroAdminApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shiro-core/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/consts/CommonConst.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.consts; 21 | 22 | /** 23 | * @project: springboot-shiro 24 | * @description: 程序中公用的常量类 25 | * @date: 2019-08-15 9:22 AM 26 | * @version: 1.0 27 | * @website: https://yubuntu0109.github.io/ 28 | */ 29 | public class CommonConst { 30 | // TODO: 8/15/2019 安全密码(由UUID生成),作为盐值用于用户密码的加密 31 | public static final String ZYD_SECURITY_KEY = "929123f8f17944e8b0a531045453e1f1"; 32 | 33 | // TODO: 8/15/2019 程序默认的错误状态码 34 | public static final int DEFAULT_ERROR_CODE = 500; 35 | 36 | // TODO: 8/15/2019 程序默认的成功状态码 37 | public static final int DEFAULT_SUCCESS_CODE = 200; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/consts/SessionConst.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.consts; 21 | 22 | /** 23 | * @project: springboot-shiro 24 | * @description: 程序中公用的Session常量类 25 | * @date: 2019-08-15 9:30 AM 26 | * @version: 1.0 27 | * @website: https://yubuntu0109.github.io/ 28 | */ 29 | public class SessionConst { 30 | 31 | // TODO: 8/15/2019 User 的 session-key 32 | public static final String USER_SESSION_KEY = "user"; 33 | } 34 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/entity/Resources.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.entity; 21 | 22 | import com.zyd.shiro.business.enums.ResourceTypeEnum; 23 | import com.zyd.shiro.persistence.beans.SysResources; 24 | 25 | import java.util.Date; 26 | import java.util.List; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: 资源信息 31 | * @date: 2019-08-15 9:36 AM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | public class Resources { 36 | private SysResources sysResources; 37 | 38 | public Resources() { 39 | this.sysResources = new SysResources(); 40 | } 41 | 42 | public Resources(SysResources sysResources) { 43 | this.sysResources = sysResources; 44 | } 45 | 46 | public SysResources getSysResources() { 47 | return this.sysResources; 48 | } 49 | 50 | public Long getId() { 51 | return this.sysResources.getId(); 52 | } 53 | 54 | public void setId(Long id) { 55 | this.sysResources.setId(id); 56 | } 57 | 58 | public String getName() { 59 | return this.sysResources.getName(); 60 | } 61 | 62 | public void setName(String name) { 63 | this.sysResources.setName(name); 64 | } 65 | 66 | public ResourceTypeEnum getType() { 67 | return this.sysResources.getType() != null ? ResourceTypeEnum.valueOf(this.sysResources.getType()) : null; 68 | } 69 | 70 | public void setType(ResourceTypeEnum type) { 71 | this.sysResources.setType(type.toString()); 72 | } 73 | 74 | public String getUrl() { 75 | return this.sysResources.getUrl(); 76 | } 77 | 78 | public void setUrl(String url) { 79 | this.sysResources.setUrl(url); 80 | } 81 | 82 | public String getPermission() { 83 | return this.sysResources.getPermission(); 84 | } 85 | 86 | public void setPermission(String permission) { 87 | this.sysResources.setPermission(permission); 88 | } 89 | 90 | public Long getParentId() { 91 | return this.sysResources.getParentId(); 92 | } 93 | 94 | public void setParentId(Long parentId) { 95 | this.sysResources.setParentId(parentId); 96 | } 97 | 98 | public Integer getSort() { 99 | return this.sysResources.getSort(); 100 | } 101 | 102 | public void setSort(Integer sort) { 103 | this.sysResources.setSort(sort); 104 | } 105 | 106 | public boolean isAvailable() { 107 | Boolean value = this.sysResources.getAvailable(); 108 | return value != null ? value : false; 109 | } 110 | 111 | public void setAvailable(boolean available) { 112 | this.sysResources.setAvailable(available); 113 | } 114 | 115 | public Boolean getExternal() { 116 | Boolean value = this.sysResources.getExternal(); 117 | return null == value ? false : value; 118 | } 119 | 120 | public void setExternal(Boolean external) { 121 | this.sysResources.setExternal(external); 122 | } 123 | 124 | public String getIcon() { 125 | return this.sysResources.getIcon(); 126 | } 127 | 128 | public void setIcon(String icon) { 129 | this.sysResources.setIcon(icon); 130 | } 131 | 132 | public Date getCreateTime() { 133 | return this.sysResources.getCreateTime(); 134 | } 135 | 136 | public void setCreateTime(Date regTime) { 137 | this.sysResources.setCreateTime(regTime); 138 | } 139 | 140 | public Date getUpdateTime() { 141 | return this.sysResources.getUpdateTime(); 142 | } 143 | 144 | public void setUpdateTime(Date updateTime) { 145 | this.sysResources.setUpdateTime(updateTime); 146 | } 147 | 148 | public SysResources getParent() { 149 | return this.sysResources.getParent(); 150 | } 151 | 152 | public void setParent(SysResources parent) { 153 | this.sysResources.setParent(parent); 154 | } 155 | 156 | public List getNodes() { 157 | return this.sysResources.getNodes(); 158 | } 159 | 160 | public void setNodes(List nodes) { 161 | this.sysResources.setNodes(nodes); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/entity/Role.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.entity; 21 | 22 | import com.zyd.shiro.persistence.beans.SysRole; 23 | 24 | import java.util.Date; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 角色信息 29 | * @date: 2019-08-15 9:36 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public class Role { 34 | private SysRole sysRole; 35 | 36 | public Role() { 37 | this.sysRole = new SysRole(); 38 | } 39 | 40 | public Role(SysRole sysRole) { 41 | this.sysRole = sysRole; 42 | } 43 | 44 | public SysRole getSysRole() { 45 | return this.sysRole; 46 | } 47 | 48 | public Long getId() { 49 | return this.sysRole.getId(); 50 | } 51 | 52 | public void setId(Long id) { 53 | this.sysRole.setId(id); 54 | } 55 | 56 | public String getName() { 57 | return this.sysRole.getName(); 58 | } 59 | 60 | public void setName(String name) { 61 | this.sysRole.setName(name); 62 | } 63 | 64 | 65 | public String getDescription() { 66 | return this.sysRole.getDescription(); 67 | } 68 | 69 | public void setDescription(String description) { 70 | this.sysRole.setDescription(description); 71 | } 72 | 73 | public boolean isAvailable() { 74 | Boolean value = this.sysRole.getAvailable(); 75 | return value != null ? value : false; 76 | } 77 | 78 | public void setAvailable(boolean available) { 79 | this.sysRole.setAvailable(available); 80 | } 81 | 82 | public Date getCreateTime() { 83 | return this.sysRole.getCreateTime(); 84 | } 85 | 86 | public void setCreateTime(Date regTime) { 87 | this.sysRole.setCreateTime(regTime); 88 | } 89 | 90 | public Date getUpdateTime() { 91 | return this.sysRole.getUpdateTime(); 92 | } 93 | 94 | public void setUpdateTime(Date updateTime) { 95 | this.sysRole.setUpdateTime(updateTime); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/entity/RoleResources.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.entity; 21 | 22 | import com.zyd.shiro.persistence.beans.SysRoleResources; 23 | 24 | import java.util.Date; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 连接角色与资源信息的桥梁 29 | * @date: 2019-08-15 9:41 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public class RoleResources { 34 | 35 | private SysRoleResources sysRoleResources; 36 | 37 | public RoleResources() { 38 | this.sysRoleResources = new SysRoleResources(); 39 | } 40 | 41 | public RoleResources(SysRoleResources sysRoleResources) { 42 | this.sysRoleResources = sysRoleResources; 43 | } 44 | 45 | public SysRoleResources getSysRoleResources() { 46 | return this.sysRoleResources; 47 | } 48 | 49 | public Long getRoleId() { 50 | return this.sysRoleResources.getRoleId(); 51 | } 52 | 53 | public void setRoleId(Long roleId) { 54 | this.sysRoleResources.setRoleId(roleId); 55 | } 56 | 57 | public Long getResourcesId() { 58 | return this.sysRoleResources.getResourcesId(); 59 | } 60 | 61 | public void setResourcesId(Long resourcesId) { 62 | this.sysRoleResources.setResourcesId(resourcesId); 63 | } 64 | 65 | public Date getCreateTime() { 66 | return this.sysRoleResources.getCreateTime(); 67 | } 68 | 69 | public void setCreateTime(Date regTime) { 70 | this.sysRoleResources.setCreateTime(regTime); 71 | } 72 | 73 | public Date getUpdateTime() { 74 | return this.sysRoleResources.getUpdateTime(); 75 | } 76 | 77 | public void setUpdateTime(Date updateTime) { 78 | this.sysRoleResources.setUpdateTime(updateTime); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/entity/UserRole.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.entity; 21 | 22 | import com.zyd.shiro.persistence.beans.SysUserRole; 23 | 24 | import java.util.Date; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 连接用户与角色信息的桥梁 29 | * @date: 2019-08-15 9:40 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public class UserRole { 34 | 35 | private SysUserRole sysUserRole; 36 | 37 | public UserRole() { 38 | this.sysUserRole = new SysUserRole(); 39 | } 40 | 41 | public UserRole(SysUserRole sysUserRole) { 42 | this.sysUserRole = sysUserRole; 43 | } 44 | 45 | public SysUserRole getSysUserRole() { 46 | return this.sysUserRole; 47 | } 48 | 49 | public Long getUserId() { 50 | return this.sysUserRole.getUserId(); 51 | } 52 | 53 | public void setUserId(Long userId) { 54 | this.sysUserRole.setUserId(userId); 55 | } 56 | 57 | public Long getRoleId() { 58 | return this.sysUserRole.getRoleId(); 59 | } 60 | 61 | public void setRoleId(Long roleId) { 62 | this.sysUserRole.setRoleId(roleId); 63 | } 64 | 65 | public Date getCreateTime() { 66 | return this.sysUserRole.getCreateTime(); 67 | } 68 | 69 | public void setCreateTime(Date regTime) { 70 | this.sysUserRole.setCreateTime(regTime); 71 | } 72 | 73 | public Date getUpdateTime() { 74 | return this.sysUserRole.getUpdateTime(); 75 | } 76 | 77 | public void setUpdateTime(Date updateTime) { 78 | this.sysUserRole.setUpdateTime(updateTime); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/enums/ResourceTypeEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.business.enums; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 资源类型 29 | * @date: 2019-08-15 10:14 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public enum ResourceTypeEnum { 34 | menu("菜单"), 35 | button("按钮"); 36 | 37 | private final String info; 38 | 39 | private ResourceTypeEnum(String info) { 40 | this.info = info; 41 | } 42 | 43 | public String getInfo() { 44 | return info; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/enums/ResponseStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.business.enums; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 错误操作的提示信息 29 | * @date: 2019-08-15 10:08 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public enum ResponseStatus { 34 | 35 | SUCCESS(200, "操作成功!"), 36 | ERROR(500, "服务器未知错误!"), 37 | UNAUTHORIZED(500, "尚未登录!"), 38 | FORBIDDEN(500, "您没有操作权限!"), 39 | NOT_FOUND(500, "资源不存在!"), 40 | LOGIN_ERROR(500, "账号或密码错误!"), 41 | USER_EXIST(500, "已存在的用户!"), 42 | INVALID_AUTHCODE(500, "手机验证码无效!"), 43 | INVALID_TOKEN(500, "无效的TOKEN,您没有操作权限!"), 44 | INVALID_ACCESS(500, "无效的请求,该请求已过期!"), 45 | DELETE_ERROR(500, "删除失败!"); 46 | 47 | private Integer code; 48 | private String message; 49 | 50 | ResponseStatus(Integer code, String message) { 51 | this.code = code; 52 | this.message = message; 53 | } 54 | 55 | /** 56 | * @description: 获取错误操作的响应状态 57 | * @param: message 58 | * @date: 2019-08-15 10:11 AM 59 | * @return: com.zyd.shiro.business.enums.ResponseStatus 60 | */ 61 | public static ResponseStatus getResponseStatus(String message) { 62 | for (ResponseStatus ut : ResponseStatus.values()) { 63 | if (ut.getMessage() == message) { 64 | return ut; 65 | } 66 | } 67 | return null; 68 | } 69 | 70 | public Integer getCode() { 71 | return code; 72 | } 73 | 74 | public String getMessage() { 75 | return message; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/enums/UserGenderEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.business.enums; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 用户性别信息 29 | * @date: 2019-08-15 10:05 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public enum UserGenderEnum { 34 | MALE(1, "男"), FEMALE(0, "女"), UNKNOW(-1, ""); 35 | private int code; 36 | private String desc; 37 | 38 | UserGenderEnum(int code, String desc) { 39 | this.code = code; 40 | this.desc = desc; 41 | } 42 | 43 | /** 44 | * @description: (never used)通过code码获取用户的性别信息 45 | * @param: code 46 | * @date: 2019-08-15 10:05 AM 47 | * @return: com.zyd.shiro.business.enums.UserGenderEnum 48 | */ 49 | public static UserGenderEnum getUserSex(Integer code) { 50 | if (code == null) { 51 | return UNKNOW; 52 | } 53 | for (UserGenderEnum userSexEnum : UserGenderEnum.values()) { 54 | if (userSexEnum.getCode() == code) { 55 | return userSexEnum; 56 | } 57 | } 58 | return UNKNOW; 59 | } 60 | 61 | /** 62 | * @description: (never used)通过字符code获取用户性别信息 63 | * @param: code 64 | * @date: 2019-08-15 10:06 AM 65 | * @return: com.zyd.shiro.business.enums.UserGenderEnum 66 | */ 67 | public static UserGenderEnum getUserSex(String code) { 68 | if (code == null) { 69 | return UNKNOW; 70 | } 71 | if ("m".equals(code)) { 72 | return MALE; 73 | } 74 | if ("f".equals(code)) { 75 | return FEMALE; 76 | } 77 | return UNKNOW; 78 | } 79 | 80 | public int getCode() { 81 | return code; 82 | } 83 | 84 | //the method is never used 85 | public String getDesc() { 86 | return desc; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/enums/UserStatusEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.business.enums; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 用户状态信息 29 | * @date: 2019-08-15 9:56 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public enum UserStatusEnum { 34 | NORMAL(1, "正常"), 35 | DISABLE(0, "禁用"),; 36 | private Integer code; 37 | private String desc; 38 | 39 | UserStatusEnum(Integer code, String desc) { 40 | this.code = code; 41 | this.desc = desc; 42 | } 43 | 44 | /** 45 | * @description: 获取用户的状态(是否可使用) 46 | * @param: code 47 | * @date: 2019-08-15 10:00 AM 48 | * @return: com.zyd.shiro.business.enums.UserStatusEnum 49 | */ 50 | public static UserStatusEnum get(Integer code) { 51 | if (null == code) { 52 | return NORMAL; 53 | } 54 | UserStatusEnum[] enums = UserStatusEnum.values(); 55 | for (UserStatusEnum anEnum : enums) { 56 | if (anEnum.getCode().equals(code)) { 57 | return anEnum; 58 | } 59 | } 60 | return NORMAL; 61 | } 62 | 63 | public Integer getCode() { 64 | return code; 65 | } 66 | 67 | //the method is never used 68 | public String getDesc() { 69 | return desc; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/enums/UserTypeEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.business.enums; 25 | 26 | import org.springframework.util.StringUtils; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: 用户的身份类型信息 31 | * @date: 2019-08-15 9:51 AM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | public enum UserTypeEnum { 36 | ROOT("超级管理员"), 37 | ADMIN("管理员"), 38 | USER("系统会员"), 39 | UNKNOW("未知"); 40 | private String desc; 41 | 42 | UserTypeEnum(String desc) { 43 | this.desc = desc; 44 | } 45 | 46 | /** 47 | * @description: 获取用户的身份类型 48 | * @param: type 49 | * @date: 2019-08-15 9:55 AM 50 | * @return: com.zyd.shiro.business.enums.UserTypeEnum 51 | */ 52 | public static UserTypeEnum getByType(String type) { 53 | if (StringUtils.isEmpty(type)) { 54 | return UserTypeEnum.UNKNOW; 55 | } 56 | for (UserTypeEnum ut : UserTypeEnum.values()) { 57 | if (ut.toString().equalsIgnoreCase(type)) { 58 | return ut; 59 | } 60 | } 61 | return UserTypeEnum.UNKNOW; 62 | } 63 | 64 | //the method is never used 65 | public String getDesc() { 66 | return desc; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/service/ShiroService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.service; 21 | 22 | import com.zyd.shiro.business.entity.User; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: Shiro-权限相关的业务处理 29 | * @date: 2019-08-14 3:57 PM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public interface ShiroService { 34 | 35 | /** 36 | * @description: 初始化权限 37 | * @param: 38 | * @date: 2019-08-14 3:53 PM 39 | * @return: java.util.Map 40 | */ 41 | Map loadFilterChainDefinitions(); 42 | 43 | /** 44 | * @description: 重新加载权限 45 | * @param: 46 | * @date: 2019-08-14 3:53 PM 47 | * @return: void 48 | */ 49 | void updatePermission(); 50 | 51 | /** 52 | * @description: 重新加载用户权限 53 | * @param: user 54 | * @date: 2019-08-14 3:54 PM 55 | * @return: void 56 | */ 57 | void reloadAuthorizingByUserId(User user); 58 | 59 | /** 60 | * @description: 重新加载所有拥有roleId角色的用户的权限 61 | * @param: roleId 62 | * @date: 2019-08-14 3:54 PM 63 | * @return: void 64 | */ 65 | void reloadAuthorizingByRoleId(Long roleId); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/service/SysResourcesService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.service; 21 | 22 | import com.github.pagehelper.PageInfo; 23 | import com.zyd.shiro.business.entity.Resources; 24 | import com.zyd.shiro.business.vo.ResourceConditionVO; 25 | import com.zyd.shiro.framework.object.AbstractService; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * @project: springboot-shiro 32 | * @description: 系统资源相关的业务处理 33 | * @date: 2019-08-14 4:05 PM 34 | * @version: 1.0 35 | * @website: https://yubuntu0109.github.io/ 36 | */ 37 | public interface SysResourcesService extends AbstractService { 38 | 39 | /** 40 | * @description: 分页查询资源列表 41 | * @param: vo 42 | * @date: 2019-08-14 4:05 PM 43 | * @return: com.github.pagehelper.PageInfo 44 | */ 45 | PageInfo findPageBreakByCondition(ResourceConditionVO vo); 46 | 47 | /** 48 | * @description: 获取用户所拥有的资源列表 49 | * @param: map 50 | * @date: 2019-08-14 4:06 PM 51 | * @return: java.util.List 52 | */ 53 | List listUserResources(Map map); 54 | 55 | /** 56 | * @description: 通过角色id获取ztree使用的资源列表 57 | * @param: rid 58 | * @date: 2019-08-14 4:06 PM 59 | * @return: java.util.List> 60 | */ 61 | List> queryResourcesListWithSelected(Long rid); 62 | 63 | /** 64 | * @description: 获取资源的url和Permission 65 | * @param: 66 | * @date: 2019-08-14 4:07 PM 67 | * @return: java.util.List 68 | */ 69 | List listUrlAndPermission(); 70 | 71 | /** 72 | * @description: 获取所有可用的菜单资源 73 | * @param: 74 | * @date: 2019-08-14 4:07 PM 75 | * @return: java.util.List 76 | */ 77 | List listAllAvailableMenu(); 78 | 79 | /** 80 | * @description: (never used)获取父级资源下所有menu资源 81 | * @param: pid 82 | * @date: 2019-08-14 4:08 PM 83 | * @return: java.util.List> 84 | */ 85 | List> listChildMenuByPid(Long pid); 86 | 87 | /** 88 | * @description: 通过用户id获取用户关联的所有资源 89 | * @param: userId 90 | * @date: 2019-08-14 4:08 PM 91 | * @return: java.util.List 92 | */ 93 | List listByUserId(Long userId); 94 | } 95 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleResourcesService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.service; 21 | 22 | 23 | import com.zyd.shiro.business.entity.RoleResources; 24 | import com.zyd.shiro.framework.object.AbstractService; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 角色资源相关的业务处理 29 | * @date: 2019-08-14 4:01 PM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public interface SysRoleResourcesService extends AbstractService { 34 | 35 | /** 36 | * @description: 添加角色资源 37 | * @param: roleId 38 | * @param: resourcesIds 39 | * @date: 2019-08-14 4:13 PM 40 | * @return: void 41 | */ 42 | void addRoleResources(Long roleId, String resourcesIds); 43 | 44 | /** 45 | * @description: 通过角色id批量删除 46 | * @param: roleId 47 | * @date: 2019-08-14 4:13 PM 48 | * @return: void 49 | */ 50 | void removeByRoleId(Long roleId); 51 | } 52 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/service/SysRoleService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.service; 21 | 22 | 23 | import com.github.pagehelper.PageInfo; 24 | import com.zyd.shiro.business.entity.Role; 25 | import com.zyd.shiro.business.vo.RoleConditionVO; 26 | import com.zyd.shiro.framework.object.AbstractService; 27 | 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | /** 32 | * @project: springboot-shiro 33 | * @description: 角色相关的业务处理 34 | * @date: 2019-08-14 4:01 PM 35 | * @version: 1.0 36 | * @website: https://yubuntu0109.github.io/ 37 | */ 38 | public interface SysRoleService extends AbstractService { 39 | 40 | /** 41 | * @description: 通过用户id获取ztree使用的角色列表 42 | * @param: uid 43 | * @date: 2019-08-14 4:02 PM 44 | * @return: java.util.List> 45 | */ 46 | List> queryRoleListWithSelected(Integer uid); 47 | 48 | /** 49 | * @description: 分页查询角色列表 50 | * @param: vo 51 | * @date: 2019-08-14 4:02 PM 52 | * @return: com.github.pagehelper.PageInfo 53 | */ 54 | PageInfo findPageBreakByCondition(RoleConditionVO vo); 55 | 56 | /** 57 | * @description: 通过用户id获取用户所拥有的角色信息 58 | * @param: userId 59 | * @date: 2019-08-14 4:03 PM 60 | * @return: java.util.List 61 | */ 62 | List listRolesByUserId(Long userId); 63 | } 64 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserRoleService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.service; 21 | 22 | 23 | import com.zyd.shiro.business.entity.UserRole; 24 | import com.zyd.shiro.framework.object.AbstractService; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 用户角色相关的业务处理 29 | * @date: 2019-08-14 4:10 PM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public interface SysUserRoleService extends AbstractService { 34 | 35 | /** 36 | * @description: 添加用户角色 37 | * @param: userId 38 | * @param: roleIds 39 | * @date: 2019-08-14 4:10 PM 40 | * @return: void 41 | */ 42 | void addUserRole(Long userId, String roleIds); 43 | 44 | /** 45 | * @description: 根据用户id删除用户角色 46 | * @param: userId 47 | * @date: 2019-08-14 4:10 PM 48 | * @return: void 49 | */ 50 | void removeByUserId(Long userId); 51 | } 52 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.service; 21 | 22 | 23 | import com.github.pagehelper.PageInfo; 24 | import com.zyd.shiro.business.entity.User; 25 | import com.zyd.shiro.business.vo.UserConditionVO; 26 | import com.zyd.shiro.framework.object.AbstractService; 27 | 28 | import java.util.List; 29 | 30 | /** 31 | * @project: springboot-shiro 32 | * @description: 用户相关的业务处理 33 | * @date: 2019-08-14 3:57 PM 34 | * @version: 1.0 35 | * @website: https://yubuntu0109.github.io/ 36 | */ 37 | public interface SysUserService extends AbstractService { 38 | 39 | /** 40 | * @description: 分页查询用户信息 41 | * @param: vo 42 | * @date: 2019-08-14 3:58 PM 43 | * @return: com.github.pagehelper.PageInfo 44 | */ 45 | PageInfo findPageBreakByCondition(UserConditionVO vo); 46 | 47 | /** 48 | * @description: (never used)更新用户最后一次登录的状态信息 49 | * @param: user 50 | * @date: 2019-08-14 3:59 PM 51 | * @return: com.zyd.shiro.business.entity.User 52 | */ 53 | User updateUserLastLoginInfo(User user); 54 | 55 | /** 56 | * @description: 根据用户名查找指定的用户信息 57 | * @param: userName 58 | * @date: 2019-08-14 4:00 PM 59 | * @return: com.zyd.shiro.business.entity.User 60 | */ 61 | User getByUserName(String userName); 62 | 63 | /** 64 | * @description: 通过角色id获取用户列表 65 | * @param: roleId 66 | * @date: 2019-08-14 4:00 PM 67 | * @return: java.util.List 68 | */ 69 | List listByRoleId(Long roleId); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/shiro/credentials/CredentialsMatcher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.shiro.credentials; 21 | 22 | import com.zyd.shiro.util.PasswordUtil; 23 | import org.apache.shiro.authc.AuthenticationInfo; 24 | import org.apache.shiro.authc.AuthenticationToken; 25 | import org.apache.shiro.authc.UsernamePasswordToken; 26 | import org.apache.shiro.authc.credential.SimpleCredentialsMatcher; 27 | 28 | /** 29 | * Shiro-密码凭证匹配器(验证密码有效性) 30 | * 31 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 32 | * @version 1.0 33 | * @website https://www.zhyd.me 34 | * @date 2018/4/24 14:37 35 | * @since 1.0 36 | */ 37 | public class CredentialsMatcher extends SimpleCredentialsMatcher { 38 | 39 | /** 40 | * @description: 用户密码加密 41 | * @param: token 用户登录信息 42 | * @param: info 用户认证信息 43 | * @date: 2019-08-13 1:12 PM 44 | * @return: boolean 45 | */ 46 | @Override 47 | public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { 48 | UsernamePasswordToken utoken = (UsernamePasswordToken) token; 49 | //获得用户输入的密码:(可以采用加盐(salt)的方式去检验) 50 | String inPassword = new String(utoken.getPassword()); 51 | //根据用户的认证信息获得数据库中的密码 52 | String dbPassword = (String) info.getCredentials(); 53 | try { 54 | //解密数据库中的用户密码 55 | dbPassword = PasswordUtil.decrypt(dbPassword, utoken.getUsername()); 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | return false; 59 | } 60 | //进行密码的比对 61 | return this.equals(inPassword, dbPassword); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/shiro/credentials/RetryLimitCredentialsMatcher.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.shiro.credentials; 21 | 22 | import com.zyd.shiro.business.consts.SessionConst; 23 | import com.zyd.shiro.business.entity.User; 24 | import com.zyd.shiro.business.service.SysUserService; 25 | import lombok.extern.slf4j.Slf4j; 26 | import org.apache.shiro.SecurityUtils; 27 | import org.apache.shiro.authc.AccountException; 28 | import org.apache.shiro.authc.AuthenticationInfo; 29 | import org.apache.shiro.authc.AuthenticationToken; 30 | import org.apache.shiro.authc.ExcessiveAttemptsException; 31 | import org.springframework.beans.factory.annotation.Autowired; 32 | import org.springframework.data.redis.core.RedisTemplate; 33 | import org.springframework.data.redis.core.ValueOperations; 34 | 35 | import java.util.concurrent.TimeUnit; 36 | 37 | /** 38 | * Shiro-密码输入错误的状态下重试次数的匹配管理 39 | * 40 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 41 | * @version 1.0 42 | * @website https://www.zhyd.me 43 | * @date 2018/4/24 14:37 44 | * @since 1.0 45 | */ 46 | @Slf4j 47 | public class RetryLimitCredentialsMatcher extends CredentialsMatcher { 48 | 49 | /** 50 | * 用户登录次数计数 redisKey 前缀 51 | */ 52 | private static final String SHIRO_LOGIN_COUNT = "shiro_login_count_"; 53 | /** 54 | * 用户登录是否被锁定 一小时 redisKey 前缀 55 | */ 56 | private static final String SHIRO_IS_LOCK = "shiro_is_lock_"; 57 | @Autowired 58 | private RedisTemplate redisTemplate; 59 | @Autowired 60 | private SysUserService userService; 61 | 62 | @Override 63 | public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { 64 | Long userId = (Long) info.getPrincipals().getPrimaryPrincipal(); 65 | User user = userService.getByPrimaryKey(userId); 66 | String username = user.getUsername(); 67 | // 访问一次,计数一次 68 | ValueOperations opsForValue = redisTemplate.opsForValue(); 69 | String loginCountKey = SHIRO_LOGIN_COUNT + username; 70 | String isLockKey = SHIRO_IS_LOCK + username; 71 | opsForValue.increment(loginCountKey, 1); 72 | 73 | if (redisTemplate.hasKey(isLockKey)) { 74 | throw new ExcessiveAttemptsException("帐号[" + username + "]已被禁止登录!"); 75 | } 76 | 77 | // 计数大于5时,设置用户被锁定一小时 78 | String loginCount = String.valueOf(opsForValue.get(loginCountKey)); 79 | int retryCount = (5 - Integer.parseInt(loginCount)); 80 | if (retryCount <= 0) { 81 | opsForValue.set(isLockKey, "LOCK"); 82 | redisTemplate.expire(isLockKey, 1, TimeUnit.HOURS); 83 | redisTemplate.expire(loginCountKey, 1, TimeUnit.HOURS); 84 | throw new ExcessiveAttemptsException("由于密码输入错误次数过多,帐号[" + username + "]已被禁止登录!"); 85 | } 86 | 87 | boolean matches = super.doCredentialsMatch(token, info); 88 | if (!matches) { 89 | String msg = retryCount <= 0 ? "您的账号一小时内禁止登录!" : "您还剩" + retryCount + "次重试的机会"; 90 | throw new AccountException("帐号或密码不正确!" + msg); 91 | } 92 | 93 | //清空登录计数 94 | redisTemplate.delete(loginCountKey); 95 | try { 96 | userService.updateUserLastLoginInfo(user); 97 | } catch (Exception e) { 98 | e.printStackTrace(); 99 | } 100 | // 当验证都通过后,把用户信息放在session里 101 | // 注:User必须实现序列化 102 | SecurityUtils.getSubject().getSession().setAttribute(SessionConst.USER_SESSION_KEY, user); 103 | return true; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/vo/ResourceConditionVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.vo; 21 | 22 | import com.zyd.shiro.framework.object.BaseConditionVO; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 资源信息 29 | * @date: 2019-08-15 10:26 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | @Data 34 | @EqualsAndHashCode(callSuper = false) 35 | public class ResourceConditionVO extends BaseConditionVO { 36 | private String type; 37 | } 38 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/vo/RoleConditionVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.vo; 21 | 22 | import com.zyd.shiro.business.entity.Role; 23 | import com.zyd.shiro.framework.object.BaseConditionVO; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | 27 | /** 28 | * @project: springboot-shiro 29 | * @description: 角色信息 30 | * @date: 2019-08-15 10:26 AM 31 | * @version: 1.0 32 | * @website: https://yubuntu0109.github.io/ 33 | */ 34 | @Data 35 | @EqualsAndHashCode(callSuper = false) 36 | public class RoleConditionVO extends BaseConditionVO { 37 | private Role role; 38 | } 39 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/business/vo/UserConditionVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.business.vo; 21 | 22 | import com.zyd.shiro.business.entity.User; 23 | import com.zyd.shiro.framework.object.BaseConditionVO; 24 | import lombok.Data; 25 | import lombok.EqualsAndHashCode; 26 | 27 | /** 28 | * @project: springboot-shiro 29 | * @description: 用户信息 30 | * @date: 2019-08-15 10:20 AM 31 | * @version: 1.0 32 | * @website: https://yubuntu0109.github.io/ 33 | */ 34 | @Data 35 | @EqualsAndHashCode(callSuper = false) 36 | public class UserConditionVO extends BaseConditionVO { 37 | private User user; 38 | } 39 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/config/DruidConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.config; 25 | 26 | import com.alibaba.druid.support.http.StatViewServlet; 27 | import com.alibaba.druid.support.http.WebStatFilter; 28 | import com.zyd.shiro.framework.property.DruidProperties; 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 31 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 32 | import org.springframework.context.annotation.Bean; 33 | import org.springframework.context.annotation.Configuration; 34 | import org.springframework.util.CollectionUtils; 35 | import org.springframework.util.StringUtils; 36 | 37 | import java.util.List; 38 | 39 | /** 40 | * @project: springboot-shiro 41 | * @description: Druid Monitor的配置信息 42 | * @date: 2019-08-15 11:38 AM 43 | * @version: 1.0 44 | * @website: https://yubuntu0109.github.io/ 45 | */ 46 | @Configuration 47 | public class DruidConfig { 48 | 49 | @Autowired 50 | private DruidProperties druidProperties; 51 | 52 | @Bean 53 | public ServletRegistrationBean druidStatViewServlet() { 54 | ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), druidProperties.getServletPath()); 55 | 56 | // IP黑名单(存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry,you are not permitted to view this page. 57 | List denyIps = druidProperties.getDenyIps(); 58 | if (!CollectionUtils.isEmpty(denyIps)) { 59 | bean.addInitParameter("deny", StringUtils.collectionToDelimitedString(denyIps, ",")); 60 | } 61 | // IP白名单 62 | List allowIps = druidProperties.getAllowIps(); 63 | if (!CollectionUtils.isEmpty(allowIps)) { 64 | bean.addInitParameter("allow", StringUtils.collectionToDelimitedString(allowIps, ",")); 65 | } 66 | // 登录查看信息的账号密码 67 | bean.addInitParameter("loginUsername", druidProperties.getUsername()); 68 | bean.addInitParameter("loginPassword", druidProperties.getPassword()); 69 | // 禁用HTML页面上的"Reset All"功能(默认false) 70 | bean.addInitParameter("resetEnable", String.valueOf(druidProperties.getResetEnable())); 71 | return bean; 72 | } 73 | 74 | /** 75 | * @description: 配置Druid的StatFilter 76 | * @param: 77 | * @date: 2019-08-15 11:39 AM 78 | * @return: org.springframework.boot.web.servlet.FilterRegistrationBean 79 | */ 80 | @Bean 81 | public FilterRegistrationBean druidStatFilter() { 82 | FilterRegistrationBean bean = new FilterRegistrationBean(new WebStatFilter()); 83 | // 添加过滤规则 84 | bean.addUrlPatterns("/*"); 85 | // 排除的url 86 | bean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); 87 | return bean; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/config/ErrorPagesConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.config; 25 | 26 | import org.springframework.boot.web.server.ErrorPage; 27 | import org.springframework.boot.web.server.WebServerFactoryCustomizer; 28 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; 29 | import org.springframework.context.annotation.Bean; 30 | import org.springframework.http.HttpStatus; 31 | import org.springframework.stereotype.Component; 32 | 33 | /** 34 | * @project: springboot-shiro 35 | * @description: 自定义异常页的配置类 36 | * @date: 2019-08-15 11:40 AM 37 | * @version: 1.0 38 | * @website: https://yubuntu0109.github.io/ 39 | */ 40 | @Component 41 | public class ErrorPagesConfig { 42 | 43 | /** 44 | * @description: 自定义异常处理路径 45 | * @param: 46 | * @date: 2019-08-15 11:40 AM 47 | * @return: org.springframework.boot.web.server.WebServerFactoryCustomizer 48 | */ 49 | @Bean 50 | public WebServerFactoryCustomizer containerCustomizer() { 51 | return factory -> { 52 | factory.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400")); 53 | factory.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401")); 54 | factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403")); 55 | factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404")); 56 | factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500")); 57 | factory.addErrorPages(new ErrorPage(Throwable.class, "/error/500")); 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/config/FreeMarkerConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.framework.config; 21 | 22 | import com.jagregory.shiro.freemarker.ShiroTags; 23 | import com.zyd.shiro.framework.tag.CustomTagDirective; 24 | import freemarker.template.TemplateModelException; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.context.annotation.Configuration; 27 | 28 | import javax.annotation.PostConstruct; 29 | 30 | /** 31 | * @project: springboot-shiro 32 | * @description: FreeMarker配置类 33 | * @date: 2019-08-15 11:42 AM 34 | * @version: 1.0 35 | * @website: https://yubuntu0109.github.io/ 36 | */ 37 | @Configuration 38 | public class FreeMarkerConfig { 39 | 40 | @Autowired 41 | protected freemarker.template.Configuration configuration; 42 | @Autowired 43 | protected CustomTagDirective customTagDirective; 44 | 45 | /** 46 | * @description: 添加自定义标签 47 | * @param: 48 | * @date: 2019-08-15 11:42 AM 49 | * @return: void 50 | */ 51 | @PostConstruct 52 | public void setSharedVariable() { 53 | configuration.setSharedVariable("zhydTag", customTagDirective); 54 | //shiro标签 55 | configuration.setSharedVariable("shiro", new ShiroTags()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/config/MybatisConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.config; 25 | 26 | import tk.mybatis.spring.annotation.MapperScan; 27 | import org.springframework.stereotype.Component; 28 | 29 | /** 30 | * @project: springboot-shiro 31 | * @description: MyBatis配置类 32 | * @date: 2019-08-15 11:42 AM 33 | * @version: 1.0 34 | * @website: https://yubuntu0109.github.io/ 35 | */ 36 | @Component 37 | @MapperScan("com.zyd.shiro.persistence.mapper") 38 | public class MybatisConfig { 39 | } 40 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.config; 25 | 26 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 27 | import com.fasterxml.jackson.annotation.PropertyAccessor; 28 | import com.fasterxml.jackson.databind.ObjectMapper; 29 | import org.springframework.cache.CacheManager; 30 | import org.springframework.cache.annotation.CachingConfigurerSupport; 31 | import org.springframework.cache.annotation.EnableCaching; 32 | import org.springframework.cache.interceptor.KeyGenerator; 33 | import org.springframework.context.annotation.Bean; 34 | import org.springframework.context.annotation.Configuration; 35 | import org.springframework.data.redis.cache.RedisCacheConfiguration; 36 | import org.springframework.data.redis.cache.RedisCacheManager; 37 | import org.springframework.data.redis.cache.RedisCacheWriter; 38 | import org.springframework.data.redis.connection.RedisConnectionFactory; 39 | import org.springframework.data.redis.core.RedisTemplate; 40 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; 41 | 42 | import java.time.Duration; 43 | 44 | 45 | /** 46 | * @project: springboot-shiro 47 | * @description: Redis配置类 48 | * @date: 2019-08-15 11:42 AM 49 | * @version: 1.0 50 | * @website: https://yubuntu0109.github.io/ 51 | */ 52 | @Configuration 53 | @EnableCaching 54 | public class RedisConfig extends CachingConfigurerSupport { 55 | 56 | /** 57 | * @description: 缓存数据时Key的生成器, 可依据业务和技术场景自行定制 58 | * @param: 59 | * @date: 2019-08-15 11:44 AM 60 | * @return: org.springframework.cache.interceptor.KeyGenerator 61 | */ 62 | @Bean 63 | @Override 64 | @Deprecated 65 | public KeyGenerator keyGenerator() { 66 | return (target, method, params) -> { 67 | StringBuilder sb = new StringBuilder(); 68 | //类名+方法名 69 | sb.append(target.getClass().getName()); 70 | sb.append(".").append(method.getName()); 71 | for (Object obj : params) { 72 | sb.append(obj); 73 | } 74 | return sb.toString(); 75 | }; 76 | } 77 | 78 | @Bean 79 | public CacheManager cacheManager(RedisConnectionFactory factory) { 80 | return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(factory)) 81 | // 默认缓存过期时间:30天 82 | .cacheDefaults(RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofDays(30))) 83 | .transactionAware() 84 | .build(); 85 | } 86 | 87 | @Bean 88 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) { 89 | RedisTemplate template = new RedisTemplate<>(); 90 | template.setConnectionFactory(factory); 91 | ObjectMapper om = new ObjectMapper(); 92 | om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 93 | om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 94 | GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(om); 95 | template.setValueSerializer(jackson2JsonRedisSerializer); 96 | template.setKeySerializer(jackson2JsonRedisSerializer); 97 | template.afterPropertiesSet(); 98 | return template; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.framework.config; 21 | 22 | import com.zyd.shiro.framework.interceptor.RememberAuthenticationInterceptor; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.context.annotation.Configuration; 25 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 26 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: WebMVC配置类 31 | * @date: 2019-08-15 1:29 AM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | @Configuration 36 | public class WebMvcConfig implements WebMvcConfigurer { 37 | 38 | @Autowired 39 | private RememberAuthenticationInterceptor rememberAuthenticationInterceptor; 40 | 41 | @Override 42 | public void addInterceptors(InterceptorRegistry registry) { 43 | registry.addInterceptor(rememberAuthenticationInterceptor) 44 | .excludePathPatterns("/passport/**", "/error/**", "/assets/**", "favicon.ico") 45 | .addPathPatterns("/**"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/exception/ZhydException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright [2016-2017] [yadong.zhang] 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.zyd.shiro.framework.exception; 14 | 15 | /** 16 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 17 | * @version 1.0 18 | * @website https://www.zhyd.me 19 | * @date 2018/4/16 16:26 20 | * @since 1.0 21 | */ 22 | public class ZhydException extends RuntimeException { 23 | /** 24 | * Constructs a new runtime exception with {@code null} as its 25 | * detail message. The cause is not initialized, and may subsequently be 26 | * initialized by a call to {@link #initCause}. 27 | */ 28 | public ZhydException() { 29 | super(); 30 | } 31 | 32 | /** 33 | * Constructs a new runtime exception with the specified detail message. 34 | * The cause is not initialized, and may subsequently be initialized by a 35 | * call to {@link #initCause}. 36 | * 37 | * @param message 38 | * the detail message. The detail message is saved for 39 | * later retrieval by the {@link #getMessage()} method. 40 | */ 41 | public ZhydException(String message) { 42 | super(message); 43 | } 44 | 45 | /** 46 | * Constructs a new runtime exception with the specified detail message and 47 | * cause.

Note that the detail message associated with 48 | * {@code cause} is not automatically incorporated in 49 | * this runtime exception's detail message. 50 | * 51 | * @param message 52 | * the detail message (which is saved for later retrieval 53 | * by the {@link #getMessage()} method). 54 | * @param cause 55 | * the cause (which is saved for later retrieval by the 56 | * {@link #getCause()} method). (A null value is 57 | * permitted, and indicates that the cause is nonexistent or 58 | * unknown.) 59 | * @since 1.4 60 | */ 61 | public ZhydException(String message, Throwable cause) { 62 | super(message, cause); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/holder/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.holder; 25 | 26 | import org.springframework.beans.BeansException; 27 | import org.springframework.context.ApplicationContext; 28 | import org.springframework.context.ApplicationContextAware; 29 | import org.springframework.stereotype.Component; 30 | 31 | /** 32 | * @project: springboot-shiro 33 | * @description: SpringContext的基础支架 34 | * @date: 2019-08-16 3:18 PM 35 | * @version: 1.0 36 | * @website: https://yubuntu0109.github.io/ 37 | */ 38 | @Component 39 | public class SpringContextHolder implements ApplicationContextAware { 40 | 41 | private static ApplicationContext appContext = null; 42 | 43 | /** 44 | * @description: (never used)通过name获取指定的Bean 45 | * @param: name 46 | * @date: 2019-08-16 3:20 PM 47 | * @return: java.lang.Object 48 | */ 49 | public static Object getBean(String name) { 50 | return appContext.getBean(name); 51 | 52 | } 53 | 54 | /** 55 | * @description: 通过class获取指定的Bean 56 | * @param: clazz 57 | * @date: 2019-08-16 3:20 PM 58 | * @return: T 59 | */ 60 | public static T getBean(Class clazz) { 61 | return appContext.getBean(clazz); 62 | } 63 | 64 | /** 65 | * @description: (never used)通过name及clazz获取指定的Bean 66 | * @param: name 67 | * @param: clazz 68 | * @date: 2019-08-16 3:21 PM 69 | * @return: T 70 | */ 71 | public static T getBean(String name, Class clazz) { 72 | return appContext.getBean(name, clazz); 73 | } 74 | 75 | /** 76 | * @description: 初始化applicationContext 77 | * @param: applicationContext 78 | * @date: 2019-08-16 3:21 PM 79 | * @return: void 80 | */ 81 | @Override 82 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 83 | if (appContext == null) { 84 | appContext = applicationContext; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/interceptor/RememberAuthenticationInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.framework.interceptor; 21 | 22 | import com.zyd.shiro.business.consts.SessionConst; 23 | import com.zyd.shiro.business.entity.User; 24 | import com.zyd.shiro.business.service.SysUserService; 25 | import com.zyd.shiro.util.PasswordUtil; 26 | import lombok.extern.slf4j.Slf4j; 27 | import org.apache.shiro.SecurityUtils; 28 | import org.apache.shiro.authc.UsernamePasswordToken; 29 | import org.apache.shiro.session.Session; 30 | import org.apache.shiro.subject.Subject; 31 | import org.springframework.beans.factory.annotation.Autowired; 32 | import org.springframework.stereotype.Component; 33 | import org.springframework.web.servlet.HandlerInterceptor; 34 | import org.springframework.web.servlet.ModelAndView; 35 | 36 | import javax.servlet.http.HttpServletRequest; 37 | import javax.servlet.http.HttpServletResponse; 38 | 39 | /** 40 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 41 | * @version 1.0 42 | * @website https://www.zhyd.me 43 | * @date 2018/7/15 15:24 44 | * @since 1.0 45 | */ 46 | @Slf4j 47 | @Component 48 | public class RememberAuthenticationInterceptor implements HandlerInterceptor { 49 | 50 | @Autowired 51 | private SysUserService userService; 52 | 53 | @Override 54 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 55 | Subject subject = SecurityUtils.getSubject(); 56 | if (subject.isAuthenticated()) { 57 | return true; 58 | } 59 | Session session = subject.getSession(true); 60 | if (session.getAttribute(SessionConst.USER_SESSION_KEY) != null) { 61 | return true; 62 | } 63 | if(!subject.isRemembered()) { 64 | log.warn("未设置“记住我”,跳转到登录页..."); 65 | response.sendRedirect(request.getContextPath() + "/passport/login"); 66 | return false; 67 | } 68 | try { 69 | Long userId = Long.parseLong(subject.getPrincipal().toString()); 70 | User user = userService.getByPrimaryKey(userId); 71 | UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), PasswordUtil.decrypt(user.getPassword(), user.getUsername()), true); 72 | subject.login(token); 73 | session.setAttribute(SessionConst.USER_SESSION_KEY, user); 74 | log.info("[{}] - 已自动登录", user.getUsername()); 75 | } catch (Exception e) { 76 | log.error("自动登录失败", e); 77 | response.sendRedirect(request.getContextPath() + "/passport/login"); 78 | return false; 79 | } 80 | return true; 81 | } 82 | 83 | @Override 84 | public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception { 85 | 86 | } 87 | 88 | @Override 89 | public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception { 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractBO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.object; 25 | 26 | import java.io.Serializable; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: (Business Object)业务对象 31 | * @date: 2019-08-16 3:37 PM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | public abstract class AbstractBO implements Serializable { 36 | private static final long serialVersionUID = -3737736141782545763L; 37 | } 38 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractDO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.object; 25 | 26 | import lombok.Data; 27 | import lombok.EqualsAndHashCode; 28 | 29 | import javax.persistence.GeneratedValue; 30 | import javax.persistence.GenerationType; 31 | import javax.persistence.Id; 32 | import java.io.Serializable; 33 | import java.util.Date; 34 | 35 | /** 36 | * @project: springboot-shiro 37 | * @description: (Data Transfer Object)数据传输对象 38 | * @date: 2019-08-16 3:41 PM 39 | * @version: 1.0 40 | * @website: https://yubuntu0109.github.io/ 41 | */ 42 | @Data 43 | @EqualsAndHashCode(callSuper = false) 44 | public abstract class AbstractDO implements Serializable { 45 | 46 | /** 47 | * @fieldName: serialVersionUID 48 | * @fieldType: long 49 | */ 50 | private static final long serialVersionUID = 5088697673359856350L; 51 | 52 | @Id 53 | @GeneratedValue(strategy = GenerationType.IDENTITY) 54 | private Long id; 55 | 56 | private Date createTime; 57 | private Date updateTime; 58 | 59 | } -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/object/AbstractService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.object; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: 通用的Service接口:提高代码的简洁及可维护性 31 | * @date: 2019-08-16 3:47 PM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | public interface AbstractService { 36 | 37 | /** 38 | * @description: 保存一个实体, null的属性不会保存(使用数据库默认值) 39 | * @param: entity 40 | * @date: 2019-08-16 3:47 PM 41 | * @return: T 42 | */ 43 | T insert(T entity); 44 | 45 | /** 46 | * @description: 批量插入:既支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列 47 | * @param: entities 48 | * @date: 2019-08-16 4:05 PM 49 | * @return: void 50 | */ 51 | void insertList(List entities); 52 | 53 | /** 54 | * @description: 根据主键字段进行删除, 方法参数必须包含完整的主键属性 55 | * @param: primaryKey 56 | * @date: 2019-08-16 4:06 PM 57 | * @return: boolean 58 | */ 59 | boolean removeByPrimaryKey(PK primaryKey); 60 | 61 | /** 62 | * @description: 根据主键更新实体全部字段, null值也会被更新 63 | * @param: entity 64 | * @date: 2019-08-16 4:07 PM 65 | * @return: boolean 66 | */ 67 | boolean update(T entity); 68 | 69 | /** 70 | * @description: 根据主键更新属性不为null的值 71 | * @param: entity 72 | * @date: 2019-08-16 4:08 PM 73 | * @return: boolean 74 | */ 75 | boolean updateSelective(T entity); 76 | 77 | /** 78 | * @description: 根据主键字段进行查询, 方法参数必须包含完整的主键属性, 查询条件使用等号 79 | * @param: primaryKey 80 | * @date: 2019-08-16 4:09 PM 81 | * @return: T 82 | */ 83 | T getByPrimaryKey(PK primaryKey); 84 | 85 | /** 86 | * @description: 根据实体中的属性进行查询, 只能有一个返回值, 有多个结果时抛出异常, 查询条件使用等号 87 | * @param: entity 88 | * @date: 2019-08-16 4:11 PM 89 | * @return: T 90 | */ 91 | T getOneByEntity(T entity); 92 | 93 | /** 94 | * @description: 查询全部结果, 注:listByEntity(null)方法能达到同样的效果 95 | * @param: 96 | * @date: 2019-08-16 4:12 PM 97 | * @return: java.util.List 98 | */ 99 | List listAll(); 100 | 101 | /** 102 | * @description: (never used)根据实体中的属性值进行查询, 查询条件使用等号 103 | * @param: entity 104 | * @date: 2019-08-16 4:12 PM 105 | * @return: java.util.List 106 | */ 107 | List listByEntity(T entity); 108 | } 109 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/object/BaseConditionVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.object; 25 | 26 | import lombok.Data; 27 | import lombok.EqualsAndHashCode; 28 | import org.springframework.format.annotation.DateTimeFormat; 29 | 30 | import java.util.Date; 31 | 32 | /** 33 | * @project: springboot-shiro 34 | * @description: 基础的条件值对象(Value Object) 35 | * @date: 2019-08-16 4:30 PM 36 | * @version: 1.0 37 | * @website: https://yubuntu0109.github.io/ 38 | */ 39 | @Data 40 | @EqualsAndHashCode(callSuper = false) 41 | public class BaseConditionVO { 42 | public final static int DEFAULT_PAGE_SIZE = 10; 43 | private int pageNumber = 1; 44 | private int pageSize = 0; 45 | private int pageStart = 0; 46 | private String orderField; 47 | private String orderDirection; 48 | private String keywords; 49 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 50 | private Date startDate; 51 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 52 | private Date endDate; 53 | 54 | public int getPageSize() { 55 | return pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE; 56 | } 57 | 58 | //the method is never used 59 | public int getPageStart() { 60 | return pageNumber > 0 ? (pageNumber - 1) * getPageSize() : 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/object/PageResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.framework.object; 21 | 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * @project: springboot-shiro 29 | * @description: 分页结果:BootStrap table中需获取的json格式数据 30 | * @date: 2019-08-16 4:17 PM 31 | * @version: 1.0 32 | * @website: https://yubuntu0109.github.io/ 33 | */ 34 | @Data 35 | @EqualsAndHashCode(callSuper = false) 36 | public class PageResult { 37 | private Long total; 38 | private List rows; 39 | 40 | public PageResult(Long total, List rows) { 41 | this.total = total; 42 | this.rows = rows; 43 | } 44 | 45 | //the constructor is never used 46 | public PageResult() { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/object/ResponseVO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.framework.object; 21 | 22 | import com.alibaba.fastjson.JSONObject; 23 | import com.alibaba.fastjson.serializer.SerializerFeature; 24 | import com.zyd.shiro.business.enums.ResponseStatus; 25 | import lombok.Data; 26 | import lombok.EqualsAndHashCode; 27 | 28 | import java.util.Collection; 29 | import java.util.List; 30 | 31 | /** 32 | * @project: springboot-shiro 33 | * @description: Controller层需返回的json格式数据 34 | * @date: 2019-08-16 4:17 PM 35 | * @version: 1.0 36 | * @website: https://yubuntu0109.github.io/ 37 | */ 38 | @Data 39 | @EqualsAndHashCode(callSuper = false) 40 | public class ResponseVO { 41 | private Integer status; 42 | private String message; 43 | private T data; 44 | 45 | public ResponseVO(Integer status, String message, T data) { 46 | this.status = status; 47 | this.message = message; 48 | this.data = data; 49 | } 50 | 51 | //the constructor is never used 52 | public ResponseVO(ResponseStatus status, T data) { 53 | this(status.getCode(), status.getMessage(), data); 54 | } 55 | 56 | //the method is never used 57 | public String toJson() { 58 | T t = this.getData(); 59 | if (t instanceof List || t instanceof Collection) { 60 | return JSONObject.toJSONString(this, SerializerFeature.WriteNullListAsEmpty); 61 | } else { 62 | return JSONObject.toJSONString(this, SerializerFeature.WriteMapNullValue); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/property/DruidProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.framework.property; 21 | 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | import org.springframework.boot.context.properties.ConfigurationProperties; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.core.annotation.Order; 27 | 28 | import java.util.List; 29 | 30 | /** 31 | * @project: springboot-shiro 32 | * @description: druid属性信息 33 | * @date: 2019-08-15 11:35 AM 34 | * @version: 1.0 35 | * @website: https://yubuntu0109.github.io/ 36 | */ 37 | @Configuration 38 | @ConfigurationProperties(prefix = "zyd.druid") 39 | @Data 40 | @EqualsAndHashCode(callSuper = false) 41 | @Order(-1) 42 | public class DruidProperties { 43 | private String username; 44 | private String password; 45 | private String servletPath = "/druid/*"; 46 | private Boolean resetEnable = false; 47 | private List allowIps; 48 | private List denyIps; 49 | } 50 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/property/RedisProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.property; 25 | 26 | import lombok.Data; 27 | import lombok.EqualsAndHashCode; 28 | import org.springframework.boot.context.properties.ConfigurationProperties; 29 | import org.springframework.context.annotation.Configuration; 30 | import org.springframework.core.annotation.Order; 31 | 32 | /** 33 | * @project: springboot-shiro 34 | * @description: redis属性信息 35 | * @date: 2019-08-15 11:37 AM 36 | * @version: 1.0 37 | * @website: https://yubuntu0109.github.io/ 38 | */ 39 | @Configuration 40 | @ConfigurationProperties(prefix = "spring.redis") 41 | @Data 42 | @EqualsAndHashCode(callSuper = false) 43 | @Order(-1) 44 | public class RedisProperties { 45 | private Integer database; 46 | private String host; 47 | private Integer port; 48 | private String password; 49 | private Integer timeout; 50 | /** 51 | * 默认30天 = 2592000s 52 | */ 53 | private Integer expire = 2592000; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/redis/CustomRedisManager.java: -------------------------------------------------------------------------------- 1 | package com.zyd.shiro.framework.redis; 2 | 3 | import org.crazycake.shiro.RedisManager; 4 | import org.springframework.util.StringUtils; 5 | import redis.clients.jedis.Jedis; 6 | import redis.clients.jedis.JedisPool; 7 | import redis.clients.jedis.JedisPoolConfig; 8 | 9 | import java.util.Set; 10 | 11 | /** 12 | * 自定义org.crazycake.shiro.RedisManager。
13 | * 该自定义的Manager扩展的功能:
14 | * 1.增加database参数,可跟随配置文件的数据库索引选择redis数据库保存相关数据,避免了多个项目共用一个redis database所潜在的问题
15 | * 2.修改expire参数,默认值为30天 = 2592000s
16 | * 17 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 18 | * @version 1.0 19 | * @website https://www.zhyd.me 20 | * @date 2018/6/12 14:22 21 | * @since 1.0 22 | */ 23 | public class CustomRedisManager extends RedisManager { 24 | private static JedisPool jedisPool = null; 25 | private String host = "127.0.0.1"; 26 | private int port = 6379; 27 | private int expire = 2592000; 28 | private int timeout = 2000; 29 | private int database = 0; 30 | private String password = null; 31 | 32 | public CustomRedisManager() { 33 | } 34 | 35 | @Override 36 | public void init() { 37 | this.password = StringUtils.isEmpty(this.password) ? null : this.password; 38 | if (jedisPool == null) { 39 | jedisPool = new JedisPool(new JedisPoolConfig(), this.host, this.port, this.timeout, this.password, database); 40 | } 41 | } 42 | 43 | @Override 44 | public byte[] get(byte[] key) { 45 | byte[] value = null; 46 | 47 | try (Jedis jedis = jedisPool.getResource()) { 48 | value = jedis.get(key); 49 | } 50 | 51 | return value; 52 | } 53 | 54 | @Override 55 | public byte[] set(byte[] key, byte[] value) { 56 | 57 | try (Jedis jedis = jedisPool.getResource()) { 58 | jedis.set(key, value); 59 | if (this.expire != 0) { 60 | jedis.expire(key, this.expire); 61 | } 62 | } 63 | 64 | return value; 65 | } 66 | 67 | @Override 68 | public byte[] set(byte[] key, byte[] value, int expire) { 69 | 70 | try (Jedis jedis = jedisPool.getResource()) { 71 | jedis.set(key, value); 72 | if (expire != 0) { 73 | jedis.expire(key, expire); 74 | } 75 | } 76 | 77 | return value; 78 | } 79 | 80 | @Override 81 | public void del(byte[] key) { 82 | 83 | try (Jedis jedis = jedisPool.getResource()) { 84 | jedis.del(key); 85 | } 86 | 87 | } 88 | 89 | @Override 90 | public void flushDB() { 91 | 92 | try (Jedis jedis = jedisPool.getResource()) { 93 | jedis.flushDB(); 94 | } 95 | 96 | } 97 | 98 | @Override 99 | public Long dbSize() { 100 | Long dbSize = 0L; 101 | 102 | try (Jedis jedis = jedisPool.getResource()) { 103 | dbSize = jedis.dbSize(); 104 | } 105 | 106 | return dbSize; 107 | } 108 | 109 | @Override 110 | public Set keys(String pattern) { 111 | Set keys = null; 112 | 113 | try (Jedis jedis = jedisPool.getResource()) { 114 | keys = jedis.keys(pattern.getBytes()); 115 | } 116 | 117 | return keys; 118 | } 119 | 120 | @Override 121 | public String getHost() { 122 | return this.host; 123 | } 124 | 125 | @Override 126 | public void setHost(String host) { 127 | this.host = host; 128 | } 129 | 130 | @Override 131 | public int getPort() { 132 | return this.port; 133 | } 134 | 135 | @Override 136 | public void setPort(int port) { 137 | this.port = port; 138 | } 139 | 140 | @Override 141 | public int getExpire() { 142 | return this.expire; 143 | } 144 | 145 | @Override 146 | public void setExpire(int expire) { 147 | this.expire = expire; 148 | } 149 | 150 | @Override 151 | public int getTimeout() { 152 | return this.timeout; 153 | } 154 | 155 | @Override 156 | public void setTimeout(int timeout) { 157 | this.timeout = timeout; 158 | } 159 | 160 | @Override 161 | public String getPassword() { 162 | return this.password; 163 | } 164 | 165 | @Override 166 | public void setPassword(String password) { 167 | this.password = password; 168 | } 169 | 170 | public int getDatabase() { 171 | return database; 172 | } 173 | 174 | public void setDatabase(Integer database) { 175 | if (null == database) { 176 | return; 177 | } 178 | this.database = database; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/runner/BlogApplicationRunner.java: -------------------------------------------------------------------------------- 1 | package com.zyd.shiro.framework.runner; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.ApplicationArguments; 6 | import org.springframework.boot.ApplicationRunner; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * 程序启动后通过ApplicationRunner处理一些事务 11 | * 12 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 13 | * @version 1.0 14 | * @website https://www.zhyd.me 15 | * @date 2018/6/6 16:07 16 | * @since 1.0 17 | */ 18 | @Slf4j 19 | @Component 20 | public class BlogApplicationRunner implements ApplicationRunner { 21 | 22 | @Value("${server.port}") 23 | private int port; 24 | 25 | @Override 26 | public void run(ApplicationArguments applicationArguments) { 27 | log.info("程序部署完成,访问地址:http://localhost:" + port); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/framework/tag/CustomTagDirective.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 yadong.zhang 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.framework.tag; 25 | 26 | import com.zyd.shiro.business.service.SysResourcesService; 27 | import freemarker.core.Environment; 28 | import freemarker.template.*; 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.stereotype.Component; 31 | import org.springframework.util.StringUtils; 32 | 33 | import java.io.IOException; 34 | import java.util.HashMap; 35 | import java.util.Map; 36 | 37 | /** 38 | * 自定义的freemarker标签 39 | * 40 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 41 | * @version 1.0 42 | * @website https://www.zhyd.me 43 | * @date 2018/4/16 16:26 44 | * @since 1.0 45 | */ 46 | @Component 47 | public class CustomTagDirective implements TemplateDirectiveModel { 48 | private static final String METHOD_KEY = "method"; 49 | @Autowired 50 | private SysResourcesService resourcesService; 51 | 52 | @Override 53 | public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { 54 | DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); 55 | if (map.containsKey(METHOD_KEY)) { 56 | String method = map.get(METHOD_KEY).toString(); 57 | switch (method) { 58 | case "availableMenus": 59 | // 获取所有可用的菜单资源 60 | environment.setVariable("availableMenus", builder.build().wrap(resourcesService.listAllAvailableMenu())); 61 | break; 62 | case "menus": 63 | Integer userId = null; 64 | if (map.containsKey("userId")) { 65 | String userIdStr = map.get("userId").toString(); 66 | if(StringUtils.isEmpty(userIdStr)){ 67 | return; 68 | } 69 | userId = Integer.parseInt(userIdStr); 70 | } 71 | Map params = new HashMap<>(2); 72 | params.put("type", "menu"); 73 | params.put("userId", userId); 74 | environment.setVariable("menus", builder.build().wrap(resourcesService.listUserResources(params))); 75 | break; 76 | default: 77 | break; 78 | } 79 | } 80 | templateDirectiveBody.render(environment.getOut()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysResources.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.beans; 21 | 22 | import com.zyd.shiro.framework.object.AbstractDO; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | 26 | import javax.persistence.Transient; 27 | import java.util.List; 28 | 29 | /** 30 | * @project: springboot-shiro 31 | * @description: 资源信息 32 | * @date: 2019-08-14 2:19 PM 33 | * @version: 1.0 34 | * @website: https://yubuntu0109.github.io/ 35 | */ 36 | @Data 37 | @EqualsAndHashCode(callSuper = false) 38 | public class SysResources extends AbstractDO { 39 | private String name; 40 | private String type; 41 | private String url; 42 | private String permission; 43 | private Long parentId; 44 | private Integer sort; 45 | private Boolean external; 46 | private Boolean available; 47 | private String icon; 48 | 49 | @Transient 50 | private String checked; 51 | @Transient 52 | private SysResources parent; 53 | @Transient 54 | private List nodes; 55 | } 56 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRole.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.beans; 21 | 22 | import com.zyd.shiro.framework.object.AbstractDO; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | 26 | import javax.persistence.Transient; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: 角色信息 31 | * @date: 2019-08-14 2:22 PM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | @Data 36 | @EqualsAndHashCode(callSuper = false) 37 | public class SysRole extends AbstractDO { 38 | private String name; 39 | private String description; 40 | private Boolean available; 41 | 42 | @Transient 43 | private Integer selected; 44 | } 45 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysRoleResources.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.beans; 21 | 22 | import com.zyd.shiro.framework.object.AbstractDO; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 连接用户与资源信息的桥梁 29 | * @date: 2019-08-14 2:23 PM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | @Data 34 | @EqualsAndHashCode(callSuper = false) 35 | public class SysRoleResources extends AbstractDO { 36 | private Long roleId; 37 | private Long resourcesId; 38 | } 39 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.beans; 21 | 22 | import com.zyd.shiro.framework.object.AbstractDO; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | 26 | import java.util.Date; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: 用户信息 31 | * @date: 2019-08-14 1:56 PM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | @Data 36 | @EqualsAndHashCode(callSuper = false) 37 | public class SysUser extends AbstractDO { 38 | private String username; 39 | private String password; 40 | private String nickname; 41 | private String mobile; 42 | private String email; 43 | private String qq; 44 | private Date birthday; 45 | private Integer gender; 46 | private String avatar; 47 | private String userType; 48 | private String regIp; 49 | private String lastLoginIp; 50 | private Date lastLoginTime; 51 | private Integer loginCount; 52 | private String remark; 53 | private Integer status; 54 | } 55 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/beans/SysUserRole.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.beans; 21 | 22 | import com.zyd.shiro.framework.object.AbstractDO; 23 | import lombok.Data; 24 | import lombok.EqualsAndHashCode; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 连接用户与角色信息的桥梁 29 | * @date: 2019-08-14 2:32 PM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | @Data 34 | @EqualsAndHashCode(callSuper = false) 35 | public class SysUserRole extends AbstractDO { 36 | private Long userId; 37 | private Long roleId; 38 | } 39 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysResourceMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.mapper; 21 | 22 | import com.zyd.shiro.business.vo.ResourceConditionVO; 23 | import com.zyd.shiro.persistence.beans.SysResources; 24 | import com.zyd.shiro.plugin.BaseMapper; 25 | import org.springframework.stereotype.Repository; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * @project: springboot-shiro 32 | * @description: 操控系统资源信息 33 | * @date: 2019-08-14 3:06 PM 34 | * @version: 1.0 35 | * @website: https://yubuntu0109.github.io/ 36 | */ 37 | @Repository 38 | public interface SysResourceMapper extends BaseMapper { 39 | 40 | /** 41 | * @description: 分页查询系统资源 42 | * @param: vo 43 | * @date: 2019-08-14 3:08 PM 44 | * @return: java.util.List 45 | */ 46 | List findPageBreakByCondition(ResourceConditionVO vo); 47 | 48 | /** 49 | * @description: 获取用户的资源列表 50 | * @param: map 51 | * @date: 2019-08-14 3:10 PM 52 | * @return: java.util.List 53 | */ 54 | List listUserResources(Map map); 55 | 56 | /** 57 | * @description: 根据角色id获取ztree使用的资源列表, 代码参考自 http://blog.csdn.net/poorcoder_/article/details/71374002 58 | * @param: rid 59 | * @date: 2019-08-14 3:12 PM 60 | * @return: java.util.List 61 | */ 62 | List queryResourcesListWithSelected(Long rid); 63 | 64 | /** 65 | * @description: 获取资源的url和Permission 66 | * @param: 67 | * @date: 2019-08-14 3:13 PM 68 | * @return: java.util.List 69 | */ 70 | List listUrlAndPermission(); 71 | 72 | /** 73 | * @description: 获取所有可用的菜单资源 74 | * @param: 75 | * @date: 2019-08-14 3:15 PM 76 | * @return: java.util.List 77 | */ 78 | List listAllAvailableMenu(); 79 | 80 | /** 81 | * @description: 通过父级菜单id获取父级资源下所有menu资源 82 | * @param: pid 83 | * @date: 2019-08-14 3:16 PM 84 | * @return: java.util.List 85 | */ 86 | List listMenuResourceByPid(Long pid); 87 | 88 | /** 89 | * @description: 通过用户id获取用户关联的所有资源 90 | * @param: userId 91 | * @date: 2019-08-14 3:18 PM 92 | * @return: java.util.List 93 | */ 94 | List listByUserId(Long userId); 95 | } 96 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.persistence.mapper; 21 | 22 | import com.zyd.shiro.business.vo.RoleConditionVO; 23 | import com.zyd.shiro.persistence.beans.SysRole; 24 | import com.zyd.shiro.plugin.BaseMapper; 25 | import org.springframework.stereotype.Repository; 26 | 27 | import java.util.List; 28 | 29 | /** 30 | * @project: springboot-shiro 31 | * @description: 操控系统角色信息 32 | * @date: 2019-08-14 2:48 PM 33 | * @version: 1.0 34 | * @website: https://yubuntu0109.github.io/ 35 | */ 36 | @Repository 37 | public interface SysRoleMapper extends BaseMapper { 38 | 39 | /** 40 | * @description: 分页查询角色信息 41 | * @param: vo 42 | * @date: 2019-08-14 2:49 PM 43 | * @return: java.util.List 44 | */ 45 | List findPageBreakByCondition(RoleConditionVO vo); 46 | 47 | /** 48 | * @description: 通过用户id获取ztree使用的角色列表, 代码参考自 http://blog.csdn.net/poorcoder_/article/details/71374002 49 | * @param: userId 50 | * @date: 2019-08-14 2:50 PM 51 | * @return: java.util.List 52 | */ 53 | List queryRoleListWithSelected(Integer userId); 54 | 55 | /** 56 | * @description: 通过用户id获取用户所拥有的角色信息 57 | * @param: userId 58 | * @date: 2019-08-14 2:51 PM 59 | * @return: java.util.List 60 | */ 61 | List listRolesByUserId(Long userId); 62 | } 63 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysRoleResourcesMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.persistence.mapper; 25 | 26 | import com.zyd.shiro.persistence.beans.SysRoleResources; 27 | import com.zyd.shiro.plugin.BaseMapper; 28 | import org.springframework.stereotype.Repository; 29 | 30 | /** 31 | * @project: springboot-shiro 32 | * @description: 角色与资源信息的连表操作 33 | * @date: 2019-08-14 3:39 PM 34 | * @version: 1.0 35 | * @website: https://yubuntu0109.github.io/ 36 | */ 37 | @Repository 38 | public interface SysRoleResourcesMapper extends BaseMapper { 39 | } 40 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.persistence.mapper; 25 | 26 | import com.zyd.shiro.business.vo.UserConditionVO; 27 | import com.zyd.shiro.persistence.beans.SysUser; 28 | import com.zyd.shiro.plugin.BaseMapper; 29 | import org.springframework.stereotype.Repository; 30 | 31 | import java.util.List; 32 | 33 | /** 34 | * @project: springboot-shiro 35 | * @description: 操控系统用户信息 36 | * @date: 2019-08-14 2:47 PM 37 | * @version: 1.0 38 | * @website: https://yubuntu0109.github.io/ 39 | */ 40 | @Repository 41 | public interface SysUserMapper extends BaseMapper { 42 | 43 | /** 44 | * @description: 分页查询用户信息 45 | * @param: vo 46 | * @date: 2019-08-14 2:34 PM 47 | * @return: java.util.List 48 | */ 49 | List findPageBreakByCondition(UserConditionVO vo); 50 | 51 | /** 52 | * @description: 通过角色Id获取用户列表 53 | * @param: roleId 54 | * @date: 2019-08-14 2:34 PM 55 | * @return: java.util.List 56 | */ 57 | List listByRoleId(Long roleId); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/persistence/mapper/SysUserRoleMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | *

4 | * Copyright (c) 2018 yadong.zhang 5 | *

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

13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.zyd.shiro.persistence.mapper; 25 | 26 | import com.zyd.shiro.persistence.beans.SysUserRole; 27 | import com.zyd.shiro.plugin.BaseMapper; 28 | import org.springframework.stereotype.Repository; 29 | 30 | import java.util.List; 31 | 32 | 33 | /** 34 | * @project: springboot-shiro 35 | * @description: 用户与角色信息的连表操作 36 | * @date: 2019-08-14 2:59 PM 37 | * @version: 1.0 38 | * @website: https://yubuntu0109.github.io/ 39 | */ 40 | @Repository 41 | public interface SysUserRoleMapper extends BaseMapper { 42 | 43 | /** 44 | * @description: (never used)通过角色id查询指定的用户信息 45 | * @param: roleId 46 | * @date: 2019-08-14 3:04 PM 47 | * @return: java.util.List 48 | */ 49 | List findUserIdByRoleId(Integer roleId); 50 | } 51 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/plugin/BaseMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.plugin; 21 | 22 | import tk.mybatis.mapper.common.Mapper; 23 | import tk.mybatis.mapper.common.MySqlMapper; 24 | 25 | /** 26 | * @project: springboot-shiro 27 | * @description: 通用的Mapper接口:提高代码的简洁及可维护性 28 | * @date: 2019-08-16 3:51 PM 29 | * @version: 1.0 30 | * @website: https://yubuntu0109.github.io/ 31 | */ 32 | public interface BaseMapper extends Mapper, MySqlMapper { 33 | // 特别注意:该接口不能被扫描到,否则会出错 34 | } 35 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/util/AesUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.util; 21 | 22 | import org.apache.commons.codec.binary.Base64; 23 | 24 | import javax.crypto.Cipher; 25 | import javax.crypto.KeyGenerator; 26 | import javax.crypto.SecretKey; 27 | import javax.crypto.spec.SecretKeySpec; 28 | import java.security.NoSuchAlgorithmException; 29 | import java.security.SecureRandom; 30 | 31 | /** 32 | * @project: springboot-shiro 33 | * @description: 加密工具类:AES(Advanced Encryption Standard),又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准 34 | * @date: 2019-08-15 10:35 AM 35 | * @version: 1.0 36 | * @website: https://yubuntu0109.github.io/ 37 | */ 38 | public class AesUtil { 39 | private static final String KEY_ALGORITHM = "AES"; 40 | private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding"; 41 | 42 | /** 43 | * @description: AES加密 44 | * @param: passwd 加密的密钥 45 | * @param: content 需要加密的字符串 46 | * @date: 2019-08-15 10:40 AM 47 | * @return: java.lang.String 返回Base64转码后的加密数据 48 | */ 49 | public static String encrypt(String passwd, String content) throws Exception { 50 | // 创建密码器 51 | Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); 52 | // 指定待加密字符的编码格式 53 | byte[] byteContent = content.getBytes("utf-8"); 54 | // 初始化为加密模式的密码器 55 | cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(passwd)); 56 | // 加密 57 | byte[] result = cipher.doFinal(byteContent); 58 | //通过Base64转码返回 59 | return Base64.encodeBase64String(result); 60 | } 61 | 62 | /** 63 | * @description: AES解密 64 | * @param: passwd 加密的密钥 65 | * @param: encrypted 已加密的密文 66 | * @date: 2019-08-15 10:44 AM 67 | * @return: java.lang.String 返回解密后的数据 68 | */ 69 | public static String decrypt(String passwd, String encrypted) throws Exception { 70 | //实例化 71 | Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); 72 | //使用密钥初始化,设置为解密模式 73 | cipher.init(Cipher.DECRYPT_MODE, getSecretKey(passwd)); 74 | //解密 75 | byte[] result = cipher.doFinal(Base64.decodeBase64(encrypted)); 76 | //返回解密后的数据 77 | return new String(result, "utf-8"); 78 | } 79 | 80 | /** 81 | * @description: 生成加密秘钥 82 | * @param: password 83 | * @date: 2019-08-15 10:46 AM 84 | * @return: javax.crypto.spec.SecretKeySpec 85 | */ 86 | private static SecretKeySpec getSecretKey(final String password) throws NoSuchAlgorithmException { 87 | // 获取生成指定算法密钥生成器的 KeyGenerator 对象 88 | KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); 89 | // 异常:javax.crypto.BadPaddingException: Given final block not properly padded的解决方案如下 90 | // https://www.cnblogs.com/zempty/p/4318902.html - 用此法解决的 91 | // https://www.cnblogs.com/digdeep/p/5580244.html - 留作参考吧 92 | SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); 93 | random.setSeed(password.getBytes()); 94 | // AES要求密钥长度为128 95 | kg.init(128, random); 96 | // 生成一个密钥 97 | SecretKey secretKey = kg.generateKey(); 98 | // 转换为AES专用密钥 99 | return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/util/IpUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.util; 21 | 22 | import org.springframework.util.StringUtils; 23 | 24 | import javax.servlet.http.HttpServletRequest; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: 获取IP的工具类 29 | * @date: 2019-08-15 10:55 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | public class IpUtil { 34 | 35 | /** 36 | * @description: 获取真实的IP地址 37 | * @param: request 38 | * @date: 2019-08-15 10:52 AM 39 | * @return: java.lang.String 40 | */ 41 | public static String getRealIp(HttpServletRequest request) { 42 | String ip = request.getHeader("x-forwarded-for"); 43 | return checkIp(ip) ? ip : ( 44 | checkIp(ip = request.getHeader("Proxy-Client-IP")) ? ip : ( 45 | checkIp(ip = request.getHeader("WL-Proxy-Client-IP")) ? ip : 46 | request.getRemoteAddr())); 47 | } 48 | 49 | /** 50 | * @description: 校验IP地址 51 | * @param: ip 52 | * @date: 2019-08-15 10:53 AM 53 | * @return: boolean 54 | */ 55 | private static boolean checkIp(String ip) { 56 | return !StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip); 57 | } 58 | } -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/util/Md5Util.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.util; 21 | 22 | import lombok.extern.slf4j.Slf4j; 23 | 24 | import java.security.MessageDigest; 25 | 26 | /** 27 | * @project: springboot-shiro 28 | * @description: MD5加密工具类 29 | * @date: 2019-08-15 10:55 AM 30 | * @version: 1.0 31 | * @website: https://yubuntu0109.github.io/ 32 | */ 33 | @Slf4j 34 | public class Md5Util { 35 | 36 | /** 37 | * @description: (never used)通过盐值对字符串进行MD5加密 38 | * @param: param 需要加密的字符串 39 | * @param: salt 盐值 40 | * @date: 2019-08-15 10:56 AM 41 | * @return: java.lang.String 42 | */ 43 | public static String MD5(String param, String salt) { 44 | return MD5(param + salt); 45 | } 46 | 47 | /** 48 | * @description: 加密字符串 49 | * @param: s 50 | * @date: 2019-08-15 10:57 AM 51 | * @return: java.lang.String 52 | */ 53 | public static String MD5(String s) { 54 | char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 55 | try { 56 | byte[] btInput = s.getBytes(); 57 | MessageDigest mdInst = MessageDigest.getInstance("MD5"); 58 | mdInst.update(btInput); 59 | byte[] md = mdInst.digest(); 60 | int j = md.length; 61 | char[] str = new char[j * 2]; 62 | int k = 0; 63 | for (byte byte0 : md) { 64 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 65 | str[k++] = hexDigits[byte0 & 0xf]; 66 | } 67 | return new String(str); 68 | } catch (Exception e) { 69 | log.error("MD5生成失败", e); 70 | return null; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/util/PasswordUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.util; 21 | 22 | import com.zyd.shiro.business.consts.CommonConst; 23 | 24 | /** 25 | * @project: springboot-shiro 26 | * @description: 用户密码加密/解密工具 27 | * @date: 2017/12/15 17:03 28 | * @version: 1.0 29 | * @website: https://yubuntu0109.github.io/ 30 | */ 31 | public class PasswordUtil { 32 | 33 | /** 34 | * @throws Exception 35 | * @description: AES 加密 36 | * @param: password 未加密的用户密码 37 | * @param: salt 默认使用用户名作为盐值 38 | * @date: 2019-08-13 1:15 PM 39 | * @return: java.lang.String 40 | */ 41 | public static String encrypt(String password, String salt) throws Exception { 42 | return AesUtil.encrypt(Md5Util.MD5(salt + CommonConst.ZYD_SECURITY_KEY), password); 43 | } 44 | 45 | /** 46 | * @throws Exception 47 | * @description: AES 解密 48 | * @param: encryptPassword 加密后的用户密码 49 | * @param: salt 默认使用用户名作为盐值 50 | * @date: 2019-08-13 1:17 PM 51 | * @return: java.lang.String 52 | */ 53 | public static String decrypt(String encryptPassword, String salt) throws Exception { 54 | return AesUtil.decrypt(Md5Util.MD5(salt + CommonConst.ZYD_SECURITY_KEY), encryptPassword); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/util/ResultUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.util; 21 | 22 | import com.github.pagehelper.PageInfo; 23 | import com.zyd.shiro.business.consts.CommonConst; 24 | import com.zyd.shiro.business.enums.ResponseStatus; 25 | import com.zyd.shiro.framework.object.PageResult; 26 | import com.zyd.shiro.framework.object.ResponseVO; 27 | import org.springframework.web.servlet.ModelAndView; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | /** 34 | * @project: springboot-shiro 35 | * @description: 接口返回工具类:支持ModelAndView、ResponseVO、PageResult 36 | * @date: 2019-08-15 10:59 AM 37 | * @version: 1.0 38 | * @website: https://yubuntu0109.github.io/ 39 | */ 40 | public class ResultUtil { 41 | 42 | public static ModelAndView view(String view) { 43 | return new ModelAndView(view); 44 | } 45 | 46 | //the method is not used 47 | public static ModelAndView view(String view, Map model) { 48 | return new ModelAndView(view, model); 49 | } 50 | 51 | public static ModelAndView redirect(String view) { 52 | return new ModelAndView("redirect:" + view); 53 | } 54 | 55 | public static ResponseVO error(int code, String message) { 56 | return vo(code, message, null); 57 | } 58 | 59 | public static ResponseVO error(ResponseStatus status) { 60 | return vo(status.getCode(), status.getMessage(), null); 61 | } 62 | 63 | public static ResponseVO error(String message) { 64 | return vo(CommonConst.DEFAULT_ERROR_CODE, message, null); 65 | } 66 | 67 | public static ResponseVO success(String message, Object data) { 68 | return vo(CommonConst.DEFAULT_SUCCESS_CODE, message, data); 69 | } 70 | 71 | public static ResponseVO success(String message) { 72 | return success(message, null); 73 | } 74 | 75 | public static ResponseVO success(ResponseStatus status) { 76 | return vo(status.getCode(), status.getMessage(), null); 77 | } 78 | 79 | public static ResponseVO vo(int code, String message, Object data) { 80 | return new ResponseVO<>(code, message, data); 81 | } 82 | 83 | public static PageResult tablePage(Long total, List list) { 84 | return new PageResult(total, list); 85 | } 86 | 87 | public static PageResult tablePage(PageInfo info) { 88 | if (info == null) { 89 | return new PageResult(0L, new ArrayList()); 90 | } 91 | return tablePage(info.getTotal(), info.getList()); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /shiro-core/src/main/java/com/zyd/shiro/util/SessionUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * Copyright (c) 2018 yadong.zhang 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | * SOFTWARE. 19 | */ 20 | package com.zyd.shiro.util; 21 | 22 | import com.zyd.shiro.business.consts.SessionConst; 23 | import com.zyd.shiro.business.entity.User; 24 | import com.zyd.shiro.framework.holder.RequestHolder; 25 | 26 | import java.util.UUID; 27 | 28 | /** 29 | * @project: springboot-shiro 30 | * @description: Session工具类 31 | * @date: 2019-08-15 11:04 AM 32 | * @version: 1.0 33 | * @website: https://yubuntu0109.github.io/ 34 | */ 35 | public class SessionUtil { 36 | 37 | /** 38 | * @description: 获取session中的用户信息 39 | * @param: 40 | * @date: 2019-08-15 11:04 AM 41 | * @return: com.zyd.shiro.business.entity.User 42 | */ 43 | public static User getUser() { 44 | return (User) RequestHolder.getSession(SessionConst.USER_SESSION_KEY); 45 | } 46 | 47 | /** 48 | * @description: 将用户信息添加到session 49 | * @param: user 50 | * @date: 2019-08-15 11:05 AM 51 | * @return: void 52 | */ 53 | public static void setUser(User user) { 54 | RequestHolder.setSession(SessionConst.USER_SESSION_KEY, user); 55 | } 56 | 57 | /** 58 | * @description: 删除session中的用户信息 59 | * @param: 60 | * @date: 2019-08-15 11:05 AM 61 | * @return: void 62 | */ 63 | public static void removeUser() { 64 | RequestHolder.removeSession(SessionConst.USER_SESSION_KEY); 65 | } 66 | 67 | /** 68 | * @description: 获取session中的Token信息 69 | * @param: key 70 | * @date: 2019-08-15 11:09 AM 71 | * @return: java.lang.String 72 | */ 73 | public static String getToken(String key) { 74 | return (String) RequestHolder.getSession(key); 75 | } 76 | 77 | /** 78 | * @description: 将Token信息添加到session 79 | * @param: key 80 | * @date: 2019-08-15 11:09 AM 81 | * @return: void 82 | */ 83 | public static void setToken(String key) { 84 | RequestHolder.setSession(key, UUID.randomUUID().toString()); 85 | } 86 | 87 | /** 88 | * @description: 删除session中的Token信息 89 | * @param: key 90 | * @date: 2019-08-15 11:10 AM 91 | * @return: void 92 | */ 93 | public static void removeToken(String key) { 94 | RequestHolder.removeSession(key); 95 | } 96 | 97 | /** 98 | * @description: 删除所有的session信息 99 | * @param: 100 | * @date: 2019-08-15 11:11 AM 101 | * @return: void 102 | */ 103 | public static void removeAllSession() { 104 | String[] keys = RequestHolder.getSessionKeys(); 105 | if (keys != null && keys.length > 0) { 106 | for (String key : keys) { 107 | RequestHolder.removeSession(key); 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /shiro-core/src/main/resources/mybatis/SysRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 32 | 33 | 34 | 54 | 55 | 56 | 65 | 66 | -------------------------------------------------------------------------------- /shiro-core/src/main/resources/mybatis/SysUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 79 | 80 | 81 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /shiro-core/src/main/resources/mybatis/SysUserRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 22 | -------------------------------------------------------------------------------- /shiro-core/src/test/java/com/zyd/shiro/ListUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.zyd.shiro; 2 | 3 | import org.junit.Test; 4 | import org.springframework.util.StringUtils; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) 11 | * @version 1.0 12 | * @date 2018/5/17 11:35 13 | * @since 1.0 14 | */ 15 | public class ListUtilTest { 16 | 17 | @Test 18 | public void list2String(){ 19 | List list = new ArrayList<>(); 20 | for(int i = 0 ; i < 10; i ++){ 21 | list.add(i + 100 + ""); 22 | } 23 | // 类js中的array.join(,)方法 24 | System.out.println(StringUtils.collectionToDelimitedString(list, ","));; 25 | System.out.println(StringUtils.arrayToDelimitedString(list.toArray(new String[list.size()]), ","));; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /shiro-core/src/test/java/com/zyd/shiro/ShiroCoreApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.zyd.shiro; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShiroCoreApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------