@Test public void returnsConfigUsingOwnerSubject() throws Exception { Config config = factory.buildConfig(defaultConfig, WS_ID); assertEquals(config, expectedConfig); verify(environmentProvider).getWorkspacesOpenshiftConfig(eq(ownerSubject)); }
@Override public Config buildConfig(Config defaultConfig, @Nullable String workspaceId) throws InfrastructureException { Subject subject = EnvironmentContext.getCurrent().getSubject(); if (workspaceId == null && (subject == null || subject.isAnonymous())) { return defaultConfig; } if (workspaceId != null) { Optional<RuntimeIdentity> runtimeIdentity = getRuntimeIdentity(workspaceId); if (runtimeIdentity.isPresent()) { String userIdFromWorkspaceId = runtimeIdentity.get().getOwnerId(); if (!userIdFromWorkspaceId.equals(subject.getUserId())) { try { subject = subjectsRegistry.getSubject(userIdFromWorkspaceId); } catch (NotFoundException e) { Optional<KubernetesRuntimeState> runtimeState = runtimeStateCache.get(runtimeIdentity.get()); if (cheServiceAccountTokenToggle.useCheServiceAccountToken(userIdFromWorkspaceId) && runtimeState.isPresent()) { LOG.debug( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache.\n" + "Let's search inside the running workspace runtime state, if any, to find the user namespace", subject.getUserId(), userIdFromWorkspaceId, workspaceId); subject = new GuessedSubject(userIdFromWorkspaceId, runtimeState.get().getNamespace()); } else { LOG.warn( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache", subject.getUserId(), userIdFromWorkspaceId, workspaceId); } } } } else { LOG.warn( "Could not get runtimeIdentity for workspace '{}', and so cannot verify " + "if current subject '{}' owns workspace", workspaceId, subject.getUserId()); } } return envProvider.getWorkspacesOpenshiftConfig(subject); }
Fabric8OpenShiftClientFactory extends OpenShiftClientFactory { @Override public Config buildConfig(Config defaultConfig, @Nullable String workspaceId) throws InfrastructureException { Subject subject = EnvironmentContext.getCurrent().getSubject(); if (workspaceId == null && (subject == null || subject.isAnonymous())) { return defaultConfig; } if (workspaceId != null) { Optional<RuntimeIdentity> runtimeIdentity = getRuntimeIdentity(workspaceId); if (runtimeIdentity.isPresent()) { String userIdFromWorkspaceId = runtimeIdentity.get().getOwnerId(); if (!userIdFromWorkspaceId.equals(subject.getUserId())) { try { subject = subjectsRegistry.getSubject(userIdFromWorkspaceId); } catch (NotFoundException e) { Optional<KubernetesRuntimeState> runtimeState = runtimeStateCache.get(runtimeIdentity.get()); if (cheServiceAccountTokenToggle.useCheServiceAccountToken(userIdFromWorkspaceId) && runtimeState.isPresent()) { LOG.debug( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache.\n" + "Let's search inside the running workspace runtime state, if any, to find the user namespace", subject.getUserId(), userIdFromWorkspaceId, workspaceId); subject = new GuessedSubject(userIdFromWorkspaceId, runtimeState.get().getNamespace()); } else { LOG.warn( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache", subject.getUserId(), userIdFromWorkspaceId, workspaceId); } } } } else { LOG.warn( "Could not get runtimeIdentity for workspace '{}', and so cannot verify " + "if current subject '{}' owns workspace", workspaceId, subject.getUserId()); } } return envProvider.getWorkspacesOpenshiftConfig(subject); } }
Fabric8OpenShiftClientFactory extends OpenShiftClientFactory { @Override public Config buildConfig(Config defaultConfig, @Nullable String workspaceId) throws InfrastructureException { Subject subject = EnvironmentContext.getCurrent().getSubject(); if (workspaceId == null && (subject == null || subject.isAnonymous())) { return defaultConfig; } if (workspaceId != null) { Optional<RuntimeIdentity> runtimeIdentity = getRuntimeIdentity(workspaceId); if (runtimeIdentity.isPresent()) { String userIdFromWorkspaceId = runtimeIdentity.get().getOwnerId(); if (!userIdFromWorkspaceId.equals(subject.getUserId())) { try { subject = subjectsRegistry.getSubject(userIdFromWorkspaceId); } catch (NotFoundException e) { Optional<KubernetesRuntimeState> runtimeState = runtimeStateCache.get(runtimeIdentity.get()); if (cheServiceAccountTokenToggle.useCheServiceAccountToken(userIdFromWorkspaceId) && runtimeState.isPresent()) { LOG.debug( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache.\n" + "Let's search inside the running workspace runtime state, if any, to find the user namespace", subject.getUserId(), userIdFromWorkspaceId, workspaceId); subject = new GuessedSubject(userIdFromWorkspaceId, runtimeState.get().getNamespace()); } else { LOG.warn( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache", subject.getUserId(), userIdFromWorkspaceId, workspaceId); } } } } else { LOG.warn( "Could not get runtimeIdentity for workspace '{}', and so cannot verify " + "if current subject '{}' owns workspace", workspaceId, subject.getUserId()); } } return envProvider.getWorkspacesOpenshiftConfig(subject); } @Inject  Fabric8OpenShiftClientFactory(
      Fabric8WorkspaceEnvironmentProvider envProvider,
      Provider<WorkspaceRuntimes> workspaceRuntimeProvider,
      WorkspaceSubjectsRegistry subjectsRegistry,
      KubernetesRuntimeStateCache runtimeStateCache,
      CheServiceAccountTokenToggle cheServiceAccountTokenToggle,
      @Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts,
      @Named("che.infra.kubernetes.client.http.async_requests.max") int maxConcurrentRequests,
      @Named("che.infra.kubernetes.client.http.async_requests.max_per_host")
          int maxConcurrentRequestsPerHost,
      @Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
      @Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
          int connectionPoolKeepAlive,
      EventListener eventListener); }
Fabric8OpenShiftClientFactory extends OpenShiftClientFactory { @Override public Config buildConfig(Config defaultConfig, @Nullable String workspaceId) throws InfrastructureException { Subject subject = EnvironmentContext.getCurrent().getSubject(); if (workspaceId == null && (subject == null || subject.isAnonymous())) { return defaultConfig; } if (workspaceId != null) { Optional<RuntimeIdentity> runtimeIdentity = getRuntimeIdentity(workspaceId); if (runtimeIdentity.isPresent()) { String userIdFromWorkspaceId = runtimeIdentity.get().getOwnerId(); if (!userIdFromWorkspaceId.equals(subject.getUserId())) { try { subject = subjectsRegistry.getSubject(userIdFromWorkspaceId); } catch (NotFoundException e) { Optional<KubernetesRuntimeState> runtimeState = runtimeStateCache.get(runtimeIdentity.get()); if (cheServiceAccountTokenToggle.useCheServiceAccountToken(userIdFromWorkspaceId) && runtimeState.isPresent()) { LOG.debug( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache.\n" + "Let's search inside the running workspace runtime state, if any, to find the user namespace", subject.getUserId(), userIdFromWorkspaceId, workspaceId); subject = new GuessedSubject(userIdFromWorkspaceId, runtimeState.get().getNamespace()); } else { LOG.warn( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache", subject.getUserId(), userIdFromWorkspaceId, workspaceId); } } } } else { LOG.warn( "Could not get runtimeIdentity for workspace '{}', and so cannot verify " + "if current subject '{}' owns workspace", workspaceId, subject.getUserId()); } } return envProvider.getWorkspacesOpenshiftConfig(subject); } @Inject  Fabric8OpenShiftClientFactory(
      Fabric8WorkspaceEnvironmentProvider envProvider,
      Provider<WorkspaceRuntimes> workspaceRuntimeProvider,
      WorkspaceSubjectsRegistry subjectsRegistry,
      KubernetesRuntimeStateCache runtimeStateCache,
      CheServiceAccountTokenToggle cheServiceAccountTokenToggle,
      @Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts,
      @Named("che.infra.kubernetes.client.http.async_requests.max") int maxConcurrentRequests,
      @Named("che.infra.kubernetes.client.http.async_requests.max_per_host")
          int maxConcurrentRequestsPerHost,
      @Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
      @Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
          int connectionPoolKeepAlive,
      EventListener eventListener); @Override Config buildConfig(Config defaultConfig, @Nullable String workspaceId); }
Fabric8OpenShiftClientFactory extends OpenShiftClientFactory { @Override public Config buildConfig(Config defaultConfig, @Nullable String workspaceId) throws InfrastructureException { Subject subject = EnvironmentContext.getCurrent().getSubject(); if (workspaceId == null && (subject == null || subject.isAnonymous())) { return defaultConfig; } if (workspaceId != null) { Optional<RuntimeIdentity> runtimeIdentity = getRuntimeIdentity(workspaceId); if (runtimeIdentity.isPresent()) { String userIdFromWorkspaceId = runtimeIdentity.get().getOwnerId(); if (!userIdFromWorkspaceId.equals(subject.getUserId())) { try { subject = subjectsRegistry.getSubject(userIdFromWorkspaceId); } catch (NotFoundException e) { Optional<KubernetesRuntimeState> runtimeState = runtimeStateCache.get(runtimeIdentity.get()); if (cheServiceAccountTokenToggle.useCheServiceAccountToken(userIdFromWorkspaceId) && runtimeState.isPresent()) { LOG.debug( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache.\n" + "Let's search inside the running workspace runtime state, if any, to find the user namespace", subject.getUserId(), userIdFromWorkspaceId, workspaceId); subject = new GuessedSubject(userIdFromWorkspaceId, runtimeState.get().getNamespace()); } else { LOG.warn( "Current user ID ('{}') is different from the user ID ('{}') that started workspace {} " + "and subject of user that started workspace is not found in subjects cache", subject.getUserId(), userIdFromWorkspaceId, workspaceId); } } } } else { LOG.warn( "Could not get runtimeIdentity for workspace '{}', and so cannot verify " + "if current subject '{}' owns workspace", workspaceId, subject.getUserId()); } } return envProvider.getWorkspacesOpenshiftConfig(subject); } @Inject  Fabric8OpenShiftClientFactory(
      Fabric8WorkspaceEnvironmentProvider envProvider,
      Provider<WorkspaceRuntimes> workspaceRuntimeProvider,
      WorkspaceSubjectsRegistry subjectsRegistry,
      KubernetesRuntimeStateCache runtimeStateCache,
      CheServiceAccountTokenToggle cheServiceAccountTokenToggle,
      @Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts,
      @Named("che.infra.kubernetes.client.http.async_requests.max") int maxConcurrentRequests,
      @Named("che.infra.kubernetes.client.http.async_requests.max_per_host")
          int maxConcurrentRequestsPerHost,
      @Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
      @Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
          int connectionPoolKeepAlive,
      EventListener eventListener); @Override Config buildConfig(Config defaultConfig, @Nullable String workspaceId);  }