io.choerodon.core.oauth.CustomUserDetails Java Examples

The following examples show how to use io.choerodon.core.oauth.CustomUserDetails. 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: IssueServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
private void insertSprintWhenTransform(Long issueId, Long sprintId, Long projectId, List<Long> issueIds) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    IssueSprintRelDTO issueSprintRelDTO = new IssueSprintRelDTO();
    issueSprintRelDTO.setIssueId(issueId);
    issueSprintRelDTO.setSprintId(sprintId);
    issueSprintRelDTO.setProjectId(projectId);
    if (issueSprintRelMapper.selectOne(issueSprintRelDTO) == null) {
        if (issueMapper.selectUnCloseSprintId(projectId, issueId) != null) {
            BatchRemoveSprintDTO batchRemoveSprintDTO = new BatchRemoveSprintDTO(projectId, sprintId, issueIds);
            issueAccessDataService.removeIssueFromSprintByIssueIds(batchRemoveSprintDTO);
            issueAccessDataService.issueToDestinationByIds(projectId, sprintId, issueIds, new Date(), customUserDetails.getUserId());
        } else {
            issueSprintRelService.createIssueSprintRel(modelMapper.map(issueSprintRelDTO, IssueSprintRelDTO.class));
        }
    }
}
 
Example #2
Source File: PiServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
public PiDTO startPi(Long programId, PiVO piVO) {
    piValidator.checkPiStart(piVO);
    // create sprint in each project
    createSprintWhenStartPi(programId, piVO.getId());
    // update pi status: doing
    if (piMapper.updateByPrimaryKeySelective(new PiDTO(programId, piVO.getId(), PI_DOING, new Date(), piVO.getObjectVersionNumber())) != 1) {
        throw new CommonException("error.pi.update");
    }
    // update issue status
    List<IssueDTO> issueDTOList = issueMapper.selectStatusChangeIssueByPiId(programId, piVO.getId());
    Long updateStatusId = piVO.getUpdateStatusId();
    if (updateStatusId != null) {
        if (issueDTOList != null && !issueDTOList.isEmpty()) {
            CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
            issueAccessDataService.updateStatusIdBatch(programId, updateStatusId, issueDTOList, customUserDetails.getUserId(), new Date());
        }
    }
    return piMapper.selectByPrimaryKey(piVO.getId());
}
 
Example #3
Source File: ProductVersionServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
@Saga(code = "agile-delete-version", description = "删除版本", inputSchemaClass = VersionPayload.class)
public Boolean mergeVersion(Long projectId, ProductVersionMergeVO productVersionMergeVO) {
    productVersionMergeVO.getSourceVersionIds().remove(productVersionMergeVO.getTargetVersionId());
    if (productVersionMergeVO.getSourceVersionIds().isEmpty()) {
        throw new CommonException(SOURCE_VERSION_ERROR);
    }
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<VersionIssueDTO> versionIssues = productVersionMapper.queryIssueByVersionIds(projectId, productVersionMergeVO.getSourceVersionIds(), productVersionMergeVO.getTargetVersionId());
    versionIssueRelService.deleteByVersionIds(projectId, productVersionMergeVO.getSourceVersionIds());
    if (!versionIssues.isEmpty()) {
        iProductVersionService.batchIssueToDestination(projectId, productVersionMergeVO.getTargetVersionId(), versionIssues, new Date(), customUserDetails.getUserId());
    }
    //这里不用日志是因为deleteByVersionIds方法已经有删除的日志了
    deleteByVersionIds(projectId, productVersionMergeVO.getSourceVersionIds());
    productVersionMergeVO.getSourceVersionIds().forEach(versionId -> {
        VersionPayload versionPayload = new VersionPayload();
        versionPayload.setVersionId(versionId);
        versionPayload.setProjectId(projectId);
        sagaClient.startSaga("agile-delete-version", new StartInstanceDTO(JSON.toJSONString(versionPayload), "", "", ResourceLevel.PROJECT.value(), projectId));
    });
    return true;
}
 
Example #4
Source File: ProductVersionServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
public ProductVersionDetailVO releaseVersion(Long projectId, ProductVersionReleaseVO productVersionRelease) {
    if (!Objects.equals(projectId, productVersionRelease.getProjectId())) {
        throw new CommonException(NOT_EQUAL_ERROR);
    }
    productVersionValidator.isRelease(projectId, productVersionRelease);
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    if (productVersionRelease.getTargetVersionId() != null && !Objects.equals(productVersionRelease.getTargetVersionId(), 0L)) {
        List<VersionIssueDTO> incompleteIssues = productVersionMapper.queryIncompleteIssues(projectId, productVersionRelease.getVersionId());
        if (!incompleteIssues.isEmpty()) {
            versionIssueRelService.deleteIncompleteIssueByVersionId(projectId, productVersionRelease.getVersionId());
            iProductVersionService.batchIssueToDestination(projectId, productVersionRelease.getTargetVersionId(), incompleteIssues, new Date(), customUserDetails.getUserId());
        }
    }
    release(projectId, productVersionRelease.getVersionId(), productVersionRelease.getReleaseDate());
    return versionDataAssembler.toTarget(productVersionMapper.selectByPrimaryKey(productVersionRelease.getVersionId()), ProductVersionDetailVO.class);
}
 
Example #5
Source File: ProductVersionServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean deleteVersion(Long projectId, Long versionId, Long targetVersionId) {
    productVersionValidator.judgeExist(projectId, targetVersionId);
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    if (targetVersionId != null && !Objects.equals(targetVersionId, 0L)) {
        List<VersionIssueDTO> versionFixIssues = productVersionMapper.queryIssuesByRelationType(projectId, versionId, FIX_RELATION_TYPE);
        if (versionFixIssues != null && !versionFixIssues.isEmpty()) {
            iProductVersionService.batchIssueToDestination(projectId, targetVersionId, versionFixIssues, new Date(), customUserDetails.getUserId());
        }
        List<VersionIssueDTO> versionInfIssues = productVersionMapper.queryIssuesByRelationType(projectId, versionId, INFLUENCE_RELATION_TYPE);
        if (versionInfIssues != null && !versionInfIssues.isEmpty()) {
            iProductVersionService.batchIssueToDestination(projectId, targetVersionId, versionInfIssues, new Date(), customUserDetails.getUserId());
        }
    }
    versionIssueRelService.deleteByVersionId(projectId, versionId);
    return simpleDeleteVersion(projectId, versionId);
}
 
Example #6
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 #7
Source File: SendMsgUtil.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
@Async
public void sendPmAndEmailAfterPiComplete(Long programId, PiDTO piDTO) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<ProjectRelationshipVO> projectRelationshipVOList = iamFeignClient.getProjUnderGroup(ConvertUtil.getOrganizationId(programId), programId, true).getBody();
    List<Long> projectIds = (projectRelationshipVOList != null && !projectRelationshipVOList.isEmpty() ? projectRelationshipVOList.stream().map(ProjectRelationshipVO::getProjectId).collect(Collectors.toList()) : null);
    if (projectIds == null) {
        return;
    }
    ProjectVO projectVO = userService.queryProject(programId);
    if (projectVO == null) {
        throw new CommonException(ERROR_PROJECT_NOTEXIST);
    }
    List<Long> result = new ArrayList<>();
    getProjectOwnerByProjects(projectIds, result);
    List<SprintDTO> sprintDTOList = sprintMapper.selectListByPiId(programId, piDTO.getId());
    Map<String, Object> params = new HashMap<>();
    params.put("programName", projectVO.getName());
    params.put("piName", piDTO.getCode() + "-" + piDTO.getName());
    params.put("sprintNameList", sprintDTOList != null && !sprintDTOList.isEmpty() ? sprintDTOList.stream().map(SprintDTO::getSprintName).collect(Collectors.joining(",")) : "");
    siteMsgUtil.piComplete(result, customUserDetails.getUserId(), programId, params);
}
 
Example #8
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 #9
Source File: SprintServiceImpl.java    From agile-service-old with Apache License 2.0 6 votes vote down vote up
private void moveNotDoneIssueToTargetSprint(Long projectId, SprintCompleteVO sprintCompleteVO) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<MoveIssueDTO> moveIssueDTOS = new ArrayList<>();
    Long targetSprintId = sprintCompleteVO.getIncompleteIssuesDestination();
    List<Long> moveIssueRankIds = sprintMapper.queryIssueIdOrderByRankDesc(projectId, sprintCompleteVO.getSprintId());
    moveIssueRankIds.addAll(sprintMapper.queryUnDoneSubOfParentIds(projectId, sprintCompleteVO.getSprintId()));
    beforeRank(projectId, sprintCompleteVO.getIncompleteIssuesDestination(), moveIssueDTOS, moveIssueRankIds);
    if (moveIssueDTOS.isEmpty()) {
        return;
    }
    List<Long> moveIssueIds = sprintMapper.queryIssueIds(projectId, sprintCompleteVO.getSprintId());
    moveIssueIds.addAll(issueMapper.querySubTaskIds(projectId, sprintCompleteVO.getSprintId()));
    moveIssueIds.addAll(sprintMapper.queryParentsDoneSubtaskUnDoneIds(projectId, sprintCompleteVO.getSprintId()));
    if (targetSprintId != null && !Objects.equals(targetSprintId, 0L)) {
        issueAccessDataService.issueToDestinationByIdsCloseSprint(projectId, targetSprintId, moveIssueIds, new Date(), customUserDetails.getUserId());
    }
    issueAccessDataService.batchUpdateIssueRank(projectId, moveIssueDTOS);
}
 
Example #10
Source File: SprintServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> queryByProjectId(Long projectId, Map<String, Object> searchParamMap, List<Long> quickFilterIds, Long organizationId, List<Long> assigneeFilterIds) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    Map<String, Object> backlog = new HashMap<>(2);
    String filterSql = null;
    if (quickFilterIds != null && !quickFilterIds.isEmpty()) {
        filterSql = getQuickFilter(quickFilterIds);
    }
    //待办事项查询相关issue的issueIds,不包含已完成的issue
    List<Long> issueIds = issueMapper.querySprintIssueIdsByCondition(projectId, customUserDetails.getUserId(),
            StringUtil.cast(searchParamMap.get(ADVANCED_SEARCH_ARGS)), filterSql, assigneeFilterIds);
    //待办事项查询相关issue的issueIds,包含已完成的issue
    List<IssueIdSprintIdVO> issueIdSprintIdVOS = issueMapper.querySprintAllIssueIdsByCondition(projectId, customUserDetails.getUserId(),
            StringUtil.cast(searchParamMap.get(ADVANCED_SEARCH_ARGS)), filterSql, assigneeFilterIds);
    List<SprintSearchVO> sprintSearches = new ArrayList<>();
    BackLogIssueVO backLogIssueVO = new BackLogIssueVO();
    Map<Long, PriorityVO> priorityMap = priorityService.queryByOrganizationId(organizationId);
    Map<Long, StatusVO> statusMapDTOMap = statusService.queryAllStatusMap(organizationId);
    setStatusIsCompleted(projectId, statusMapDTOMap);
    Map<Long, IssueTypeVO> issueTypeDTOMap = issueTypeService.listIssueTypeMap(organizationId);
    if (issueIdSprintIdVOS != null && !issueIdSprintIdVOS.isEmpty()) {
        handleSprintIssueData(issueIdSprintIdVOS, issueIds, sprintSearches, backLogIssueVO, projectId, priorityMap, statusMapDTOMap, issueTypeDTOMap);
    } else {
        handleSprintNoIssue(sprintSearches, projectId);
    }
    backlog.put(SPRINT_DATA, sprintSearches);
    backlog.put(BACKLOG_DATA, backLogIssueVO);
    return backlog;
}
 
Example #11
Source File: IssueCommentServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public IssueCommentVO createIssueComment(Long projectId, IssueCommentCreateVO issueCommentCreateVO) {
    IssueCommentDTO issueCommentDTO = issueCommentAssembler.toTarget(issueCommentCreateVO, IssueCommentDTO.class);
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    issueCommentDTO.setUserId(customUserDetails.getUserId());
    issueCommentDTO.setProjectId(projectId);
    return queryByProjectIdAndCommentId(projectId, iIssueCommentService.createBase(issueCommentDTO).getCommentId());
}
 
Example #12
Source File: PiServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public List<SubFeatureDTO> batchFeatureToPi(Long programId, Long piId, MoveIssueVO moveIssueVO) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<MoveIssueDTO> moveIssueDTOS = new ArrayList<>();
    if (moveIssueVO.getBefore()) {
        beforeRank(programId, piId, moveIssueVO, moveIssueDTOS);
    } else {
        afterRank(programId, piId, moveIssueVO, moveIssueDTOS);
    }
    issueAccessDataService.batchUpdateFeatureRank(programId, moveIssueDTOS);
    List<Long> moveIssueIds = moveIssueVO.getIssueIds();
    List<SubFeatureDTO> featureDTOList = piMapper.selectFeatureIdByFeatureIds(programId, moveIssueIds).stream().filter(subFeatureDO -> subFeatureDO.getPiId() == null ? piId != 0 : !subFeatureDO.getPiId().equals(piId)).collect(Collectors.toList());
    if (featureDTOList != null && !featureDTOList.isEmpty()) {
        List<Long> moveIssueIdsFilter = featureDTOList.stream().map(SubFeatureDTO::getIssueId).collect(Collectors.toList());
        // batch update status
        if (moveIssueVO.getUpdateStatusId() != null) {
            batchUpdateStatus(programId, piId, moveIssueIdsFilter, moveIssueVO.getUpdateStatusId(), moveIssueVO.getStatusCategoryCode(), customUserDetails.getUserId());
        }
        BatchRemovePiDTO batchRemovePiDTO = new BatchRemovePiDTO(programId, piId, moveIssueIdsFilter);
        issueAccessDataService.removeFeatureFromPiByIssueIds(batchRemovePiDTO);
        if (piId != null && !Objects.equals(piId, 0L)) {
            issueAccessDataService.batchFeatureToPi(programId, piId, moveIssueIdsFilter, new Date(), customUserDetails.getUserId());
        }
        return featureDTOList;
    } else {
        return new ArrayList<>();
    }
}
 
Example #13
Source File: PiServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public void dealUnCompleteFeature(Long programId, Long piId, Long targetPiId) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    List<MoveIssueDTO> moveIssueDTOS = new ArrayList<>();
    List<Long> moveFeatureRankIds = piMapper.queryFeatureIdOrderByRankDesc(programId, piId);
    beforeRankInProgram(programId, targetPiId, moveIssueDTOS, moveFeatureRankIds);
    if (moveIssueDTOS.isEmpty()) {
        return;
    }
    List<Long> moveFeatureIds = piMapper.queryFeatureIds(programId, piId);
    // batch update status
    Long organizationId = ConvertUtil.getOrganizationId(programId);
    //获取状态机id
    Long issueTypeId = null;
    List<IssueTypeVO> issueTypeVOList = projectConfigService.queryIssueTypesByProjectId(programId, "program");
    for (IssueTypeVO issueTypeVO : issueTypeVOList) {
        if ("feature".equals(issueTypeVO.getTypeCode())) {
            issueTypeId = issueTypeVO.getId();
            break;
        }
    }
    Long stateMachineId = projectConfigService.queryStateMachineId(programId, "program", issueTypeId);
    if (stateMachineId == null) {
        throw new CommonException(ERROR_ISSUE_STATE_MACHINE_NOT_FOUND);
    }
    //获取初始状态
    Long initStatusId = instanceService.queryInitStatusId(organizationId, stateMachineId);
    if (initStatusId == null) {
        throw new CommonException(ERROR_ISSUE_STATUS_NOT_FOUND);
    }
    batchUpdateStatus(programId, targetPiId, moveFeatureIds, initStatusId, "prepare", customUserDetails.getUserId());
    if (targetPiId != null && !Objects.equals(targetPiId, 0L)) {
        issueAccessDataService.featureToDestinationByIdsClosePi(programId, targetPiId, moveFeatureIds, new Date(), customUserDetails.getUserId());
    }
    issueAccessDataService.batchUpdateFeatureRank(programId, moveIssueDTOS);
}
 
Example #14
Source File: PriorityServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean delete(Long organizationId, Long priorityId, Long changePriorityId) {
    if (priorityId.equals(changePriorityId)) {
        throw new CommonException(DELETE_ILLEGAL);
    }
    checkLastPriority(organizationId, priorityId);
    PriorityDTO priority = priorityMapper.selectByPrimaryKey(priorityId);
    List<ProjectVO> projectVOS = iamFeignClient.queryProjectsByOrgId(organizationId, 1, 0).getBody().getList();
    List<Long> projectIds = projectVOS.stream().map(ProjectVO::getId).collect(Collectors.toList());
    Long count;
    if (projectIds == null || projectIds.isEmpty()) {
        count = 0L;
    } else {
        count = priorityService.checkPriorityDelete(organizationId, priorityId, projectIds);
    }
    //执行优先级转换
    if (!count.equals(0L)) {
        if (changePriorityId == null) {
            throw new CommonException(DELETE_ILLEGAL);
        }
        CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
        priorityService.batchChangeIssuePriority(organizationId, priorityId, changePriorityId, customUserDetails.getUserId(), projectIds);
    }
    int isDelete = priorityMapper.deleteByPrimaryKey(priorityId);
    if (isDelete != 1) {
        throw new CommonException("error.priority.delete");
    }
    if (priority.getDefault()) {
        updateOtherDefault(organizationId);
    }
    return true;
}
 
Example #15
Source File: FeedbackCommentServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public FeedbackCommentDTO createFeedbackComment(Long projectId, FeedbackCommentDTO feedbackCommentDTO) {
    feedbackCommentValidator.checkFeedbackCommentCreate(feedbackCommentDTO);
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    feedbackCommentDTO.setUserId(customUserDetails.getUserId());
    FeedbackCommentDTO result = iFeedbackCommentService.createBase(feedbackCommentDTO);
    if (feedbackCommentDTO.getBeRepliedId() != null && !feedbackCommentDTO.getWithin() && feedbackCommentDTO.getBeRepliedId() == null) {
        FeedbackDTO feedbackDTO = feedbackMapper.selectByPrimaryKey(feedbackCommentDTO.getFeedbackId());
        sendEmailUtil.feedbackCommentReplied(feedbackDTO.getEmail(), feedbackCommentDTO.getContent());
    }
    return result;
}
 
Example #16
Source File: UserServiceImpl.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
@Override
public UserDTO queryUserNameByOption(Long userId, Boolean withId) {
    CustomUserDetails customUserDetails = DetailsHelper.getUserDetails();
    if (userId == null || userId == 0) {
        return new UserDTO();
    } else {
        UserDTO userDTO = iamFeignClient.query(customUserDetails.getOrganizationId(), userId).getBody();
        if (withId) {
            userDTO.setRealName(userDTO.getLoginName() + userDTO.getRealName());
            return userDTO;
        } else {
            return userDTO;
        }
    }
}
 
Example #17
Source File: CustomUserDetailsServiceImpl.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
/**
 * 通过用户名加载用户对象
 *
 * @param username 用户名
 * @return 用户对象,带权限列表
 */
@Override
public UserDetails loadUserByUsername(String username) {
    UserE user = userService.queryByLoginField(username);
    CustomUserDetails details = new CustomUserDetails(
            user.getLoginName(), user.getPassword(), Collections.emptyList());
    details.setUserId(user.getId());
    details.setLanguage(user.getLanguage());
    details.setTimeZone(user.getTimeZone());
    details.setEmail(user.getEmail());
    details.setOrganizationId(user.getOrganizationId());
    details.setAdmin(user.getAdmin());
    return details;
}
 
Example #18
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;
}
 
Example #19
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 #20
Source File: GetUserDetailsServiceImpl.java    From api-gateway-old with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private CustomUserDetails setUserDetails(final Map<String, Object> map, boolean isClientOnly) {
    if (map.containsKey(USER_ID)) {
        CustomUserDetails user = new CustomUserDetails((String) map.get("username"),
                "unknown password", Collections.emptyList());
        user.setOrganizationId((long) (Integer) map.get("organizationId"));
        if (map.get(USER_ID) != null) {
            user.setUserId((long) (Integer) map.get(USER_ID));
            user.setLanguage((String) map.get("language"));
            user.setAdmin((Boolean) map.get("admin"));
            user.setTimeZone((String) map.get("timeZone"));
            if (map.get("email") != null) {
                user.setEmail((String) map.get("email"));
            }
        }
        if (isClientOnly) {
            user.setClientId((long) (Integer) map.get("clientId"));
            user.setClientName((String) map.get("clientName"));
            user.setClientAccessTokenValiditySeconds((Integer) map.get("clientAccessTokenValiditySeconds"));
            user.setClientRefreshTokenValiditySeconds((Integer) map.get("clientRefreshTokenValiditySeconds"));
            user.setClientAuthorizedGrantTypes((Collection<String>) map.get("clientAuthorizedGrantTypes"));
            user.setClientAutoApproveScopes((Collection<String>) map.get("clientAutoApproveScopes"));
            user.setClientRegisteredRedirectUri((Collection<String>) map.get("clientRegisteredRedirectUri"));
            user.setClientResourceIds((Collection<String>) map.get("clientResourceIds"));
            user.setClientScope((Collection<String>) map.get("clientScope"));
        }
        try {
            if (map.get(ADDITION_INFO) != null) {
                user.setAdditionInfo((Map) map.get(ADDITION_INFO));
            }
        } catch (Exception e) {
            LOGGER.warn("Parser addition info error:{}", e);
        }
        return user;
    }
    return null;
}
 
Example #21
Source File: OauthController.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
/**
 * 判断用户是否登录
 * @return
 */
@ResponseBody
@GetMapping(value = "/is_login")
public Boolean isLogin() {
    CustomUserDetails userDetails = DetailsHelper.getUserDetails();
    return userDetails != null;
}
 
Example #22
Source File: OauthController.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@GetMapping("/api/user")
public Principal user(Principal principal) {
    if (((OAuth2Authentication) principal).getPrincipal() instanceof String) {
        return principalService.setClientDetailUserDetails(principal);
    }
    if (((OAuth2Authentication) principal).getPrincipal() instanceof CustomUserDetails) {
        CustomUserDetails customUserDetails = (CustomUserDetails) ((OAuth2Authentication) principal).getPrincipal();
        principalService.addRouteRuleCode(customUserDetails);
    }
    return principal;
}
 
Example #23
Source File: GetUserDetailsServiceImpl.java    From gateway-helper with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private CustomUserDetails setUserDetails(final Map<String, Object> map, boolean isClientOnly) {
    if (map.containsKey(USER_ID)) {
        CustomUserDetails user = new CustomUserDetails((String) map.get("username"),
                "unknown password", Collections.emptyList());
        user.setOrganizationId((long) (Integer) map.get("organizationId"));
        if (map.get(USER_ID) != null) {
            user.setUserId((long) (Integer) map.get(USER_ID));
            user.setLanguage((String) map.get("language"));
            user.setAdmin((Boolean) map.get("admin"));
            user.setTimeZone((String) map.get("timeZone"));
            if (map.get("email") != null) {
                user.setEmail((String) map.get("email"));
            }
        }
        if (isClientOnly) {
            user.setClientId((long) (Integer) map.get("clientId"));
            user.setClientName((String) map.get("clientName"));
            user.setClientAccessTokenValiditySeconds((Integer) map.get("clientAccessTokenValiditySeconds"));
            user.setClientRefreshTokenValiditySeconds((Integer) map.get("clientRefreshTokenValiditySeconds"));
            user.setClientAuthorizedGrantTypes((Collection<String>) map.get("clientAuthorizedGrantTypes"));
            user.setClientAutoApproveScopes((Collection<String>) map.get("clientAutoApproveScopes"));
            user.setClientRegisteredRedirectUri((Collection<String>) map.get("clientRegisteredRedirectUri"));
            user.setClientResourceIds((Collection<String>) map.get("clientResourceIds"));
            user.setClientScope((Collection<String>) map.get("clientScope"));
        }
        try {
            if (map.get(ADDITION_INFO) != null) {
                user.setAdditionInfo((Map) map.get(ADDITION_INFO));
            }
        } catch (Exception e) {
            LOGGER.warn("Parser addition info error:{}", e);
        }
        return user;
    }
    return null;
}
 
Example #24
Source File: RequestContext.java    From api-gateway-old with Apache License 2.0 4 votes vote down vote up
public void setCustomUserDetails(CustomUserDetails customUserDetails) {
    this.customUserDetails = customUserDetails;
}
 
Example #25
Source File: ScheduleInstanceConsumerDTO.java    From choerodon-starters with Apache License 2.0 4 votes vote down vote up
public void setUserDetails(CustomUserDetails userDetails) {
    this.userDetails = userDetails;
}
 
Example #26
Source File: CustomUserDetailsWithResult.java    From api-gateway-old with Apache License 2.0 4 votes vote down vote up
public CustomUserDetails getCustomUserDetails() {
    return customUserDetails;
}
 
Example #27
Source File: CustomUserDetailsWithResult.java    From api-gateway-old with Apache License 2.0 4 votes vote down vote up
public CustomUserDetailsWithResult(CustomUserDetails customUserDetails, CheckState state) {
    this.customUserDetails = customUserDetails;
    this.state = state;
}
 
Example #28
Source File: CustomUserDetailsWithResult.java    From api-gateway-old with Apache License 2.0 4 votes vote down vote up
public void setCustomUserDetails(CustomUserDetails customUserDetails) {
    this.customUserDetails = customUserDetails;
}
 
Example #29
Source File: RequestContext.java    From api-gateway-old with Apache License 2.0 4 votes vote down vote up
public CustomUserDetails getCustomUserDetails() {
    return customUserDetails;
}
 
Example #30
Source File: ScheduleInstanceConsumerDTO.java    From choerodon-starters with Apache License 2.0 4 votes vote down vote up
public CustomUserDetails getUserDetails() {
    return userDetails;
}