AccountResource.java 文件源码

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

项目:jhipster-microservices-example 作者:
/**
 * GET  /account : get the current user.
 *
 * @return the ResponseEntity with status 200 (OK) and the current user in body, or status 500 (Internal Server
 * Error) if the user couldn't be returned
 */
@GetMapping("/account")
@Timed
public ResponseEntity<UserVM> getAccount() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    try{
        User user = (User) authentication.getPrincipal();
        UserVM userVM = new UserVM(user.getUsername(),
            user.getAuthorities().stream()
                .map(GrantedAuthority::getAuthority).collect(Collectors.toSet()));
        return new ResponseEntity<>(userVM, HttpStatus.OK);
    } catch (NullPointerException | ClassCastException e){
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号