shiro学习笔记(2)-添加maven依赖以及与spring的整合

一、在maven中添加shiro的依赖

  

        <dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-all</artifactId>
			<version>1.2.2</version>
		</dependency>

这里使用的是1.2.2版本的shiro框架

 

二、在web.xml中配置shiro框架的过滤器,注意要将其配置在struts2的过滤器前

  <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>

三、在applicationContext.xml中配置shiroFilter的<bean>

  

    <!-- 配置shiro框架 的过滤器工厂对象-->
		<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
			<!-- 注入安全管理器对象 -->
			<property name="securityManager" ref="securityManager"></property>
			<!-- 注入相关页面访问URL -->
			<property name="loginUrl" value="/login.jsp"/>
			<property name="successUrl" value="/index.jsp"/>
			<property name="unauthorizedUrl" value="/unauthorized.jsp"/>
			<!--注入URL拦截规则 -->
			<property name="filterChainDefinitions">
				<value>
					/css/** = anon
					/js/** = anon
					/images/** = anon
					/validatecode.jsp* = anon
					/login.jsp = anon
					/userAction_login.action = anon
					/page_base_staff.action = perms["staff-list"]
					/* = authc
				</value>
			</property>
		</bean>

loginUrl为在未登陆时,需要跳转到的登陆页面,successUrl为在登陆后进入的页面,unauthorizedUrl为未授权时显示的页面

过滤器简称:

过滤器简称

对应的java类

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表示可以匿名使用,无需校验权限

authc表示需要校验权限

perms["staff-list"]表示需要有"staff-list"这个权限才能查看

 

四、在applicationContext.xml中配置安全管理器

<!-- 注册安全管理器 -->
		<bean id="securityManager"           class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
			<property name="realm" ref="bosRealm"></property>
		</bean>

 

五、在applicationContext.xml中配置realm数据桥梁

<!-- 注册realm -->
		<bean id="bosRealm" class="com.iteason.realm.BOSRealm"></bean>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BoringRong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值