Search in sources :

Example 1 with UserTransfer

use of com.weibo.model.UserTransfer in project motan by weibocom.

the class UserController method getUser.

/**
     * Retrieves the currently logged in user.
     *
     * @return A transfer containing the username and the roles.
     */
@RequestMapping(value = "", method = RequestMethod.GET)
public UserTransfer getUser() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication instanceof AnonymousAuthenticationToken) {
        throw new CustomException.UnauthorizedException();
    }
    UserDetails userDetails = (UserDetails) authentication.getPrincipal();
    return new UserTransfer(userDetails.getUsername(), createRoleMap(userDetails));
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) UserTransfer(com.weibo.model.UserTransfer) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserTransfer (com.weibo.model.UserTransfer)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1