shiro 验证码 配置

shiro结合spring进行权限管理,项目还未上线,权限系统还未开启,先把用到的验证码和登录过滤部分功能记录一下html

验证码是否开启:web

    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager" >
        <property name="realm" ref="shiroDbRealm" />
        <property name="cacheManager" ref="shiroEhcacheManager" />
    </bean>

<!--     <bean id="userServiceImpl" class="com.joloplay.security.service.impl.UserServiceImpl"></bean> -->
<!--     <bean id="userRoleServiceImpl" class="com.joloplay.security.service.impl.UserRoleServiceImpl"></bean> -->
<!-- Spring Data Jpa配置 -->
   
    
    <bean id="shiroDbRealm" class="com.joloplay.security.shiro.ShiroDbRealm"  depends-on="securityUserDao,userRoleDao">
        <property name="userService" ref="userServiceImpl"/>
        <property name="userRoleService" ref="userRoleServiceImpl"/>
        <property name="useCaptcha" value="true"/>
    </bean>

修改下面的bean中的 "useCaptcha"属性的value值便可,TRUE为开启验证码,FALSE为不开启。spring

 

2.经过配置,使相应的请求跳过登录过滤器:apache

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager" />
        <property name="loginUrl" value="/login.do" />
        <property name="successUrl" value="/ui/index.do" />
        <property name="filters">
            <map>         
<!--                 <entry key="authc" value-ref="baseFormAuthenticationFilter"/> -->
<!--                 是否启用验证码检验 -->
                <entry key="authc" value-ref="captchaFormAuthenticationFilter"/>
            </map>
        </property>
        <property name="filterChainDefinitions">
            <value>
                /sdkData/*.do =anon
                /infoFee/*.do =anon
                /Captcha.jpg = anon
                /include/** = anon
                /login/timeout = anon
                /login.do = authc
                /logout = logout
                /ui/*.do = user
                /ui/index/*.do = user
                /ui/** = anon
                /*.jsp = anon
                /*.html = anon
                /** = user
             </value>
        </property>
    </bean>

只须要在filterChainDefinetions属性中,将请求的URL列出便可,设置为anon,即实现不登录就可访问的效果。jsp

shiro的权限控制仍是比较强大的,配置比较简单,有空得好好学学--ui

相关文章
相关标签/搜索