问题大概是这样的:
1.在登录的时候,输入的用户名和密码都可以用此方法取的到
public String getCurrentUserName() {
Authentication currentUser = getCurrentUserAuthentication();
if (currentUser != null) {
return currentUser.getName();
}
return null;
}
再调:
public Authentication getCurrentUserAuthentication() {
Authentication currentUser = null;
SecurityContext context = SecurityContextHolder.getContext();
if (null != context) {
currentUser = context.getAuthentication();
}
return currentUser;
}
这里返回的就是用户名! 2.奇怪的地方来了:当我做增,删,改操作的时候,我却不能取到用户名。使用的还是上面的那个方法。
求解,SecurityContext context = SecurityContextHolder.getContext()这不操作应该要注意什么事项?
这个SecurityContextHolder 好像还得用配置文件来配置,getContext()方法是不是从缓存中取数?
脑袋中全是疑问,我只好问你了!!大哥,大姐们!!!求赐教!!!!
1.在登录的时候,输入的用户名和密码都可以用此方法取的到
public String getCurrentUserName() {
Authentication currentUser = getCurrentUserAuthentication();
if (currentUser != null) {
return currentUser.getName();
}
return null;
}
再调:
public Authentication getCurrentUserAuthentication() {
Authentication currentUser = null;
SecurityContext context = SecurityContextHolder.getContext();
if (null != context) {
currentUser = context.getAuthentication();
}
return currentUser;
}
这里返回的就是用户名! 2.奇怪的地方来了:当我做增,删,改操作的时候,我却不能取到用户名。使用的还是上面的那个方法。
求解,SecurityContext context = SecurityContextHolder.getContext()这不操作应该要注意什么事项?
这个SecurityContextHolder 好像还得用配置文件来配置,getContext()方法是不是从缓存中取数?
脑袋中全是疑问,我只好问你了!!大哥,大姐们!!!求赐教!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货