热卖商品
新闻详情
使用Acegi 1.0获取用户信息 - 程序园
来自 : www.voidcn.com/article/p-pybar
发布时间:2021-03-25
importorg.acegisecurity.Authentication; importorg.acegisecurity.context.SecurityContext; importorg.acegisecurity.context.SecurityContextHolder; importorg.acegisecurity.ui.WebAuthenticationDetails; importorg.acegisecurity.userdetails.UserDetails; publicclassThreadLocaTest{ /***/ /** *取得当前用户名 * */ publicstaticStringgetUsername(){ SecurityContextctx=SecurityContextHolder.getContext(); if(ctx!=null){ Authenticationauth=ctx.getAuthentication(); if(auth!=null){ Objectprincipal=auth.getPrincipal(); if(principalinstanceofUserDetails){ return((UserDetails)principal).getUsername(); }else{ returnprincipal.toString(); } } } returnnull; } /***/ /** *取得当前用户密码 * */ publicstaticStringgetPassword(){ SecurityContextctx=SecurityContextHolder.getContext(); if(ctx!=null){ Authenticationauth=ctx.getAuthentication(); if(auth!=null){ Objectprincipal=auth.getPrincipal(); if(principalinstanceofUserDetails){ return((UserDetails)principal).getPassword(); }else{ returnnull; } } } returnnull; } /***/ /** *取得当前用户SessionId * */ publicstaticStringgetSessionID(){ SecurityContextctx=SecurityContextHolder.getContext(); if(ctx!=null){ if(ctxinstanceofSecurityContext){ SecurityContextsc=(SecurityContext)ctx; Authenticationauth=sc.getAuthentication(); if(auth!=null){ Objectdetails=auth.getDetails(); if(detailsinstanceofWebAuthenticationDetails){ return((WebAuthenticationDetails)details) .getSessionId(); }else{ returnnull; } } } } returnnull; } }
本文链接: http://acegi0.immuno-online.com/view-724523.html
发布于 : 2021-03-25
阅读(0)
最新动态
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
公司介绍
品牌分类
联络我们