热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_45633079
糖六文
4 年前
trueweixin_45633079

//获取登录用户信息
public CsmallAuthenticationInfo getUserInfo(){
// 获得SpringSecurity上下文(容器)对象
UsernamePasswordAuthenticationToken authenticationToken=
(UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext()
.getAuthentication();
if(authenticationToken==null){
throw new CoolSharkServiceException(ResponseCode.UNAUTHORIZED,"没有登录信息");
}
// 如果authenticationToken不为空,获得其中的用户信息
CsmallAuthenticationInfo csmallAuthenticationInfo=
(CsmallAuthenticationInfo) authenticationToken.getCredentials();
// 返回登录用户信息
return csmallAuthenticationInfo;
}
// 业务逻辑层大多数方法都是需要获得用户Id,所以我们编写一个方法,专门返回当前登录用户的id
public Long getUserId(){
return getUserInfo().getId();
}

CSDN App 扫码分享
分享
评论
2
打赏
  • 复制链接
  • 举报
下一条:
人性所有特点的根本来源是基因决定的“生存”与“延续”。
立即登录