shiro权限控制
来源:互联网 发布:linux服务器安装vnc 编辑:程序博客网 时间:2024/06/05 12:44
shiro 是一个权限管理框架,可以用来做权限的管理与控制,这个shiro框架可以对权限做控制,他的权限管理,大到role,小到权限,在权限控制上,可以通过shiro标记做资源权限管理。
简单记录一下这个shiro的使用:自身是做web的,所以就说shiro在web中的使用。在web.xml中加shiro过滤器:
<!-- apache shiro权限 -->
<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>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
这个是说过滤.jsp和.do的请求。
在applicationContext.xml中:
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/login.jsp" />
<property name="successUrl" value="/login.jsp" />
<property name="unauthorizedUrl" value="/error/noperms.jsp" />
<property name="filterChainDefinitions">
<value>
/login.jsp* = anon
/login.do* = anon
/index.jsp*= anon
/error/noperms.jsp*= anon
/*.jsp* = authc
/*.do* = authc
</value>
</property>
</bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--设置自定义realm -->
<property name="realm" ref="monitorRealm" />
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<!--自定义Realm 继承自AuthorizingRealm -->
<bean id="monitorRealm" class="com.ha.shiro.MonitorRealm"></bean>
<!-- securityManager -->
<bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod"
value="org.apache.shiro.SecurityUtils.setSecurityManager" />
<property name="arguments" ref="securityManager" />
</bean>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after -->
<!-- the lifecycleBeanProcessor has run: -->
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
这样就配好了:
还要自定义一个realm:
这个realm要继承AuthorizingRealm,重写:doGetAuthorizationInfo和doGetAuthenticationInfo。
doGetAuthorizationInfo这个是获取权限和角色。
doGetAuthenticationInfo是做登录验证,登录验证的方法:subject.login()这个就是用这个方法来检验的。
- shiro、SpringMVC权限控制
- shiro、SpringMVC权限控制
- shiro权限控制
- 权限控制框架 shiro
- Shiro 权限控制框架
- Apache Shiro 权限控制
- shiro权限控制
- Shiro 权限控制
- shiro权限控制
- Shiro进行权限控制
- 权限控制框架-shiro
- shiro-权限控制框架
- 权限控制框架-shiro
- 权限控制框架-shiro
- 权限控制框架-shiro
- 权限控制框架-shiro
- Apache Shiro权限控制实战,权限控制SpringMVC + Mybatis + Shiro
- Apache Shiro权限控制实战,权限控制SpringMVC + Mybatis + Shiro
- Arcgis+ArcEngine+Java开发软件安装配置问题
- javascript中的后退和刷新
- MFC-缩放位图
- js--面向对象--原型链
- django访问数据库出错 OperationalError: attempt to write a readonly database
- shiro权限控制
- 欢迎使用CSDN-markdown编辑器
- Delphi中TStringList类常用属性方法详解
- ACM程序设计选修课——1041: XX's easy problem(神烦的多次字符串重定向处理)
- PHPStorm安装与破解
- JZOJ4419. 【GDOI2016模拟4.2】hole
- java jdbc如何使用
- TCP KeepAlive
- android查看源码的时候看不了