e代劍客——溫柔一刀

          生活就像海洋,只有意志堅強的人,才能到達彼岸

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            76 隨筆 :: 7 文章 :: 215 評論 :: 0 Trackbacks

          使用Acegi 1.0獲取用戶信息,

          import ?org.acegisecurity.Authentication;
          import ?org.acegisecurity.context.SecurityContext;
          import ?org.acegisecurity.context.SecurityContextHolder;
          import ?org.acegisecurity.ui.WebAuthenticationDetails;
          import ?org.acegisecurity.userdetails.UserDetails;
          public ? class ?ThreadLocaTest? {
          ?
          ?
          /**
          ????*?取得當前用戶名
          ????*?
          ????
          */

          ???
          public ? static ?String?getUsername() {
          ????SecurityContext?ctx?
          = ?SecurityContextHolder.getContext();
          ?????
          if (ctx != null ) {
          ??????Authentication?auth?
          = ?ctx.getAuthentication();???
          ?????????
          if (auth != null ) {
          ???????????Object?principal
          = auth.getPrincipal();
          ???????????
          if (principal? instanceof ?UserDetails)? {
          ?????????????
          return ?((UserDetails)principal).getUsername();
          ???????????}
          else {
          ?????????????
          return ?principal.toString();?????????
          ?????????}

          ???????}

          ?????}

          ?????
          return ? null ;
          ???}

          ???
          /** ?
          ????*?取得當前用戶密碼
          ????*?
          ????
          */

          ???
          public ? static ?String?getPassword() {
          ????SecurityContext?ctx?
          = ?SecurityContextHolder.getContext();
          ?????
          if (ctx != null ) {???
          ?????????Authentication?auth
          = ctx.getAuthentication();
          ?????????
          if (auth != null ) {
          ???????????Object?principal
          = auth.getPrincipal();
          ???????????
          if (principal? instanceof ?UserDetails)? {
          ?????????????
          return ?((UserDetails)principal).getPassword();
          ???????????}
          else {
          ?????????????
          return ? null ;
          ???????????}

          ?????????}

          ???????
          ?????}

          ?????
          return ? null ;
          ???}

          ???
          /**
          ????*?取得當前用戶SessionId
          ????*?
          ????
          */

          ???
          public ? static ?String?getSessionID() {
          ????SecurityContext?ctx?
          = ?SecurityContextHolder.getContext();
          ?????
          if (ctx != null ) {
          ???????
          if (ctx? instanceof ?SecurityContext) {
          ????????SecurityContext?sc
          = (SecurityContext)ctx;
          ?????????Authentication?auth
          = sc.getAuthentication();
          ?????????
          if (auth != null ) {
          ???????????Object?details
          = auth.getDetails();
          ???????????
          if (details? instanceof ?WebAuthenticationDetails)? {
          ?????????????
          return ?((WebAuthenticationDetails)details).getSessionId();
          ???????????}
          else {
          ?????????????
          return ? null ;
          ???????????}

          ?????????}

          ???????}

          ?????}

          ?????
          return ? null ;
          ???}

          }


          posted on 2006-09-29 15:17 溫柔一刀 閱讀(742) 評論(3)  編輯  收藏 所屬分類: 開源框架

          評論

          # re: 使用Acegi 1.0獲取用戶信息[未登錄] 2008-04-22 16:49 rain
          為什么我登入成功,Authentication auth = ctx.getAuthentication();
          這個為空的呢..我是用struts2  回復  更多評論
            

          # re: 使用Acegi 1.0獲取用戶信息 2008-06-16 13:55 xx
          我也是null  回復  更多評論
            

          # re: 使用Acegi 1.0獲取用戶信息 2008-08-06 15:57 jinshan
          我的也是null,請指教!fujinshan_403@163.com,謝謝  回復  更多評論
            

          聯系偶 zhupanjava@gmail.com 溫柔一刀
          主站蜘蛛池模板: 阜新| 乌什县| 天镇县| 巨野县| 兰溪市| 鸡泽县| 交城县| 五指山市| 盐山县| 白城市| 永嘉县| 光泽县| 芦溪县| 太仓市| 天长市| 平乡县| 永昌县| 壤塘县| 樟树市| 靖宇县| 南投县| 绥江县| 湖州市| 城市| 德昌县| 乐安县| 得荣县| 大同县| 新泰市| 工布江达县| 池州市| 威远县| 银川市| 胶州市| 南充市| 中江县| 崇信县| 石柱| 西贡区| 昌江| 东乡族自治县|