热卖商品
新闻详情
使用Acegi 1.0获取用户信息 - 温柔一刀 - ITeye博客
来自 : zhupan.iteye.com/blog/26...
发布时间:2021-03-25
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; }
本文链接: http://acegi0.immuno-online.com/view-724504.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
公司介绍
品牌分类
联络我们