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

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

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

    javajohn

    金色年華

    acegi源碼學習之用戶登錄篇

    acegi 源碼學習之用戶登錄篇

    一、查看 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 .登錄的時候執行的過濾為 authenticationProcessingFilter ,查看其實現為 org.bookStore.test.plugins.security.UserAuthenticationProcessingFilter ,該類繼承自 org.acegisecurity.ui.webapp.AuthenticationProcessingFilter ,又繼承自 org.acegisecurity.ui.AbstractProcessingFilter ,這時候看到了 doFilter() 該方法取了 web 層傳過來的 request response ,然后對登錄路徑執行了判斷等操作,接下來執行至 authResult = attemptAuthentication(httpRequest);

    2 .從類繼承關系上找到該方法的實現來自 AuthenticationProcessingFilter ,執行的邏輯為先取出 web 層傳過來的用戶名和密碼接著將得到的信息包裝為 UsernamePasswordAuthenticationToken

    public UsernamePasswordAuthenticationToken(Object principal, Object credentials) {

    ??? super ( null );

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

    ??? this . credentials = credentials;

    ??? setAuthenticated( false );

    }

    3 .接下來執行了 setDetails(request, authRequest); request 實例賦給 authRequest 的屬性。

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

    5 .程序轉至 authenticationManager 內執行。該類繼承自 org.acegisecurity. AbstractAuthenticationManager ,執行方法 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) 來自 ProviderManager 該方法執行了其 providers 中的方法 authenticate(Authentication authentication)

    6 .此方法中調用了 retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication) 該方法內按 web 層用戶輸入的用戶名和密碼從數據庫內比較是否有該用戶,如果有則將其 user 表內對應的信息包裝為 UserDetail( 接口 , 實際為 User 的實例 ) List 對象,并將該用戶相應的權限包裝為 GrantedAuthorityImpl 對象的 List 集合對象。至此程序返回至( 3. )繼續執行

    7 .繼續執行 org.acegisecurity.ui.AbstractProcessingFilter successfulAuthentication(

    HttpServletRequest request,

    HttpServletResponse response,

    Authentication authResult){

    ??? ......

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

    ......

    }

    8 .登錄執行完畢。

    posted on 2006-12-06 17:33 javajohn 閱讀(1964) 評論(3)  編輯  收藏 所屬分類: 其他類

    Feedback

    # re: acegi源碼學習之用戶登錄篇 2006-12-07 14:51

    最近在學習這個東西
    老兄多分析一下 跟進學習  回復  更多評論   

    # re: acegi源碼學習之用戶登錄篇 2007-02-06 16:07 mircle_wang

    正在 學習中 請問 它對數據庫的建表有什么特別的限制嗎?
    權限

      回復  更多評論   

    # re: acegi源碼學習之用戶登錄篇 2009-03-10 11:07 陳一

    這個不錯~ 我剛好在找這個! 在這謝過!  回復  更多評論   


    My Links

    Blog Stats

    常用鏈接

    留言簿(7)

    隨筆分類(36)

    隨筆檔案(39)

    classmate

    good blog

    企業管理網站

    好友

    站點收藏

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 好湿好大好紧好爽免费视频| 91免费人成网站在线观看18| 亚洲av无码av制服另类专区| 无限动漫网在线观看免费 | 男性gay黄免费网站| 亚洲乱亚洲乱妇无码麻豆| 国产成人免费在线| 国产亚洲男人的天堂在线观看 | 无码色偷偷亚洲国内自拍| 好看的亚洲黄色经典| 全免费A级毛片免费看网站| 三级黄色免费观看| 亚洲国产欧洲综合997久久| 国产精品亚洲一区二区三区在线| 丁香花免费高清视频完整版| 国产真人无码作爱免费视频| 亚洲色偷偷偷综合网| 亚洲爱情岛论坛永久| 又黄又爽的视频免费看| 青娱乐免费视频在线观看| 久久久久免费视频| 亚洲精品亚洲人成在线| 中文字幕亚洲综合久久| 久久综合亚洲色HEZYO国产| 成人au免费视频影院| 无码午夜成人1000部免费视频| 另类图片亚洲校园小说区| 亚洲精品在线免费观看| 亚洲开心婷婷中文字幕| gogo全球高清大胆亚洲| 青春禁区视频在线观看直播免费| 久久精品一区二区免费看| 国产精品99爱免费视频| 亚洲日韩在线中文字幕综合| 亚洲二区在线视频| 色拍自拍亚洲综合图区| 青青草原亚洲视频| 亚洲国产午夜中文字幕精品黄网站| 成全影视免费观看大全二| 国产高清免费视频| 免费看片在线观看|