Shiro框架配置-applicationContext里面的(仅提供借鉴)

<!-- 配置自定义realm -->
<bean id="shiroAuthRealm" class="com.sykj.realm.ShiroAuthRealm">
<!-- 配置加密 -->
<property name="credentialsMatcher">
<bean class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<property name="hashAlgorithmName" value="MD5"></property> <!-- 加密算法的名称 -->
<property name="hashIterations" value="1024"></property> <!-- 配置加密的次数 -->
</bean>
</property>
</bean>

<!-- 配置安全管理器 -->
<!-- shiro的核心组件:securityManager -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- 配置缓存 -->
<property name="cacheManager" ref="cacheManager" />
<!-- 配置域realm,用户名,密码,角色都保存在域里,完成登录校验、权限校验的自定义JAVA类 -->
<property name="realm" ref="shiroAuthRealm" /> <!-- 步骤4中配置的bean id -->
</bean>

<!-- 配置拦截规则 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login.html"/>
<property name="successUrl" value="/succes.html"/>
<property name="unauthorizedUrl" value="/unauth.html"/>
<!-- 拦截规则 -->
<property name="filterChainDefinitions">
<value>
/login.html = anon <!-- anon 匿名访问 不登录允许访问-->
/account/login = anon
/** = authc <!-- authc 授权访问(必须登录后才能访问) -->

<!-- roles[角色名] 权限的控制 -->

/account/queryall=roles[admin]   
</value>
</property>
</bean>

猜你喜欢

转载自www.cnblogs.com/lqh-haodi/p/10768307.html