Java Code Examples for io.choerodon.core.oauth.CustomUserDetails#getUserId()

The following examples show how to use io.choerodon.core.oauth.CustomUserDetails#getUserId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoardServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
public UserSettingVO updateUserSettingBoard(Long projectId, Long boardId, String swimlaneBasedCode) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    Long userId = customUserDetails.getUserId();
    UserSettingDTO userSettingDTO = modelMapper.map(queryUserSettingBoardByBoardId(projectId, boardId, userId), UserSettingDTO.class);
    if (userSettingDTO == null) {
        userSettingDTO = new UserSettingDTO();
        userSettingDTO.setDefaultBoard(false);
        userSettingDTO.setTypeCode(BOARD);
        userSettingDTO.setProjectId(projectId);
        userSettingDTO.setBoardId(boardId);
        userSettingDTO.setUserId(userId);
        userSettingDTO.setSwimlaneBasedCode(swimlaneBasedCode);
        userSettingDTO = userSettingService.create(userSettingDTO);
    } else {
        userSettingDTO.setSwimlaneBasedCode(swimlaneBasedCode);
        userSettingDTO = userSettingService.update(userSettingDTO);
    }
    return modelMapper.map(userSettingDTO, UserSettingVO.class);
}
 
Example 2
Source File: PersonalFilterServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
public PersonalFilterVO create(Long projectId, PersonalFilterVO personalFilterVO) {
    if (personalFilterVO.getName() == null || personalFilterVO.getName().equals("")) {
        throw new CommonException(NAME_ERROR);
    }
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    Long userId = customUserDetails.getUserId();
    if (checkName(projectId, userId, personalFilterVO.getName())) {
        throw new CommonException(NAME_EXIST);
    }
    personalFilterVO.setUserId(userId);
    personalFilterVO.setProjectId(projectId);
    PersonalFilterDTO personalFilterDTO = modelMapper.map(personalFilterVO, PersonalFilterDTO.class);
    if (personalFilterMapper.insert(personalFilterDTO) != 1) {
        throw new CommonException(INSERT_ERROR);
    }
    return queryById(projectId, personalFilterDTO.getFilterId());
}
 
Example 3
Source File: PrincipalServiceImpl.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
@Override
public void addRouteRuleCode(CustomUserDetails customUserDetails) {
    RouteMemberRuleDTO record = new RouteMemberRuleDTO();
    Long userId = customUserDetails.getUserId();
    if (userId == null) {
        return;
    }
    record.setUserId(userId);
    RouteMemberRuleDTO routeMemberRule = routeMemberRuleMapper.selectOne(record);
    if (routeMemberRule == null) {
        return;
    }
    customUserDetails.setRouteRuleCode(routeMemberRule.getRouteRuleCode());
}
 
Example 4
Source File: CustomClientInterceptor.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (!(antPathMatcher.match(AUTHORIZE,request.getRequestURI()) && CODE.equals(request.getParameter(RESPONSE_TYPE)))) {
        return true;
    }
    Long userId;
    String clientId = request.getParameter(CLIENT_ID);
    ClientE client = clientService.getClientByName(clientId);
    LOGGER.info("start to handle client:, clientId:{}", clientId);
    if (client == null) {
        throw new NoSuchClientException("No client found : " + clientId);
    }
    // 不需要做普罗米修斯的客户端权限校验
    if (!ClientTypeEnum.CLUSTER.value().equals(client.getSourceType())) {
        return true;
    }

    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    if (customUserDetails == null || customUserDetails.getUserId() == null) {
        LOGGER.info("=========不能拿到userId");
        throw new AccessDeniedException("未登录");
    }
    userId = customUserDetails.getUserId();

    LOGGER.info("start to check user's cluster permission: userId:{}", userId);
    // 调用devops接口校验用户是否有访问集群的权限
    Boolean result = devopsFeignClient.checkUserClusterPermission(client.getSourceId(), userId).getBody();
    if (Boolean.FALSE.equals(result)) {
        throw new AccessDeniedException("权限不足");
    }
    return true;
}