├── .gitignore
├── LICENSE
├── README.md
├── docs
├── db
│ └── shiro.sql
└── img
│ ├── admin-resource.PNG
│ ├── admin-role.PNG
│ ├── admin-user.PNG
│ ├── db-datasource.PNG
│ ├── db-login.PNG
│ ├── index.PNG
│ ├── login.PNG
│ ├── role-role[admin].PNG
│ ├── root-resource.PNG
│ ├── root-role-[root].PNG
│ ├── root-role.PNG
│ ├── root-user.PNG
│ ├── root-user[role].PNG
│ └── sql-model.png
├── pom.xml
├── shiro-admin
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── zyd
│ │ │ └── shiro
│ │ │ ├── ShiroAdminApplication.java
│ │ │ └── controller
│ │ │ ├── ErrorPagesController.java
│ │ │ ├── ExceptionHandleController.java
│ │ │ ├── PassportController.java
│ │ │ ├── RenderController.java
│ │ │ ├── RestResourcesController.java
│ │ │ ├── RestRoleController.java
│ │ │ └── RestUserController.java
│ └── resources
│ │ ├── application.yml
│ │ ├── logback.xml
│ │ ├── static
│ │ └── assets
│ │ │ ├── css
│ │ │ └── zhyd.core.css
│ │ │ ├── images
│ │ │ ├── default-portrait.png
│ │ │ ├── favicon.ico
│ │ │ └── loading.gif
│ │ │ └── js
│ │ │ ├── jquery-form.js
│ │ │ ├── validator.js
│ │ │ ├── zhyd.core.js
│ │ │ ├── zyd.table.js
│ │ │ └── zyd.tool.js
│ │ └── templates
│ │ ├── error
│ │ ├── 401.ftl
│ │ ├── 403.ftl
│ │ ├── 404.ftl
│ │ └── 500.ftl
│ │ ├── index.ftl
│ │ ├── layout
│ │ ├── footer.ftl
│ │ ├── header.ftl
│ │ ├── setting.ftl
│ │ └── sidebar.ftl
│ │ ├── login.ftl
│ │ ├── resources
│ │ └── list.ftl
│ │ ├── role
│ │ └── list.ftl
│ │ └── user
│ │ └── list.ftl
│ └── test
│ └── java
│ └── com
│ └── zyd
│ └── shiro
│ └── ShiroAdminApplicationTests.java
└── shiro-core
├── .gitignore
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── zyd
│ │ └── shiro
│ │ ├── business
│ │ ├── consts
│ │ │ ├── CommonConst.java
│ │ │ └── SessionConst.java
│ │ ├── entity
│ │ │ ├── Resources.java
│ │ │ ├── Role.java
│ │ │ ├── RoleResources.java
│ │ │ ├── User.java
│ │ │ └── UserRole.java
│ │ ├── enums
│ │ │ ├── ResourceTypeEnum.java
│ │ │ ├── ResponseStatus.java
│ │ │ ├── UserGenderEnum.java
│ │ │ ├── UserStatusEnum.java
│ │ │ └── UserTypeEnum.java
│ │ ├── service
│ │ │ ├── ShiroService.java
│ │ │ ├── SysResourcesService.java
│ │ │ ├── SysRoleResourcesService.java
│ │ │ ├── SysRoleService.java
│ │ │ ├── SysUserRoleService.java
│ │ │ ├── SysUserService.java
│ │ │ └── impl
│ │ │ │ ├── ShiroServiceImpl.java
│ │ │ │ ├── SysResourcesServiceImpl.java
│ │ │ │ ├── SysRoleResourcesServiceImpl.java
│ │ │ │ ├── SysRoleServiceImpl.java
│ │ │ │ ├── SysUserRoleServiceImpl.java
│ │ │ │ └── SysUserServiceImpl.java
│ │ ├── shiro
│ │ │ ├── credentials
│ │ │ │ ├── CredentialsMatcher.java
│ │ │ │ └── RetryLimitCredentialsMatcher.java
│ │ │ └── realm
│ │ │ │ └── ShiroRealm.java
│ │ └── vo
│ │ │ ├── ResourceConditionVO.java
│ │ │ ├── RoleConditionVO.java
│ │ │ └── UserConditionVO.java
│ │ ├── framework
│ │ ├── config
│ │ │ ├── DruidConfig.java
│ │ │ ├── ErrorPagesConfig.java
│ │ │ ├── FreeMarkerConfig.java
│ │ │ ├── MybatisConfig.java
│ │ │ ├── RedisConfig.java
│ │ │ ├── ShiroConfig.java
│ │ │ └── WebMvcConfig.java
│ │ ├── exception
│ │ │ └── ZhydException.java
│ │ ├── holder
│ │ │ ├── RequestHolder.java
│ │ │ └── SpringContextHolder.java
│ │ ├── interceptor
│ │ │ └── RememberAuthenticationInterceptor.java
│ │ ├── object
│ │ │ ├── AbstractBO.java
│ │ │ ├── AbstractDO.java
│ │ │ ├── AbstractService.java
│ │ │ ├── BaseConditionVO.java
│ │ │ ├── PageResult.java
│ │ │ └── ResponseVO.java
│ │ ├── property
│ │ │ ├── DruidProperties.java
│ │ │ └── RedisProperties.java
│ │ ├── redis
│ │ │ └── CustomRedisManager.java
│ │ ├── runner
│ │ │ └── BlogApplicationRunner.java
│ │ └── tag
│ │ │ └── CustomTagDirective.java
│ │ ├── persistence
│ │ ├── beans
│ │ │ ├── SysResources.java
│ │ │ ├── SysRole.java
│ │ │ ├── SysRoleResources.java
│ │ │ ├── SysUser.java
│ │ │ └── SysUserRole.java
│ │ └── mapper
│ │ │ ├── SysResourceMapper.java
│ │ │ ├── SysRoleMapper.java
│ │ │ ├── SysRoleResourcesMapper.java
│ │ │ ├── SysUserMapper.java
│ │ │ └── SysUserRoleMapper.java
│ │ ├── plugin
│ │ └── BaseMapper.java
│ │ └── util
│ │ ├── AesUtil.java
│ │ ├── IpUtil.java
│ │ ├── Md5Util.java
│ │ ├── PasswordUtil.java
│ │ ├── ResultUtil.java
│ │ └── SessionUtil.java
└── resources
│ └── mybatis
│ ├── SysResourceMapper.xml
│ ├── SysRoleMapper.xml
│ ├── SysUserMapper.xml
│ └── SysUserRoleMapper.xml
└── test
└── java
└── com
└── zyd
└── shiro
├── ListUtilTest.java
└── ShiroCoreApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Java template
3 | # Compiled class file
4 | *.class
5 |
6 | # Log file
7 | *.log
8 |
9 | # BlueJ files
10 | *.ctxt
11 |
12 | # Mobile Tools for Java (J2ME)
13 | .mtj.tmp/
14 |
15 | # Package Files #
16 | *.jar
17 | *.war
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 |
26 | /.idea/
27 | *.iml
28 | */target/
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2018 yadong.zhang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/docs/img/admin-resource.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/admin-resource.PNG
--------------------------------------------------------------------------------
/docs/img/admin-role.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/admin-role.PNG
--------------------------------------------------------------------------------
/docs/img/admin-user.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/admin-user.PNG
--------------------------------------------------------------------------------
/docs/img/db-datasource.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/db-datasource.PNG
--------------------------------------------------------------------------------
/docs/img/db-login.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/db-login.PNG
--------------------------------------------------------------------------------
/docs/img/index.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/index.PNG
--------------------------------------------------------------------------------
/docs/img/login.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/login.PNG
--------------------------------------------------------------------------------
/docs/img/role-role[admin].PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/role-role[admin].PNG
--------------------------------------------------------------------------------
/docs/img/root-resource.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/root-resource.PNG
--------------------------------------------------------------------------------
/docs/img/root-role-[root].PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/root-role-[root].PNG
--------------------------------------------------------------------------------
/docs/img/root-role.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/root-role.PNG
--------------------------------------------------------------------------------
/docs/img/root-user.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/root-user.PNG
--------------------------------------------------------------------------------
/docs/img/root-user[role].PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/root-user[role].PNG
--------------------------------------------------------------------------------
/docs/img/sql-model.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/docs/img/sql-model.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.zyd.shiro
7 | shiro
8 | 0.0.1-SNAPSHOT
9 | pom
10 |
11 |
12 | shiro-core
13 |
14 | shiro-admin
15 |
16 |
17 | shiro
18 | A simpele authority management system
19 | https://github.com/YUbuntu0109/springboot-shiro
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-parent
25 | 2.0.1.RELEASE
26 |
27 |
28 |
29 |
30 | UTF-8
31 | UTF-8
32 | 1.8
33 | true
34 | 1.3.2
35 | 2.1.0
36 | 1.2.3
37 | 1.1.10
38 | 1.2.44
39 | 1.4.0
40 | 2.4.2.1-RELEASE
41 | 0.1
42 |
43 |
44 |
45 |
46 |
47 | org.projectlombok
48 | lombok
49 | true
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-starter-test
55 | test
56 |
57 |
58 | org.springframework.boot
59 | spring-boot-test
60 | 1.4.2.RELEASE
61 | test
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/shiro-admin/.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-admin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | shiro-admin
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | shiro-admin
11 | 后台管理模块
12 |
13 |
14 | com.zyd.shiro
15 | shiro
16 | 0.0.1-SNAPSHOT
17 |
18 |
19 |
20 |
21 | com.zyd.shiro
22 | shiro-core
23 | 0.0.1-SNAPSHOT
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-maven-plugin
32 |
33 | com.zyd.shiro.ShiroAdminApplication
34 | JAR
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/java/com/zyd/shiro/ShiroAdminApplication.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;
21 |
22 | import org.springframework.boot.SpringApplication;
23 | import org.springframework.boot.autoconfigure.SpringBootApplication;
24 |
25 | /**
26 | * 程序启动类
27 | *
28 | * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
29 | * @version 1.0
30 | * @website https://www.zhyd.me
31 | * @date 2018/4/16 16:26
32 | * @since 1.0
33 | */
34 | @SpringBootApplication
35 | public class ShiroAdminApplication {
36 |
37 | public static void main(String[] args) {
38 | SpringApplication.run(ShiroAdminApplication.class, args);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/java/com/zyd/shiro/controller/ExceptionHandleController.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.controller;
21 |
22 | import com.zyd.shiro.business.consts.CommonConst;
23 | import com.zyd.shiro.business.enums.ResponseStatus;
24 | import com.zyd.shiro.framework.exception.ZhydException;
25 | import com.zyd.shiro.framework.object.ResponseVO;
26 | import com.zyd.shiro.util.ResultUtil;
27 | import lombok.extern.slf4j.Slf4j;
28 | import org.springframework.web.bind.annotation.ControllerAdvice;
29 | import org.springframework.web.bind.annotation.ExceptionHandler;
30 | import org.springframework.web.bind.annotation.ResponseBody;
31 |
32 | import java.lang.reflect.UndeclaredThrowableException;
33 |
34 | /**
35 | * @project: springboot-shiro
36 | * @description: 统一异常处理类:捕获程序所有异常,针对不同异常,采取不同的处理方式
37 | * @date: 2019-08-15 7:38 PM
38 | * @version: 1.0
39 | * @website: https://yubuntu0109.github.io/
40 | */
41 | @Slf4j
42 | @ControllerAdvice
43 | public class ExceptionHandleController {
44 |
45 | @ExceptionHandler(value = Exception.class)
46 | @ResponseBody
47 | public ResponseVO handle(Throwable e) {
48 | if (e instanceof ZhydException) {
49 | return ResultUtil.error(e.getMessage());
50 | }
51 | if (e instanceof UndeclaredThrowableException) {
52 | e = ((UndeclaredThrowableException) e).getUndeclaredThrowable();
53 | }
54 | ResponseStatus responseStatus = ResponseStatus.getResponseStatus(e.getMessage());
55 | if (responseStatus != null) {
56 | log.error(responseStatus.getMessage());
57 | return ResultUtil.error(responseStatus.getCode(), responseStatus.getMessage());
58 | }
59 | e.printStackTrace(); //打印异常栈
60 | return ResultUtil.error(CommonConst.DEFAULT_ERROR_CODE, ResponseStatus.ERROR.getMessage());
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/java/com/zyd/shiro/controller/PassportController.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.controller;
21 |
22 | import com.zyd.shiro.framework.object.ResponseVO;
23 | import com.zyd.shiro.util.ResultUtil;
24 | import lombok.extern.slf4j.Slf4j;
25 | import org.apache.shiro.SecurityUtils;
26 | import org.apache.shiro.authc.UsernamePasswordToken;
27 | import org.apache.shiro.subject.Subject;
28 | import org.springframework.stereotype.Controller;
29 | import org.springframework.ui.Model;
30 | import org.springframework.web.bind.annotation.GetMapping;
31 | import org.springframework.web.bind.annotation.PostMapping;
32 | import org.springframework.web.bind.annotation.RequestMapping;
33 | import org.springframework.web.bind.annotation.ResponseBody;
34 | import org.springframework.web.servlet.ModelAndView;
35 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
36 |
37 | /**
38 | * @project: springboot-shiro
39 | * @description: 登录模块的控制器
40 | * @date: 2019-08-15 7:25 PM
41 | * @version: 1.0
42 | * @website: https://yubuntu0109.github.io/
43 | */
44 | @Slf4j
45 | @Controller
46 | @RequestMapping(value = "/passport")
47 | public class PassportController {
48 |
49 | /**
50 | * @description: 跳转到用户登录页
51 | * @param: model
52 | * @date: 2019-08-15 7:26 PM
53 | * @return: org.springframework.web.servlet.ModelAndView
54 | */
55 | @GetMapping("/login")//the parameter is never used
56 | public ModelAndView login(Model model) {
57 | return ResultUtil.view("/login");
58 | }
59 |
60 | /**
61 | * @description: 验证用户登录信息
62 | * @param: username
63 | * @param: password
64 | * @param: rememberMe
65 | * @param: kaptcha
66 | * @date: 2019-08-15 7:26 PM
67 | * @return: com.zyd.shiro.framework.object.ResponseVO
68 | */
69 | @PostMapping("/signin")
70 | @ResponseBody//the parameter of 'kaptcha' is never used
71 | public ResponseVO submitLogin(String username, String password, boolean rememberMe, String kaptcha) {
72 | UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
73 | //获取当前的Subject
74 | Subject currentUser = SecurityUtils.getSubject();
75 | try {
76 | // 在调用了login方法后,SecurityManager会收到AuthenticationToken,并将其发送给已配置的Realm执行必须的认证检查
77 | // 每个Realm都能在必要时对提交的AuthenticationTokens作出反应
78 | // 所以这一步在调用login(token)方法时,它会走到xxRealm.doGetAuthenticationInfo()方法中,具体验证方式详见此方法
79 | currentUser.login(token);
80 | return ResultUtil.success("登录成功!");
81 | } catch (Exception e) {
82 | log.error("登录失败,用户名[{}]", username, e);
83 | token.clear();
84 | return ResultUtil.error(e.getMessage());
85 | }
86 | }
87 |
88 | /**
89 | * @description: 使用权限管理工具完成用户的退出, 跳出登录, 给出提示信息
90 | * @param: redirectAttributes
91 | * @date: 2019-08-15 7:30 PM
92 | * @return: org.springframework.web.servlet.ModelAndView
93 | */
94 | @GetMapping("/logout")
95 | public ModelAndView logout(RedirectAttributes redirectAttributes) {
96 | // 问题: http://www.oschina.net/question/99751_91561
97 | // 解答: 退出登录代码其实不用实现,只需要保留这个接口即可,因为注销功能是由Shiro默认实现的,既而以下用于注销的代码可省略哟
98 | // SecurityUtils.getSubject().logout();
99 | redirectAttributes.addFlashAttribute("message", "您已安全退出");
100 | return ResultUtil.redirect("index");
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/java/com/zyd/shiro/controller/RenderController.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.controller;
21 |
22 | import com.zyd.shiro.util.ResultUtil;
23 | import org.apache.shiro.authz.annotation.RequiresAuthentication;
24 | import org.apache.shiro.authz.annotation.RequiresPermissions;
25 | import org.springframework.stereotype.Controller;
26 | import org.springframework.web.bind.annotation.GetMapping;
27 | import org.springframework.web.servlet.ModelAndView;
28 |
29 | /**
30 | * @project: springboot-shiro
31 | * @description: 控制页面的渲染与跳转
32 | * @date: 2019-08-15 7:21 PM
33 | * @version: 1.0
34 | * @website: https://yubuntu0109.github.io/
35 | */
36 | @Controller
37 | public class RenderController {
38 |
39 | @RequiresAuthentication
40 | @GetMapping(value = {"", "/index"})
41 | public ModelAndView home() {
42 | return ResultUtil.view("index");
43 | }
44 |
45 | @RequiresPermissions("users")
46 | @GetMapping("/users")
47 | public ModelAndView user() {
48 | return ResultUtil.view("user/list");
49 | }
50 |
51 | @RequiresPermissions("resources")
52 | @GetMapping("/resources")
53 | public ModelAndView resources() {
54 | return ResultUtil.view("resources/list");
55 | }
56 |
57 | @RequiresPermissions("roles")
58 | @GetMapping("/roles")
59 | public ModelAndView roles() {
60 | return ResultUtil.view("role/list");
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # Server settings
2 | server:
3 | port: 8080
4 | # HTTP请求和响应头的最大量,以字节为单位,默认值为4096字节,超过此长度的部分不予处理,一般8K. 解决java.io.EOFException: null问题
5 | max-http-header-size: 8192
6 | use-forward-headers: true
7 | compression:
8 | enabled: true
9 | min-response-size: 1024
10 | mime-types: text/plain,text/css,text/xml,text/javascript,application/json,application/javascript,application/xml,application/xml+rss,application/x-javascript,application/x-httpd-php,image/jpeg,image/gif,image/png
11 | tomcat:
12 | remote-ip-header: X-Forwarded-for
13 | protocol-header: X-Forwarded-Proto
14 | port-header: X-Forwarded-Port
15 | uri-encoding: UTF-8
16 | basedir: /var/tmp/website-app
17 | # Spring profiles
18 | spring:
19 | datasource:
20 | type: com.alibaba.druid.pool.DruidDataSource
21 | driver-class-name: com.mysql.jdbc.Driver
22 | url: jdbc:mysql://localhost:3306/shiro?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
23 | username:
24 | password:
25 | application:
26 | name: shiro-admin
27 | freemarker:
28 | allow-request-override: false
29 | allow-session-override: false
30 | cache: false
31 | charset: UTF-8
32 | check-template-location: true
33 | content-type: text/html
34 | enabled: true
35 | expose-request-attributes: false
36 | expose-session-attributes: false
37 | expose-spring-macro-helpers: true
38 | prefer-file-system-access: true
39 | suffix: .ftl
40 | template-loader-path: classpath:/templates/
41 | settings:
42 | template_update_delay: 0
43 | default_encoding: UTF-8
44 | classic_compatible: true
45 | # HTTP ENCODING
46 | http:
47 | multipart:
48 | max-file-size: 2MB
49 | max-request-size: 10MB
50 | encoding:
51 | enabled: true
52 | charset: UTF-8
53 | force: true
54 | messages:
55 | encoding: UTF-8
56 | jmx:
57 | enabled: true
58 | default-domain: agentservice
59 | resources:
60 | chain:
61 | strategy:
62 | content:
63 | enabled: true
64 | paths: /**
65 | # redis缓存服务配置
66 | session:
67 | store-type: redis
68 | # Redis数据库索引(默认为0)
69 | redis:
70 | database: 1
71 | # Redis服务器地址
72 | host: 127.0.0.1
73 | # Redis服务器连接端口
74 | port: 6379
75 | # Redis服务器连接密码(默认为空)
76 | password:
77 | # 连接池最大连接数(使用负值表示没有限制)
78 | pool:
79 | maxActive: 8
80 | # 连接池最大阻塞等待时间(使用负值表示没有限制)
81 | maxWait: -1
82 | # 连接池中的最大空闲连接
83 | maxIdle: 8
84 | # 连接池中的最小空闲连接
85 | minIdle: 0
86 | # 连接超时时间(毫秒)
87 | timeout: 0
88 | # 默认的数据过期时间,主要用于shiro权限管理
89 | expire: 2592000
90 | # MyBatis
91 | mybatis:
92 | type-aliases-package: com.zyd.shiro.persistence.beans
93 | mapper-locations: classpath:/mybatis/*.xml
94 | # Mapper
95 | mapper:
96 | mappers:
97 | - com.zyd.shiro.plugin.BaseMapper
98 | not-empty: false
99 | identity: MYSQL
100 | # PageHelper
101 | pagehelper:
102 | helper-dialect: mysql
103 | reasonable: true
104 | support-methods-arguments: true
105 | params: count=countSql
106 | # Banner
107 | banner:
108 | charset: UTF-8
109 | # 程序自定义配置
110 | zyd:
111 | druid:
112 | # druid访问用户名(默认:zyd-druid)
113 | username: zyd-druid
114 | # druid访问密码(默认:zyd-druid)
115 | password: zyd-druid
116 | # druid访问地址(默认:/druid/*)
117 | servletPath: /druid/*
118 | # 启用重置功能(默认false)
119 | resetEnable: false
120 | # 白名单(非必填), list
121 | allowIps[0]:
122 | # 黑名单(非必填), list
123 | denyIps[0]:
124 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss} [%class:%line] %-5level %logger - %msg%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/static/assets/images/default-portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/shiro-admin/src/main/resources/static/assets/images/default-portrait.png
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/static/assets/images/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/shiro-admin/src/main/resources/static/assets/images/favicon.ico
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/static/assets/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogTech/springboot-shiro/bf64a412bbb242ac3444d02c6a85c3920c7ccf30/shiro-admin/src/main/resources/static/assets/images/loading.gif
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/templates/error/401.ftl:
--------------------------------------------------------------------------------
1 | <#include "/layout/header.ftl"/>
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
401
13 |
无权操作
14 |
您当前无权操作,请联系管理员。
15 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | <#include "/layout/footer.ftl"/>
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/templates/error/403.ftl:
--------------------------------------------------------------------------------
1 | <#include "/layout/header.ftl"/>
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
403
13 |
拒绝访问
14 |
访问此资源需要身份验证。您当前没有权限
15 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | <#include "/layout/footer.ftl"/>
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/templates/error/404.ftl:
--------------------------------------------------------------------------------
1 | <#include "/layout/header.ftl"/>
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
404
13 |
抱歉,我们找不到这个页面
14 |
This page you are looking for does not exist。
15 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | <#include "/layout/footer.ftl"/>
36 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/templates/error/500.ftl:
--------------------------------------------------------------------------------
1 | <#include "/layout/header.ftl"/>
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
500
13 |
内部服务器错误
14 |
我们会自动跟踪这些错误,但如果问题仍然存在,请随时联系我们。同时,您可以尝试重试。
15 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | <#include "/layout/footer.ftl"/>
36 |
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/templates/index.ftl:
--------------------------------------------------------------------------------
1 | <#include "layout/header.ftl"/>
2 |
3 |
4 |
5 |
6 |
欢迎光临
7 | Shiro权限管理后台
8 |
9 |
10 |
11 |
12 |
13 |
14 |
18 |
19 |
20 | -
21 |
22 |
25 |
26 |
拥抱该项目~ 提高代码可读性ing
27 |
28 |
Stay hungray, Stay foolish. -- Steve Jobs
29 |
30 |
31 |
32 | -
33 |
34 |
37 |
38 |
添加Druid监控
39 |
40 |
Talk is cheap, show me the code. -- Linus Torvalds
41 |
42 |
43 |
44 | -
45 |
46 |
49 |
50 |
完善代码、流程,测试角色权限
51 |
52 |
Talk is cheap, show me the code. -- Linus Torvalds
53 |
54 |
55 |
56 | -
57 |
58 |
61 |
62 |
项目提交到Gitee
63 |
64 |
初次提交
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | <#include "layout/footer.ftl"/>
--------------------------------------------------------------------------------
/shiro-admin/src/main/resources/templates/layout/footer.ftl:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |