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);
}
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;
}
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));
}
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;
}
Aggregations