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

相關文章
相關標籤/搜索