我的JAVA

          我的門戶
          隨筆 - 5, 文章 - 0, 評論 - 2, 引用 - 0
          數(shù)據(jù)加載中……

          2010年2月23日

          Acegi 配置指南(4)

          認(rèn)證模式配置(二)

          表單認(rèn)證

          表單認(rèn)證利用開發(fā)者開發(fā)的登錄頁面搜集用戶名和密碼,下面是登錄頁面的基本代碼:

          <form action="j_acegi_security_check" method="post">

              用戶名:<input name="j_username"><br>

              密 碼:<input name="j_password" type="password"><br>

              14天之內(nèi)免登錄<input name="_acegi_security_remember_me" type="checkbox"><br>

              <input type="submit" value="登錄">

          </form>

          同時,還加入了退出、免登錄和匿名三個過濾器。

          代碼:

          <!-- 退出過濾器 -->

          <bean id="logoutFilter" class="org.acegisecurity.ui.logout.LogoutFilter">

              <constructor-arg value="/index.jsp" />

              <constructor-arg>

                 <list>

                     <ref local="rememberMeServices" />

                     <ref local="securityContextLogoutHandler" />

                 </list>

              </constructor-arg>

          </bean>

          <!-- 安全上下文退出句柄 -->

          <bean id="securityContextLogoutHandler" class="org.acegisecurity.ui.logout.SecurityContextLogoutHandler">

              <property name="invalidateHttpSession" value="true" />

          </bean>

          <!-- ================

                  認(rèn)證部分

               ================ -->

          <!-- 表單認(rèn)證過濾器 -->

          <bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">

              <property name="authenticationManager" ref="authenticationManager" />

              <property name="authenticationFailureUrl" value="/login.jsp?error=1" />

              <property name="defaultTargetUrl" value="/" />

              <property name="alwaysUseDefaultTargetUrl" value="true" />

              <property name="filterProcessesUrl" value="/j_acegi_security_check" />

              <property name="rememberMeServices" ref="rememberMeServices" />

          </bean>

          <!-- 認(rèn)證管理器 -->

          <bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">

              <property name="providers">

                 <list>

                     <ref local="daoAuthenticationProvider" />

                     <ref local="anonymousAuthenticationProvider" />

                     <ref local="rememberMeAuthenticationProvider" />

                 </list>

              </property>

          </bean>

          <!-- DAO認(rèn)證源提供者 -->

          <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">

              <property name="userDetailsService" ref="inMemDaoImpl" />

          </bean>

          <!-- 用戶信息源(內(nèi)存) -->

          <bean id="inMemDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">

              <property name="userMap">

                 <value>

                     admin=password,ROLE_ADMIN,ROLE_USER

                     user1=password,ROLE_USER

                 </value>

              </property>

          </bean>

          <!-- 免登錄認(rèn)證過濾器 -->

          <bean id="rememberMeProcessingFilter" class="org.acegisecurity.ui.rememberme.RememberMeProcessingFilter">

              <property name="authenticationManager" ref="authenticationManager" />

              <property name="rememberMeServices" ref="rememberMeServices"></property>

          </bean>

          <!-- 免登錄服務(wù) -->

          <bean id="rememberMeServices" class="org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices">

              <property name="userDetailsService" ref="inMemDaoImpl" />

              <property name="key" value="springRocks" />

              <property name="tokenValiditySeconds" value="1209600" />

              <property name="parameter" value="_acegi_security_remember_me" />

              <property name="cookieName" value="ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE" />

              <!--

              <property name="alwaysRemember" value="true" />

               -->

          </bean>

          <!-- 免登錄認(rèn)證源提供者 -->

          <bean id="rememberMeAuthenticationProvider" class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider">

              <property name="key" value="springRocks" />

          </bean>

          <!-- 匿名認(rèn)證過濾器 -->

          <bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter">

              <property name="key" value="foobar" />

              <property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS" />

          </bean>

          <!-- 匿名認(rèn)證源提供者 -->

          <bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">

              <property name="key" value="foobar" />

          </bean>

          <!-- 異常處理過濾器 -->

          <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">

              <property name="authenticationEntryPoint" ref="authenticationProcessingFilterEntryPoint" />

              <property name="accessDeniedHandler" ref="accessDeniedHandlerImpl" />

          </bean>

          <!-- 表單認(rèn)證入口點 -->

          <bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">

              <property name="loginFormUrl" value="/login.jsp" />

              <property name="forceHttps" value="false" />

              <property name="serverSideRedirect" value="false" />

          </bean>

          <!-- 授權(quán)拒絕句柄 -->

          <bean id="accessDeniedHandlerImpl" class="org.acegisecurity.ui.AccessDeniedHandlerImpl">

              <property name="errorPage" value="/accessDenied.jsp" />

          </bean>

          說明:

          在基本認(rèn)證過濾器之前加入退出過濾器,之后加入免登錄過濾器和匿名過濾器。參數(shù):

          Bean

          參數(shù)

          描述

          logoutFilter
          退出過濾器

          構(gòu)造參數(shù)1

          指定退出后的重定向url

          構(gòu)造參數(shù)2

          指派退出的執(zhí)行句柄,多值

          退出免登錄服務(wù)

          退出安全上下文

          securityContextLogoutHandler
          安全上下文退出句柄

          invalidateHttpSession

          是否讓HTTP會話失效

          authenticationProcessingFilter
          基本認(rèn)證過濾器

          authenticationManager

          指派認(rèn)證管理器

          authenticationFailureUrl

          認(rèn)證失敗的URL

          defaultTargetUrl

          認(rèn)證成功之后的缺省URL。兩種情況下使用:1. 用戶直接進入登錄頁;2. alwaysUseDefaultTargetUrl設(shè)為true。(一般情況是用戶進入受保護頁時,acegi會先跳轉(zhuǎn)到登錄頁,認(rèn)證成功之后再跳轉(zhuǎn)到用戶要訪問的頁面。如果用戶直接進入登錄頁,認(rèn)證成功之后acegi不知道用戶要訪問的頁面是什么時,采用該值。)

          alwaysUseDefaultTargetUrl

          是否無論用戶要訪問的頁面是什么,認(rèn)證成功之后都跳轉(zhuǎn)到defaultTargetUrl

          filterProcessesUrl

          表單提交的Action,默認(rèn)值為
          /j_acegi_security_check

          rememberMeServices

          指派免登錄服務(wù)

          authenticationManager
          認(rèn)證管理器

          providers

          指派認(rèn)證源提供者,多值

          DAO認(rèn)證源提供者

          免登錄認(rèn)證源提供者

          匿名認(rèn)證源提供者

          daoAuthenticationProvider
          DAO
          認(rèn)證源提供者

          userDetailsService

          指派用戶信息源

          inMemDaoImpl
          用戶信息源(內(nèi)存)

          userMap

          用戶信息

          rememberMeProcessingFilter

          免登錄過濾器

          authenticationManager

          指派認(rèn)證管理器

          rememberMeServices

          指派免登錄服務(wù)

          rememberMeServices

          免登錄服務(wù)

          userDetailsService

          指派用戶信息源

          key

          指定密鑰

          tokenValiditySeconds

          免登錄的時間段,單位為秒,缺省值為1209600,合14

          parameter

          在登錄表單中提交的參數(shù)名,acegi依據(jù)當(dāng)前值判斷用戶是否需要免登錄服務(wù),缺省值為:
          _acegi_security_remember_me

          cookieName

          保存在瀏覽器的Cookie名,acegi依據(jù)cookie值完成自動登錄,達到用戶免登錄目的,缺省值為:
          ACEGI_SECURITY_HASHED_
          REMEMBER_ME_COOKIE

          alwaysRemember

          是否自動提供免登錄服務(wù),將該參數(shù)設(shè)為true時,無論用戶是否選擇都提供免登錄服務(wù),設(shè)為true時會覆蓋parameter的作用。(一般在HTTP基本認(rèn)證時采用,表單認(rèn)證時不用)

          rememberMeAuthenticationProvider

          免登錄認(rèn)證源提供者

          key

          指定密鑰,和免登錄服務(wù)的密鑰保持一致

          anonymousProcessingFilter

          匿名過濾器

          userAttribute

          指定匿名登錄的用戶和角色,格式:

          uid,role

          key

          指定密鑰

          anonymousAuthenticationProvider
          匿名認(rèn)證源提供者

          key

          指定密鑰,和匿名過濾器的密鑰保持一致

          exceptionTranslationFilter
          異常處理過濾器

          authenticationEntryPoint

          指派認(rèn)證入口點

          accessDeniedHandler

          指派授權(quán)拒絕處理器

          authenticationProcessingFilterEntryPoint
          表單認(rèn)證入口點

          loginFormUrl

          指定登錄頁面,如:/login.jsp

          forceHttps

          是否強制使用https協(xié)議

          serverSideRedirect

          是否采用WEB服務(wù)器內(nèi)部跳轉(zhuǎn)到登錄頁面

          accessDeniedHandlerImpl
          授權(quán)拒絕處理器

          errorPage

          訪問無權(quán)限的頁面時,acegi跳轉(zhuǎn)的錯誤頁面

           Spring Bean關(guān)系圖:


          說明:每個圖塊為一個Spring Bean斜體Bean和同名正體Bean為同一個Bean

          問題:

          在表單認(rèn)證下,加入了“退出”之后,是可以退出Acegi安全上下文的。因此之前HTTP基本認(rèn)證不能退出可能是Acegi的一個BUG

          posted @ 2010-02-25 18:02 xuyang 閱讀(1937) | 評論 (2)編輯 收藏

          Acegi配置指南(3)

               摘要: v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} Normal 0 false 7.8 磅 0 2 false ...  閱讀全文

          posted @ 2010-02-23 13:53 xuyang 閱讀(512) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 凤翔县| 南城县| 隆昌县| 博白县| 阿尔山市| 桦甸市| 富蕴县| 莱州市| 新津县| 镇赉县| 丰原市| 石棉县| 延庆县| 仙居县| 夏邑县| 沾化县| 乐至县| 夏河县| 科技| 财经| 金塔县| 历史| 大理市| 泾川县| 荣昌县| 青川县| 延吉市| 新河县| 甘孜县| 二连浩特市| 潜山县| 隆尧县| 贵德县| 德兴市| 湾仔区| 高淳县| 北川| 瑞安市| 蒙阴县| 西昌市| 镇坪县|