use of com.webank.wedatasphere.qualitis.response.UserAndRoleResponse in project Qualitis by WeBankFinTech.
the class RoleServiceImpl method getRoleByUser.
@Override
public GeneralResponse<?> getRoleByUser() {
Long userId;
String username = null;
// Get current userId
userId = HttpUtils.getUserId(httpServletRequest);
username = HttpUtils.getUserName(httpServletRequest);
User userInDb = userDao.findById(userId);
// Find user role by user
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
// Get all roles of user
List<String> roleNames = userRoles.stream().map(userRole -> userRole.getRole().getName()).collect(Collectors.toList());
UserAndRoleResponse response = new UserAndRoleResponse();
response.setRoles(roleNames);
response.setUsername(username);
HttpSession session = httpServletRequest.getSession();
response.setLoginRandom((Integer) session.getAttribute("loginRandom"));
LOGGER.info("Succeed to get role of user, {} role: {}, current_user: {}", username, roleNames.toString(), username);
return new GeneralResponse<>("200", "{&GET_ROLE_SUCCESSFULLY}", response);
}
Aggregations