containers = new ArrayList<>();
+ for (String containerName : containersNames) {
+ final Container container = mock(Container.class);
+ when(container.getName()).thenReturn(containerName);
+ when(container.getEnv()).thenReturn(new ArrayList<>());
+
+ containers.add(container);
+ }
+
+ when(podSpec.getContainers()).thenReturn(containers);
+
+ return pod;
+ }
}
}
diff --git a/multiuser/infrastructures/openshift/pom.xml b/multiuser/infrastructures/openshift/pom.xml
deleted file mode 100644
index a16370125b..0000000000
--- a/multiuser/infrastructures/openshift/pom.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
- 4.0.0
-
- che-multiuser-infrastructures-parent
- org.eclipse.che.multiuser
- 5.19.0-SNAPSHOT
- ../pom.xml
-
- multiuser-infrastructure-openshift
- 5.19.0-SNAPSHOT
- jar
- Che Multiuser OpenShift Infrastructure
-
-
- io.fabric8
- kubernetes-model
-
-
- javax.inject
- javax.inject
-
-
- org.eclipse.che
- infrastructure-openshift
-
-
- org.eclipse.che.core
- che-core-api-core
-
-
- org.eclipse.che.core
- che-core-api-model
-
-
- org.eclipse.che.core
- che-core-api-workspace
-
-
- org.eclipse.che.multiuser
- che-multiuser-machine-authentication
-
-
-
diff --git a/multiuser/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/installer/MultiuserInstallerConfigProvisioner.java b/multiuser/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/installer/MultiuserInstallerConfigProvisioner.java
deleted file mode 100644
index 192c3a99a9..0000000000
--- a/multiuser/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/installer/MultiuserInstallerConfigProvisioner.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2012-2017 Red Hat, Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- */
-package org.eclipse.che.workspace.infrastructure.openshift.provision.installer;
-
-import io.fabric8.kubernetes.api.model.Container;
-import javax.inject.Inject;
-import javax.inject.Named;
-import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
-import org.eclipse.che.api.workspace.server.spi.InternalMachineConfig;
-import org.eclipse.che.commons.env.EnvironmentContext;
-import org.eclipse.che.multiuser.machine.authentication.server.MachineTokenRegistry;
-import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
-
-/**
- * //TODO Fix java doc
- *
- * @author Sergii Leshchenko
- */
-public class MultiuserInstallerConfigProvisioner extends InstallerConfigProvisioner {
-
- private final MachineTokenRegistry tokenRegistry;
-
- @Inject
- public MultiuserInstallerConfigProvisioner(
- @Named("che.api") String cheServerEndpoint, MachineTokenRegistry tokenRegistry) {
- super(cheServerEndpoint);
- this.tokenRegistry = tokenRegistry;
- }
-
- @Override
- protected void doProvisionContainer(
- OpenShiftEnvironment osEnv,
- Container container,
- RuntimeIdentity identity,
- String machineName,
- InternalMachineConfig machineConf) {
- super.doProvisionContainer(osEnv, container, identity, machineName, machineConf);
-
- String currentUserId = EnvironmentContext.getCurrent().getSubject().getUserId();
- String machineToken = tokenRegistry.generateToken(currentUserId, identity.getWorkspaceId());
- putEnv(container.getEnv(), "USER_TOKEN", machineToken);
- }
-}
diff --git a/multiuser/infrastructures/pom.xml b/multiuser/infrastructures/pom.xml
deleted file mode 100644
index 72b51c3d03..0000000000
--- a/multiuser/infrastructures/pom.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
- 4.0.0
-
- che-multiuser-parent
- org.eclipse.che.multiuser
- 5.19.0-SNAPSHOT
- ../pom.xml
-
- che-multiuser-infrastructures-parent
- 5.19.0-SNAPSHOT
- pom
- Che Multiuser Infrastructures Parent
-
- openshift
-
-
diff --git a/multiuser/machine-auth/che-multiuser-machine-authentication/src/main/java/org/eclipse/che/multiuser/machine/authentication/server/MachineTokenProviderImpl.java b/multiuser/machine-auth/che-multiuser-machine-authentication/src/main/java/org/eclipse/che/multiuser/machine/authentication/server/MachineTokenProviderImpl.java
new file mode 100644
index 0000000000..2338ba1ab0
--- /dev/null
+++ b/multiuser/machine-auth/che-multiuser-machine-authentication/src/main/java/org/eclipse/che/multiuser/machine/authentication/server/MachineTokenProviderImpl.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012-2017 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ */
+package org.eclipse.che.multiuser.machine.authentication.server;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.eclipse.che.api.core.NotFoundException;
+import org.eclipse.che.api.workspace.server.token.MachineTokenException;
+import org.eclipse.che.api.workspace.server.token.MachineTokenProvider;
+import org.eclipse.che.commons.env.EnvironmentContext;
+
+/**
+ * Provides machine token from {@link MachineTokenRegistry}.
+ *
+ * Note that {@link MachineTokenRegistry} provides different tokens for different users. Token of
+ * current user will be provided for agents.
+ *
+ * @author Sergii Leshchenko
+ */
+@Singleton
+public class MachineTokenProviderImpl implements MachineTokenProvider {
+ private final MachineTokenRegistry tokenRegistry;
+
+ @Inject
+ public MachineTokenProviderImpl(MachineTokenRegistry tokenRegistry) {
+ this.tokenRegistry = tokenRegistry;
+ }
+
+ @Override
+ public String getToken(String workspaceId) throws MachineTokenException {
+ String currentUserId = EnvironmentContext.getCurrent().getSubject().getUserId();
+ try {
+ return tokenRegistry.getOrCreateToken(currentUserId, workspaceId);
+ } catch (NotFoundException e) {
+ throw new MachineTokenException(e.getMessage(), e);
+ }
+ }
+}
diff --git a/multiuser/pom.xml b/multiuser/pom.xml
index 59e3949515..b4d1abf416 100644
--- a/multiuser/pom.xml
+++ b/multiuser/pom.xml
@@ -30,7 +30,6 @@
keycloak
machine-auth
personal-account
- infrastructures
integration-tests
diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/hc/ServersReadinessChecker.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/hc/ServersReadinessChecker.java
index 7ced6faf78..364dff990c 100644
--- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/hc/ServersReadinessChecker.java
+++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/hc/ServersReadinessChecker.java
@@ -27,6 +27,7 @@ import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.core.model.workspace.runtime.Server;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
+import org.eclipse.che.api.workspace.server.token.MachineTokenProvider;
/**
* Checks readiness of servers of a machine.
diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/token/MachineTokenException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/token/MachineTokenException.java
new file mode 100644
index 0000000000..cbfdb0f82f
--- /dev/null
+++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/token/MachineTokenException.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012-2017 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ */
+package org.eclipse.che.api.workspace.server.token;
+
+import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
+
+/**
+ * An exception thrown by {@link MachineTokenProvider} when an error occurred during token fetching
+ * operation execution.
+ *
+ * @author Sergii Leshchenko
+ */
+public class MachineTokenException extends InfrastructureException {
+ public MachineTokenException(String message) {
+ super(message);
+ }
+
+ public MachineTokenException(Exception e) {
+ super(e);
+ }
+
+ public MachineTokenException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/token/MachineTokenProvider.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/token/MachineTokenProvider.java
new file mode 100644
index 0000000000..8b945a3337
--- /dev/null
+++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/token/MachineTokenProvider.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012-2017 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ */
+package org.eclipse.che.api.workspace.server.token;
+
+/**
+ * Provides machine token that should be used for access to workspace master from machine.
+ *
+ * @author Sergii Leshchenko
+ */
+public interface MachineTokenProvider {
+
+ /**
+ * Returns machine token for specified workspace.
+ *
+ * @param workspaceId identifier of workspace to fetch token
+ * @throws MachineTokenException when any exception occurs on token fetching
+ */
+ String getToken(String workspaceId) throws MachineTokenException;
+
+ /** Returns empty string as machine token. */
+ class EmptyMachineTokenProvider implements MachineTokenProvider {
+ @Override
+ public String getToken(String workspaceId) {
+ return "";
+ }
+ }
+}