spring-shiro 安全框架配置

<!--创建自定义域对象-->
<bean id="authRealm" class="com.aaa.ssm.shiro.AuthRealm">
<property name="credentialsMatcher" ref="credentialsMatcher"></property>
</bean>

<!--创建凭证匹配器对象-->
<bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<!--指定要对用户传过来的明文密码进行什么加密-->
<property name="hashAlgorithmName" value="md5"></property>
<!--指明hash迭代的次数-->
<property name="hashIterations" value="5"></property>
</bean>


<!--创建会话管理器对象-->
<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<!--配置session的超时时间 单位毫秒-->
<property name="globalSessionTimeout" value="1800000"></property>
</bean>

<!--创建shiro安全管理器对象-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--声明域,在域中读取认证和授权的数据-->
<property name="realm" ref="authRealm"></property>
<!--声明会话管理器属性-->
<property name="sessionManager" ref="sessionManager"></property>
</bean>

<!--创建shiro的过滤器对象-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!--要注入安全管理器对象-->
<property name="securityManager" ref="securityManager"></property>
<!--配置登陆请求的路径-->
<property name="loginUrl" value="user/toLogin.do"></property>
<!--如果用户没有授权跳转到错误页面-->
<property name="unauthorizedUrl" value="../error.jsp"></property>
<!--配置shiro认证和授权的过滤器-->
<property name="filterChainDefinitions">
<value>
<!--对静态资源不拦截 anon指匿名访问的过滤器-->
/static/*=anon
/user/login.do=anon
/user/toLogin.do=anon
/user/register.do=anon
/login.jsp=anon
/user/index.do=anon
/register.jsp=anon
<!--配置登出请求的过滤器-->
/user/logout.do=logout
<!--配置/user/list.do必须要有user的权限才能访问-->
/user/*.do=perms[user]
<!--authc指必须经过认证(登录过之后)才能访问的请求-->
/**=authc
/*/*=authc
</value>
</property>
</bean>

猜你喜欢

转载自www.cnblogs.com/LFY001023/p/11049305.html