<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    javajohn

    金色年華

    acegi源碼學(xué)習(xí)之用戶(hù)登錄篇

    acegi 源碼學(xué)習(xí)之用戶(hù)登錄篇

    一、查看 applicationContext-acegi-security.xml 配置文件,涉及到登錄的配置為:

    ?1

    < bean id = "authenticationProcessingFilter" class = "org.javajohn.test.plugins.security.UserAuthenticationProcessingFilter" >

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

    ??????? < property name = "authenticationFailureUrl" >

    ??????????? < value > /login.jsp?login_error=1 </ value >

    ??????? </ property >

    ??????? < property name = "defaultTargetUrl" >

    ??????????? < value > /index.jsp </ value >

    ??????? </ property >

    ??????? < property name = "filterProcessesUrl" >

    ??????????? < value > /j_acegi_security_check </ value >

    ??????? </ property >

    ??????? < property name = "userManager" ref = "userManager" />

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

    ??????? < property name = "exceptionMappings" >

    ??????????? < value >

    ??????????????? org.acegisecurity.AuthenticationException=/login.jsp?login_error=user_psw_error

    ??????????????? org.acegisecurity.concurrent.ConcurrentLoginException=/login.jsp?login_error=too_many_user_error

    ??????? ???? </ value >

    ??????? </ property >

    </ bean >

    ?

    ?

    2 < bean id = "authenticationManager"

    ?????? class = "org.acegisecurity.providers.ProviderManager" >

    ?????? < property name = "providers" >

    ?????????? < list >

    ????????????? < ref local = "daoAuthenticationProvider" />

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

    ????????????????? < property name = "key" value = "javajohnKey" />

    ????????????? </ bean >

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

    ????????????????? < property name = "key" value = "javajohnKey" />

    ????????????? </ bean >

    ?????????? </ list >

    ?????? </ property > ??

    ??? </ bean >

    ?

    3

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

    ?????? < property name = "userDetailsService" ref = "jdbcDaoImpl" />

    ?????? < property name = "userCache" >

    ?????????? < bean class = "org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache" >

    ????????????? < property name = "cache" >

    ????????????????? < bean class = "org.springframework.cache.ehcache.EhCacheFactoryBean" >

    ???????????????????? < property name = "cacheManager" >

    ???????????????????????? < bean class = "org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />

    ???????????????????? </ property >

    ???????????????????? < property name = "cacheName" value = "userCache" />

    ????????????????? </ bean >

    ????????????? </ property >

    ?????????? </ bean >

    ?????? </ property >

    ?????? < property name = "passwordEncoder" ref = "passwordEncoder" />

    ??? </ bean >

    ?

    ?

    4 < bean id = "jdbcDaoImpl"

    ????????? class = "org.acegisecurity.userdetails.jdbc.JdbcDaoImpl" >

    ??????? < property name = "dataSource" ref = "dataSource" />

    ??????? < property name = "usersByUsernameQuery" >

    ??????????? < value >

    ??????????????? select loginid,passwd,1 from users where status='1' and loginid = ?

    ??????????? </ value >

    ??????? </ property >

    ??????? < property name = "authoritiesByUsernameQuery" >

    ??????????? < value >

    ??????????????? select u.loginid,p.name from

    ??????????????? users u,roles r,permissions p,user_role ur,role_permis rp

    ??????????????? where

    ??????????????? u.id=ur.user_id and

    ??????????????? r.id=ur.role_id and

    ??????????????? p.id=rp.permis_id and

    ??????????????? r.id=rp.role_id and

    ??????????????? p.status='1' and u.loginid=?

    ??????????? </ value >

    ??????? </ property >

    </ bean >

    ?

    ?

    二、程序流程:

    1 .登錄的時(shí)候執(zhí)行的過(guò)濾為 authenticationProcessingFilter ,查看其實(shí)現(xiàn)為 org.bookStore.test.plugins.security.UserAuthenticationProcessingFilter ,該類(lèi)繼承自 org.acegisecurity.ui.webapp.AuthenticationProcessingFilter ,又繼承自 org.acegisecurity.ui.AbstractProcessingFilter ,這時(shí)候看到了 doFilter() 該方法取了 web 層傳過(guò)來(lái)的 request response ,然后對(duì)登錄路徑執(zhí)行了判斷等操作,接下來(lái)執(zhí)行至 authResult = attemptAuthentication(httpRequest);

    2 .從類(lèi)繼承關(guān)系上找到該方法的實(shí)現(xiàn)來(lái)自 AuthenticationProcessingFilter ,執(zhí)行的邏輯為先取出 web 層傳過(guò)來(lái)的用戶(hù)名和密碼接著將得到的信息包裝為 UsernamePasswordAuthenticationToken

    public UsernamePasswordAuthenticationToken(Object principal, Object credentials) {

    ??? super ( null );

    ??? this . principal = principal;????

    ??? this . credentials = credentials;

    ??? setAuthenticated( false );

    }

    3 .接下來(lái)執(zhí)行了 setDetails(request, authRequest); request 實(shí)例賦給 authRequest 的屬性。

    4 .調(diào)用 authenticationManager authenticate(authRequest) 方法。

    5 .程序轉(zhuǎn)至 authenticationManager 內(nèi)執(zhí)行。該類(lèi)繼承自 org.acegisecurity. AbstractAuthenticationManager ,執(zhí)行方法 authenticate(authRequest)

    public final Authentication authenticate(Authentication authRequest)

    ??? throws AuthenticationException {

    ??? try {

    ??????? Authentication authResult = doAuthentication(authRequest);

    ??????? copyDetails(authRequest, authResult);

    ?

    ??????? return authResult;

    ??? } catch (AuthenticationException e) {

    ??????? e.setAuthentication(authRequest);

    ??????? throw e;

    ??? }

    }

    doAuthentication(authRequest) 來(lái)自 ProviderManager 該方法執(zhí)行了其 providers 中的方法 authenticate(Authentication authentication)

    6 .此方法中調(diào)用了 retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication) 該方法內(nèi)按 web 層用戶(hù)輸入的用戶(hù)名和密碼從數(shù)據(jù)庫(kù)內(nèi)比較是否有該用戶(hù),如果有則將其 user 表內(nèi)對(duì)應(yīng)的信息包裝為 UserDetail( 接口 , 實(shí)際為 User 的實(shí)例 ) List 對(duì)象,并將該用戶(hù)相應(yīng)的權(quán)限包裝為 GrantedAuthorityImpl 對(duì)象的 List 集合對(duì)象。至此程序返回至( 3. )繼續(xù)執(zhí)行

    7 .繼續(xù)執(zhí)行 org.acegisecurity.ui.AbstractProcessingFilter successfulAuthentication(

    HttpServletRequest request,

    HttpServletResponse response,

    Authentication authResult){

    ??? ......

    SecurityContextHolder.getContext().setAuthentication(authResult);// 將包裝好的 UsernamePasswordAuthenticationToken 對(duì)象保存至系統(tǒng)上下文

    ......

    }

    8 .登錄執(zhí)行完畢。

    posted on 2006-12-06 17:33 javajohn 閱讀(1966) 評(píng)論(3)  編輯  收藏 所屬分類(lèi): 其他類(lèi)

    Feedback

    # re: acegi源碼學(xué)習(xí)之用戶(hù)登錄篇 2006-12-07 14:51

    最近在學(xué)習(xí)這個(gè)東西
    老兄多分析一下 跟進(jìn)學(xué)習(xí)  回復(fù)  更多評(píng)論   

    # re: acegi源碼學(xué)習(xí)之用戶(hù)登錄篇 2007-02-06 16:07 mircle_wang

    正在 學(xué)習(xí)中 請(qǐng)問(wèn) 它對(duì)數(shù)據(jù)庫(kù)的建表有什么特別的限制嗎?
    權(quán)限

      回復(fù)  更多評(píng)論   

    # re: acegi源碼學(xué)習(xí)之用戶(hù)登錄篇 2009-03-10 11:07 陳一

    這個(gè)不錯(cuò)~ 我剛好在找這個(gè)! 在這謝過(guò)!  回復(fù)  更多評(píng)論   


    My Links

    Blog Stats

    常用鏈接

    留言簿(7)

    隨筆分類(lèi)(36)

    隨筆檔案(39)

    classmate

    good blog

    企業(yè)管理網(wǎng)站

    好友

    站點(diǎn)收藏

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 在线观看永久免费| 中文字幕乱理片免费完整的| 国产免费观看黄AV片| 一级毛片免费毛片毛片| 亚洲另类春色国产精品| 国产在线观看免费完整版中文版| 拍拍拍无挡免费视频网站| 全亚洲最新黄色特级网站 | 亚洲成在人天堂在线| 天堂在线免费观看中文版| 久久青青草原国产精品免费| 亚洲av永久中文无码精品综合| 国产综合成人亚洲区| 久久久久亚洲精品日久生情| 国产成人综合亚洲AV第一页| 蜜桃AV无码免费看永久| a级毛片免费全部播放| 在线观看亚洲专区| 亚洲美国产亚洲AV| 亚洲 暴爽 AV人人爽日日碰| 亚洲国产美女视频| 亚洲一区二区三区高清视频| 亚洲性69影院在线观看| 91亚洲va在线天线va天堂va国产| 猫咪免费人成网站在线观看入口| 日本免费网站视频www区| 在线免费观看你懂的| 一级大黄美女免费播放| 男女一边摸一边做爽的免费视频| 成人免费看吃奶视频网站| 国产青草亚洲香蕉精品久久| 九九九精品视频免费| 久久免费观看国产精品88av| AV无码免费永久在线观看| 一个人免费观看视频www| 国产成人精品免费视| 最近中文字幕免费mv视频7| 在人线av无码免费高潮喷水| 毛色毛片免费观看| www亚洲精品少妇裸乳一区二区| ssswww日本免费网站片|