Search in sources :

Example 1 with UserAndRoleResponse

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);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) LoggerFactory(org.slf4j.LoggerFactory) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleResponse(com.webank.wedatasphere.qualitis.response.RoleResponse) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) Service(org.springframework.stereotype.Service) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) DepartmentDao(com.webank.wedatasphere.qualitis.dao.DepartmentDao) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) RoleRequest(com.webank.wedatasphere.qualitis.request.role.RoleRequest) HttpSession(javax.servlet.http.HttpSession) RoleAddRequest(com.webank.wedatasphere.qualitis.request.role.RoleAddRequest) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) RoleModifyRequest(com.webank.wedatasphere.qualitis.request.role.RoleModifyRequest) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) RoleDao(com.webank.wedatasphere.qualitis.dao.RoleDao) com.webank.wedatasphere.qualitis.entity(com.webank.wedatasphere.qualitis.entity) RolePermissionDao(com.webank.wedatasphere.qualitis.dao.RolePermissionDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleDefaultTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RoleDefaultTypeEnum) BodyReaderHttpServletRequestWrapper(com.webank.wedatasphere.qualitis.filter.BodyReaderHttpServletRequestWrapper) Transactional(org.springframework.transaction.annotation.Transactional) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) HttpSession(javax.servlet.http.HttpSession)

Aggregations

DepartmentDao (com.webank.wedatasphere.qualitis.dao.DepartmentDao)1 RoleDao (com.webank.wedatasphere.qualitis.dao.RoleDao)1 RolePermissionDao (com.webank.wedatasphere.qualitis.dao.RolePermissionDao)1 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)1 UserRoleDao (com.webank.wedatasphere.qualitis.dao.UserRoleDao)1 com.webank.wedatasphere.qualitis.entity (com.webank.wedatasphere.qualitis.entity)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 BodyReaderHttpServletRequestWrapper (com.webank.wedatasphere.qualitis.filter.BodyReaderHttpServletRequestWrapper)1 PageRequest (com.webank.wedatasphere.qualitis.request.PageRequest)1 RoleAddRequest (com.webank.wedatasphere.qualitis.request.role.RoleAddRequest)1 RoleModifyRequest (com.webank.wedatasphere.qualitis.request.role.RoleModifyRequest)1 RoleRequest (com.webank.wedatasphere.qualitis.request.role.RoleRequest)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)1 RoleResponse (com.webank.wedatasphere.qualitis.response.RoleResponse)1 UserAndRoleResponse (com.webank.wedatasphere.qualitis.response.UserAndRoleResponse)1 RoleDefaultTypeEnum (com.webank.wedatasphere.qualitis.rule.constant.RoleDefaultTypeEnum)1 RoleService (com.webank.wedatasphere.qualitis.service.RoleService)1 HttpUtils (com.webank.wedatasphere.qualitis.util.HttpUtils)1 IOException (java.io.IOException)1