use of bio.terra.stairway.exception.FlightNotFoundException in project terra-workspace-manager by DataBiosphere.
the class JobService method verifyUserAccess.
/**
* Ensure the user in the user request has permission to read the workspace associated with the
* Job ID. Throws ForbiddenException if not.
*
* @param jobId - ID of running job
* @param userRequest - original user request
*/
private void verifyUserAccess(String jobId, AuthenticatedUserRequest userRequest) {
try {
FlightState flightState = stairwayComponent.get().getFlightState(jobId);
FlightMap inputParameters = flightState.getInputParameters();
UUID workspaceId = inputParameters.get(WorkspaceFlightMapKeys.WORKSPACE_ID, UUID.class);
flightBeanBag.getWorkspaceService().validateWorkspaceAndAction(userRequest, workspaceId, SamWorkspaceAction.READ);
} catch (DatabaseOperationException | InterruptedException ex) {
throw new InternalStairwayException("Stairway exception looking up the job", ex);
} catch (FlightNotFoundException ex) {
throw new JobNotFoundException("Job not found", ex);
}
}
use of bio.terra.stairway.exception.FlightNotFoundException in project terra-workspace-manager by DataBiosphere.
the class LaunchCreateGcpContextFlightStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
validateRequiredEntries(context.getInputParameters(), ControlledResourceKeys.SOURCE_WORKSPACE_ID, JobMapKeys.AUTH_USER_INFO.getKeyName(), JobMapKeys.REQUEST.getKeyName());
validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.CREATE_CLOUD_CONTEXT_FLIGHT_ID);
final var userRequest = context.getInputParameters().get(JobMapKeys.AUTH_USER_INFO.getKeyName(), AuthenticatedUserRequest.class);
final var destinationWorkspace = context.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), Workspace.class);
final var cloudContextJobId = context.getWorkingMap().get(ControlledResourceKeys.CREATE_CLOUD_CONTEXT_FLIGHT_ID, String.class);
boolean flightAlreadyExists;
try {
context.getStairway().getFlightState(cloudContextJobId);
flightAlreadyExists = true;
} catch (FlightNotFoundException e) {
flightAlreadyExists = false;
} catch (DatabaseOperationException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
// if we already have a flight, don't launch another one
if (!flightAlreadyExists) {
workspaceService.createGcpCloudContext(destinationWorkspace.getWorkspaceId(), cloudContextJobId, userRequest);
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.stairway.exception.FlightNotFoundException in project jade-data-repo by DataBiosphere.
the class JobService method verifyUserAccess.
private void verifyUserAccess(String jobId, AuthenticatedUserRequest userReq) {
try {
FlightState flightState = stairway.getFlightState(jobId);
FlightMap inputParameters = flightState.getInputParameters();
String flightSubjectId = inputParameters.get(JobMapKeys.SUBJECT_ID.getKeyName(), String.class);
if (!StringUtils.equals(flightSubjectId, userReq.getSubjectId())) {
throw new JobUnauthorizedException("Unauthorized");
}
} catch (DatabaseOperationException ex) {
throw new InternalStairwayException("Stairway exception looking up the job", ex);
} catch (FlightNotFoundException ex) {
throw new JobNotFoundException("Job not found", ex);
} catch (InterruptedException ex) {
throw new JobServiceShutdownException("Job service interrupted", ex);
}
}
Aggregations