Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

ReadMe.md

Outline

说明文档

环境介绍

Spring+SpringMVC+Mybatis+MySQL+Shiro+Maven

运行过程

1.用eclipse导入

应该可以看到如下目录结构:

2.执行SQL脚本

SQL脚本位于webapp->WEB-INF->sql下,该脚本在MySQL5.7上测试通过。 主要有五张表:

由用户、角色和权限之间的关系不难得出这五张表。

3.修改项目配置

要修改的主要是jdbc的连接配置,将jdbc.properties对应的属性修改成你本机的属性即可:

4.确保Maven已导入相关依赖


项目演示

为方便演示,sql脚本中已有相应数据:

有两个用户:admin和user

admin的role为admin,user的role为user

role["admin"]具有user:view,user:create,user:update,user:delete四种权限

role["user"]只拥有user:view的权限

Shiro的核心配置如下:

接下来进行测试,启动项目,在浏览器中输入:

由于/index配置了authc过滤器,因此用户在未认证之前会跳到loginUrl,也就是http://localhost:8080/cg/login进行认证:

输入正确的用户名跟密码(user/123456)后登录成功,再输入http://localhost:8080/cg/index,正常进入页面:

此时用户role为user,拥有的权限为user:view,输入:http://localhost:8080/cg/index2,http://localhost:8080/cg/user, 都可以正常访问,而http://localhost:8080/cg/admin则不能访问,由于用户已经登录,所以会跳到unauthorizedUrl即http://localhost:8080/cg/unauthorized,如图:

注销:http://localhost:8080/cg/logout 之后会跳到登录页面,换成admin/123456登录再验证如上url。

Morty Proxy This is a proxified and sanitized view of the page, visit original site.