Search in sources :

Example 1 with NotAuthorizedException

use of com.thoughtworks.go.config.exceptions.NotAuthorizedException in project gocd by gocd.

the class FeedService method stagesXml.

public Document stagesXml(Username username, String pipelineName, Integer pipelineCounter, String baseUrl) {
    if (!goConfigService.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) {
        throw new RecordNotFoundException(EntityType.Pipeline, pipelineName);
    }
    if (!securityService.hasViewPermissionForPipeline(username, pipelineName)) {
        throw new NotAuthorizedException(NOT_AUTHORIZED_TO_VIEW_PIPELINE);
    }
    FeedEntries feedEntries = stageService.findStageFeedBy(pipelineName, pipelineCounter, FeedModifier.Before, username);
    FeedEntriesRepresenter representable = new FeedEntriesRepresenter(pipelineName, feedEntries);
    return xmlApiService.write(representable, baseUrl);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 2 with NotAuthorizedException

use of com.thoughtworks.go.config.exceptions.NotAuthorizedException in project gocd by gocd.

the class PipelineHistoryService method load.

public PipelineInstanceModel load(String pipelineName, Integer pipelineCounter, Username username) {
    PipelineInstanceModel pipeline = pipelineDao.findPipelineHistoryByNameAndCounter(pipelineName, pipelineCounter);
    if (pipeline == null) {
        throw new RecordNotFoundException(EntityType.PipelineInstance, pipelineCounter);
    }
    PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipeline.getName()));
    if (!securityService.hasViewPermissionForPipeline(username, pipeline.getName())) {
        throw new NotAuthorizedException(NOT_AUTHORIZED_TO_VIEW_PIPELINE);
    }
    populatePipelineInstanceModel(username, false, pipelineConfig, pipeline);
    return pipeline;
}
Also used : RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 3 with NotAuthorizedException

use of com.thoughtworks.go.config.exceptions.NotAuthorizedException in project gocd by gocd.

the class ScheduleServiceStageTriggerTest method shouldNotNotifyListenersForWhenCancelStageTransactionRollsback.

@Test
public void shouldNotNotifyListenersForWhenCancelStageTransactionRollsback() throws Exception {
    Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    final Stage stage = oldest.getStages().byName(preCondition.ftStage);
    final StageIdentifier identifier = stage.getIdentifier();
    StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
    JobResultTopic jobResultTopic = mock(JobResultTopic.class);
    StageStatusListener stageStatusListener = mock(StageStatusListener.class);
    JobInstanceService jobInstanceService = jobInstanceService(jobResultTopic);
    StageService stageService = new StageService(stageDao, jobInstanceService, stageStatusTopic, stageStatusCache, securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, stageStatusListener);
    SchedulingPerformanceLogger schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    scheduleService = new ScheduleService(goConfigService, pipelineService, stageService, schedulingCheckerService, pipelineDao, stageDao, stageOrderService, securityService, pipelineScheduleQueue, this.jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService, pipelineLockService, serverHealthService, transactionTemplate, null, transactionSynchronizationManager, null, null, null, null, schedulingPerformanceLogger, null, null);
    try {
        transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

            @Override
            public Object doInTransaction(TransactionStatus status) throws Exception {
                scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
                throw new NotAuthorizedException("blah");
            }
        });
    } catch (Exception e) {
    // ignore
    }
    verify(stageStatusTopic, never()).post(any(StageStatusMessage.class));
    verify(jobResultTopic, never()).post(any(JobResultMessage.class));
    verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) TransactionStatus(org.springframework.transaction.TransactionStatus) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.jupiter.api.Test)

Example 4 with NotAuthorizedException

use of com.thoughtworks.go.config.exceptions.NotAuthorizedException in project gocd by gocd.

the class MaterialConfigService method getMaterialConfig.

public MaterialConfig getMaterialConfig(String username, String materialFingerprint) {
    MaterialConfig materialConfig = null;
    boolean hasViewPermissionForMaterial = false;
    boolean hasOperatePermissionForMaterial = false;
    for (PipelineConfigs pipelineGroup : goConfigService.groups()) {
        boolean hasViewPermissionForGroup = securityService.hasViewPermissionForGroup(username, pipelineGroup.getGroup());
        boolean hasOperatePermissionForGroup = securityService.hasOperatePermissionForGroup(new CaseInsensitiveString(username), pipelineGroup.getGroup());
        for (PipelineConfig pipelineConfig : pipelineGroup) {
            for (MaterialConfig currentMaterialConfig : pipelineConfig.materialConfigs()) {
                if (currentMaterialConfig.getFingerprint().equals(materialFingerprint)) {
                    materialConfig = currentMaterialConfig;
                    hasViewPermissionForMaterial = hasViewPermissionForMaterial || hasViewPermissionForGroup;
                    if (hasOperatePermissionForGroup) {
                        hasOperatePermissionForMaterial = hasOperatePermissionForGroup;
                        break;
                    }
                }
            }
        }
    }
    if (materialConfig == null) {
        throw new RecordNotFoundException("Material not found");
    }
    if (!hasViewPermissionForMaterial) {
        throw new NotAuthorizedException("Do not have view permission to this material");
    }
    if (!hasOperatePermissionForMaterial) {
        throw new NotAuthorizedException("Do not have permission to trigger this material");
    }
    return materialConfig;
}
Also used : RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) PipelineConfigs(com.thoughtworks.go.config.PipelineConfigs) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Aggregations

NotAuthorizedException (com.thoughtworks.go.config.exceptions.NotAuthorizedException)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)1 FeedEntries (com.thoughtworks.go.domain.feed.FeedEntries)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)1 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)1 JobResultTopic (com.thoughtworks.go.server.messaging.JobResultTopic)1 StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)1 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)1 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 Test (org.junit.jupiter.api.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1