return token; } catch (SignatureKeyManagerException | NotFoundException | ServerException ex) { throw new MachineTokenException( format( "Failed to generate machine token for user '%s' and workspace '%s'. Cause: '%s'",
throw new InternalInfrastructureException( "Failed to retrieve workspace token for ws-agent server liveness probe. Error: " + e.getMessage()); } catch (UriBuilderException e) { throw new InternalInfrastructureException(
private WorkspaceDto asDtoWithLinksAndToken(Workspace workspace) throws ServerException { WorkspaceDto workspaceDto = asDto(workspace).withLinks(linksGenerator.genLinks(workspace, getServiceContext())); RuntimeDto runtimeDto = workspaceDto.getRuntime(); if (runtimeDto != null) { try { runtimeDto.setMachineToken(machineTokenProvider.getToken(workspace.getId())); } catch (MachineAccessForbidden e) { // set runtime to null since user doesn't have the required permissions workspaceDto.setRuntime(null); } catch (MachineTokenException e) { throw new ServerException(e.getMessage(), e); } } return workspaceDto; }
@Override public String getToken(String userId, String workspaceId) throws MachineTokenException { try { if (!permissionChecker.hasPermission(userId, DOMAIN_ID, workspaceId, USE)) { throw new MachineAccessForbidden( format( "The user `%s` doesn't have the required `use` permission for workspace `%s`", userId, workspaceId)); } } catch (ServerException | NotFoundException | ConflictException e) { throw new MachineTokenException(e.getMessage(), e); } return tokenRegistry.getOrCreateToken(userId, workspaceId); } }