SecurityUtils.java 文件源码

java
阅读 39 收藏 0 点赞 0 评论 0

项目:shoucang 作者:
/**
 * Return the current user, or throws an exception, if the user is not
 * authenticated yet.
 *
 * @return the current user
 */
public static User getCurrentUser() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    if (authentication != null) {
        if (authentication.getPrincipal() instanceof User) {
            return (User) authentication.getPrincipal();
        }
    }
    throw new IllegalStateException("User not found!");
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号