Shiro实现用户授权(Authorization)
来源:互联网 发布:常见网络中间设备 编辑:程序博客网 时间:2024/05/16 08:21
1.表结构
2.Controller
// 判断是否成功登录 assertEquals(true, subject.isAuthenticated()); System.out.println("登录成功!!"); // 判断用户是否拥有某个角色 assertEquals(true, subject.hasRole("admin")); // 使用Shiro自带的断言判断用户是否有被授权 subject.checkRole("manager"); subject.checkPermission("create_user1"); // 注销用户 subject.logout();
3.Spring-dao.xml配置
<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm"> <!--<property name="credentialsMatcher" ref="credentialsMatcher"></property>--> <property name="permissionsLookupEnabled" value="true"></property> <property name="dataSource" ref="dataSource"></property> <property name="authenticationQuery" value="SELECT password FROM users WHERE username = ?"></property> <property name="userRolesQuery" value="SELECT permission FROM roles_permissions WHERE role_name = ? " /> </bean>
4.web.xml
<!-- Shiro Filter --> <filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>shiroFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
5.总结
之后在应用程序任意地方调用SecurityUtils.getSubject() 都可以获取到当前认证通过的用户实例
这就意味着在判断请求时可以方便的进行操作
博客:
http://www.cnblogs.com/xql4j/
http://kdboy.iteye.com/blog/1155450
http://blog.csdn.net/chris_mao/article/details/49215471
0 0
- Shiro实现用户授权(Authorization)
- Shiro系列之Shiro+Mysql实现用户授权(Authorization)
- Shiro笔记(五)----授权(Authorization)
- 5、Shiro+Oracle实现用户授权(Authentication)
- 第五章:Shiro的授权(Authorization)
- shiro学习:shiro实现授权
- Spring Shiro配置实现用户认证和授权
- Spring Shiro配置实现用户认证和授权
- Spring Shiro配置实现用户认证和授权
- Shiro学习笔记(3)——授权(Authorization)
- Shiro 授权实现
- shiro authorizingrealm实现认证授权
- Shiro实现用户登录
- 实现OAuth2.0服务端【授权码模式(Authorization Code)】
- shiro实现授权的三种操作
- shiro实现基于角色的权限授权
- Shiro认证授权业务软件实现流程
- shiro授权
- 2016SDAU编程练习二1017
- Linux系统设置及基本操作
- 快速排序
- 关于C++的getline换行符的问题
- 动态分配空间
- Shiro实现用户授权(Authorization)
- 分拣存储2-统计学生每个班级的总分和平均分
- 2016SDAU编程练习二1019
- stm32+lwip的物联网开发——学习过程(1)
- 分类算法-决策树之:id3 算法
- Android驱动程序编写过程记录
- TextView maxWidth maxLength maxEms 区别
- 类的初识与构造函数
- Mybatis的延迟加载