来自: http://m.oschina.net/blog/92003

1、applicationContext-shiro.xml配置:实现认证和授权

   <!-- shiro start -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManagerConfigFile"
value="classpath:ehcache.xml" />
</bean>
<bean id="credentialsMatcher"
class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<property name="hashAlgorithmName" value="SHA-256" />
</bean>
<bean id="iniRealm" class="com.boonya.shiro.security.CurrentIniRealm">
<constructor-arg type="java.lang.String" value="classpath:shiro.ini" />
<property name="credentialsMatcher" ref="credentialsMatcher" />
</bean>
<bean id="userRealm" class="com.boonya.shiro.security.UserRealm" />
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realms">
<list>
<ref bean="iniRealm" />
<ref bean="userRealm" />
</list>
</property>
<property name="cacheManager" ref="cacheManager" />
</bean>
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/login" />
<property name="successUrl" value="/maps/main.html"></property>
<property name="unauthorizedUrl" value="/unauthorized"></property>
<property name="filters">
<util:map>
<entry key="anAlias">
<bean
class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" />
</entry>
</util:map>
</property>
<property name="filterChainDefinitions">
<value>
/unauthorized=anon
/validate/code*=anon
/login/**=anon
/image/**=anon
/js/**=anon
/css/**=anon
/common/**=anon
/index.htm* = anon
/maps/**=authc
</value>
</property>
</bean>
<!-- shiro end -->说明:红色字体部分是对用户操作的URL进行过滤:认证或授权

2、shiro过滤器过滤属性含义

securityManager:这个属性是必须的。

loginUrl :没有登录的用户请求需要登录的页面时自动跳转到登录页面,不是必须的属性,不输入地址的话会自动寻找项目web项目的根目录下的”/login.jsp”页面。

successUrl :登录成功默认跳转页面,不配置则跳转至”/”。如果登陆前点击的一个需要登录的页面,则在登录自动跳转到那个需要登录的页面。不跳转到此。

unauthorizedUrl :没有权限默认跳转的页面。

===============其权限过滤器及配置释义=======================

anon   org.apache.shiro.web.filter.authc.AnonymousFilter

authc  org.apache.shiro.web.filter.authc.FormAuthenticationFilter

authcBasic org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter

perms  org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter

port   org.apache.shiro.web.filter.authz.PortFilter

rest   org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter

roles  org.apache.shiro.web.filter.authz.RolesAuthorizationFilter

ssl    org.apache.shiro.web.filter.authz.SslFilter

user   org.apache.shiro.web.filter.authc.UserFilter

logout org.apache.shiro.web.filter.authc.LogoutFilter

anon:例子/admins/**=anon 没有参数,表示可以匿名使用。

authc:例如/admins/user/**=authc表示需要认证(登录)才能使用,没有参数

roles:例子/admins/user/**=roles[admin],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,例如admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。

perms:例子/admins/user/**=perms[user:add:*],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,例如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。

rest:例子/admins/user/**=rest[user],根据请求的方法,相当于/admins/user/**=perms[user:method] ,其中method为post,get,delete等。

port:例子/admins/user/**=port[8081],当请求的url的端口不是8081是跳转到schemal://serverName:8081?queryString,其中schmal是协议http或https等,serverName是你访问的host,8081是url配置里port的端口,queryString

是你访问的url里的?后面的参数。

authcBasic:例如/admins/user/**=authcBasic没有参数表示httpBasic认证

ssl:例子/admins/user/**=ssl没有参数,表示安全的url请求,协议为https

user:例如/admins/user/**=user没有参数表示必须存在用户,当登入操作时不做检查

注:anon,authcBasic,auchc,user是认证过滤器,

perms,roles,ssl,rest,port是授权过滤器

3、web.xml中shiroFilter配置

<!-- Shiro Filter is defined in the spring application context: -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Shiro--权限控制的更多相关文章

  1. shiro权限控制入门

    一:权限控制两种主要方式 粗粒度 URL 级别权限控制和细粒度方法级别权限控制 1.粗粒度 URL 级别权限控制 可以基于 Filter 实现在数据库中存放 用户.权限.访问 URL 对应关系, 当前 ...

  2. shiro权限控制的简单实现

    权限控制常用的有shiro.spring security,两者相比较,各有优缺点,此篇文章以shiro为例,实现系统的权限控制. 一.数据库的设计 简单的五张表,用户.角色.权限及关联表: CREA ...

  3. Spring boot后台搭建二为Shiro权限控制添加缓存

    在添加权限控制后,添加方法 查看 当用户访问”获取用户信息”.”新增用户”和”删除用户”的时,后台输出打印如下信息 , Druid数据源SQL监控 为了避免频繁访问数据库获取权限信息,在Shiro中加 ...

  4. Spring boot后台搭建二集成Shiro权限控制

    上一篇文章,实现了用户验证 查看,接下来实现下权限控制 权限控制,是管理资源访问的过程,用于对用户进行的操作授权,证明该用户是否允许进行当前操作,如访问某个链接,某个资源文件等 Apache Shir ...

  5. shiro权限控制配置

    shiro配置流程 web.xml中配置shiro的filter spring中配置shiro的过滤器工厂,指定对不同地址权限控制 , 传入安全管理器 配置安全管理器,传入realm,realm中定义 ...

  6. Shiro权限控制框架

    Subject:主体,可以看到主体可以是任何可以与应用交互的"用户": SecurityManager:相当于SpringMVC中的DispatcherServlet或者Strut ...

  7. shiro权限控制

    1.1  简介 Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Securi ...

  8. JFinal配合Shiro权限控制在FreeMarker模板引擎中控制到按钮粒度的使用

    实现在FreeMarker模板中控制对应按钮的显示隐藏主要用到了Shiro中的hasRole, hasAnyRoles, hasPermission以及Authenticated等方法,我们可以实现T ...

  9. shiro权限控制(一):shiro介绍以及整合SSM框架

    shiro安全框架是目前为止作为登录注册最常用的框架,因为它十分的强大简单,提供了认证.授权.加密和会话管理等功能 . shiro能做什么? 认证:验证用户的身份 授权:对用户执行访问控制:判断用户是 ...

  10. Maven配置Spring+Hibernate Shiro权限控制项目

    前言:在Eclipse中安装好Maven插件,然后创建一个Sample项目.在Eclipse中检出Shiro的官方演示样例.地址http://svn.apache.org/repos/asf/shir ...

随机推荐

  1. 4Web镇之旅:开始链接

    为了将网页发布到web上,需要一个全日工作的网络服务器,最好的方法是找到一家主机代理商. 域名是用来定位网站的第一无二的名字. 网页的最顶层目录就是根目录.在Web服务器中,因为根目录中的东西有可能在 ...

  2. 让Storm插上CEP的翅膀 - Siddhi调研和集成

    什么是 Siddhi? Siddhi 是一种 lightweight, easy-to-use, open source CEP(Complex Event Processing)引擎,由wso2公司 ...

  3. Oracle数值处理函数 (绝对值、取整...)

    1.绝对值:abs()    select abs(-2) value from dual; 2.取整函数(大):ceil()    select ceil(-2.001) value from du ...

  4. C 判断路径存在

    1   用   int   access(const   char   *pathname,   int   mode);   判断有没有此文件或目录 --它区别不出这是文件还是目录2   用   i ...

  5. 【转】设计模式 ( 十八 ) 策略模式Strategy(对象行为型)

    设计模式 ( 十八 ) 策略模式Strategy(对象行为型) 1.概述 在软件开发中也常常遇到类似的情况,实现某一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成 ...

  6. 深入了解Windows句柄到底是什么

    深入了解Windows句柄到底是什么 http://blog.csdn.net/wenzhou1219/article/details/17659485 总是有新入门的Windows程序员问我Wind ...

  7. Reactor 与 Proactor

    一.五种IO Model blocking IO nonblocking IO IO multiplexing signal driven IO(不常用) asynchronous IO 对于一个ne ...

  8. Celery - Best Practices

    If you've worked with Django at some point you probably had the need for some background processing ...

  9. Subset---poj3977(折半枚举+二分查找)

    题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]| ...

  10. hdu1231最大连续子序列

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1231 #include<iostream> #include<cstdio> ...