Skip to content

Commit

Permalink
Merge pull request #6700 from sleshchenko/CHE-6587
Browse files Browse the repository at this point in the history
Added MachineTokenProvider interface with different implementations
  • Loading branch information
sleshchenko authored Oct 13, 2017
2 parents 1450590 + 2b7bba7 commit 95aa8bd
Show file tree
Hide file tree
Showing 48 changed files with 734 additions and 586 deletions.
4 changes: 0 additions & 4 deletions assembly-multiuser/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>che-multiuser-sql-schema</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.multiuser</groupId>
<artifactId>multiuser-infrastructure-openshift</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-activity-wsmaster</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,28 @@
import org.eclipse.che.api.user.server.jpa.JpaUserDao;
import org.eclipse.che.api.user.server.spi.PreferenceDao;
import org.eclipse.che.api.user.server.spi.UserDao;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactoryImpl;
import org.eclipse.che.commons.auth.token.ChainedTokenExtractor;
import org.eclipse.che.commons.auth.token.RequestTokenExtractor;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.mail.template.ST.STTemplateProcessorImpl;
import org.eclipse.che.mail.template.TemplateProcessor;
import org.eclipse.che.multiuser.api.permission.server.AdminPermissionInitializer;
import org.eclipse.che.multiuser.api.permission.server.PermissionChecker;
import org.eclipse.che.multiuser.api.permission.server.PermissionCheckerImpl;
import org.eclipse.che.multiuser.keycloak.server.deploy.KeycloakModule;
import org.eclipse.che.multiuser.machine.authentication.server.AuthServerCheckerFactoryImpl;
import org.eclipse.che.multiuser.machine.authentication.server.MachineAuthModule;
import org.eclipse.che.multiuser.organization.api.OrganizationApiModule;
import org.eclipse.che.multiuser.organization.api.OrganizationJpaModule;
import org.eclipse.che.multiuser.resource.api.ResourceModule;
import org.eclipse.che.security.PBKDF2PasswordEncryptor;
import org.eclipse.che.security.PasswordEncryptor;
import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftInfraModule;
import org.eclipse.che.workspace.infrastructure.openshift.provision.installer.InstallerConfigProvisioner;
import org.eclipse.che.workspace.infrastructure.openshift.provision.installer.MultiuserInstallerConfigProvisioner;

@DynaModule
public class MultiUserCheWsMasterModule extends AbstractModule {

@Override
protected void configure() {
bind(ServerCheckerFactoryImpl.class).to(AuthServerCheckerFactoryImpl.class);
bind(InstallerConfigProvisioner.class).to(MultiuserInstallerConfigProvisioner.class);
install(new OpenShiftInfraModule());

bind(TemplateProcessor.class).to(STTemplateProcessorImpl.class);
Expand Down Expand Up @@ -75,6 +72,9 @@ protected void configure() {

install(new KeycloakModule());

install(new MachineAuthModule());
bind(RequestTokenExtractor.class).to(ChainedTokenExtractor.class);

//User and profile - use profile from keycloak and other stuff is JPA
bind(PasswordEncryptor.class).to(PBKDF2PasswordEncryptor.class);
bind(UserDao.class).to(JpaUserDao.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.inject.name.Names;
import javax.sql.DataSource;
import org.eclipse.che.api.user.server.TokenValidator;
import org.eclipse.che.api.workspace.server.token.MachineTokenProvider;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.workspace.infrastructure.docker.DockerInfraModule;
import org.eclipse.che.workspace.infrastructure.docker.local.LocalDockerModule;
Expand All @@ -38,6 +39,7 @@ protected void configure() {
}

bind(TokenValidator.class).to(org.eclipse.che.api.local.DummyTokenValidator.class);
bind(MachineTokenProvider.class).to(MachineTokenProvider.EmptyMachineTokenProvider.class);

bind(org.eclipse.che.api.workspace.server.stack.StackLoader.class);
bind(DataSource.class).toProvider(org.eclipse.che.core.db.h2.H2DataSourceProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
Expand All @@ -38,8 +39,7 @@
import org.eclipse.che.api.workspace.server.adapter.StackMessageBodyAdapter;
import org.eclipse.che.api.workspace.server.adapter.WorkspaceConfigMessageBodyAdapter;
import org.eclipse.che.api.workspace.server.adapter.WorkspaceMessageBodyAdapter;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactoryImpl;
import org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory;
import org.eclipse.che.api.workspace.server.stack.StackLoader;
import org.eclipse.che.core.db.schema.SchemaInitializer;
import org.eclipse.che.inject.DynaModule;
Expand Down Expand Up @@ -99,6 +99,8 @@ protected void configure() {
bind(org.eclipse.che.api.workspace.server.stack.StackService.class);
bind(org.eclipse.che.api.workspace.server.TemporaryWorkspaceRemover.class);
bind(org.eclipse.che.api.workspace.server.WorkspaceService.class);
install(new FactoryModuleBuilder().build(ServersCheckerFactory.class));

bind(org.eclipse.che.api.workspace.server.bootstrap.InstallerService.class);
bind(org.eclipse.che.api.workspace.server.event.WorkspaceMessenger.class).asEagerSingleton();
bind(org.eclipse.che.api.workspace.server.event.WorkspaceJsonRpcMessenger.class)
Expand Down Expand Up @@ -162,8 +164,6 @@ protected void configure() {
// bind(org.eclipse.che.api.agent.server.filters.AddExecInstallerInWorkspaceFilter.class);
// bind(org.eclipse.che.api.agent.server.filters.AddExecInstallerInStackFilter.class);

bind(ServerCheckerFactory.class).to(ServerCheckerFactoryImpl.class);

bind(org.eclipse.che.api.user.server.AppStatesPreferenceCleaner.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public H2JpaCleaner(DataSource dataSource) {
this.dataSource = dataSource;
}

/** @deprecated use {@link H2JpaCleaner(H2DBTestServer)} instead. */
@Deprecated
public H2JpaCleaner() {
this(H2TestHelper.inMemoryDefault());
}

@Override
public void clean() {
super.clean();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.eclipse.che.api.workspace.server.DtoConverter;
import org.eclipse.che.api.workspace.server.URLRewriter;
import org.eclipse.che.api.workspace.server.WsAgentMachineFinderUtil;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServersReadinessChecker;
import org.eclipse.che.api.workspace.server.hc.ServersChecker;
import org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory;
import org.eclipse.che.api.workspace.server.model.impl.MachineImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
Expand Down Expand Up @@ -78,7 +78,7 @@ public class DockerInternalRuntime extends InternalRuntime<DockerRuntimeContext>
private final DockerRegistryClient dockerRegistryClient;
private final EventService eventService;
private final DockerBootstrapperFactory bootstrapperFactory;
private final ServerCheckerFactory serverCheckerFactory;
private final ServersCheckerFactory serverCheckerFactory;
private final MachineLoggersFactory loggers;

/**
Expand All @@ -95,7 +95,7 @@ public DockerInternalRuntime(
DockerRegistryClient dockerRegistryClient,
EventService eventService,
DockerBootstrapperFactory bootstrapperFactory,
ServerCheckerFactory serverCheckerFactory,
ServersCheckerFactory serverCheckerFactory,
MachineLoggersFactory loggers) {
this(
context,
Expand Down Expand Up @@ -126,7 +126,7 @@ public DockerInternalRuntime(
DockerRegistryClient dockerRegistryClient,
EventService eventService,
DockerBootstrapperFactory bootstrapperFactory,
ServerCheckerFactory serverCheckerFactory,
ServersCheckerFactory serverCheckerFactory,
MachineLoggersFactory loggers,
DockerMachineCreator machineCreator,
DockerMachineStopDetector stopDetector)
Expand Down Expand Up @@ -164,7 +164,7 @@ private DockerInternalRuntime(
DockerRegistryClient dockerRegistryClient,
EventService eventService,
DockerBootstrapperFactory bootstrapperFactory,
ServerCheckerFactory serverCheckerFactory,
ServersCheckerFactory serverCheckerFactory,
MachineLoggersFactory loggers) {
super(context, urlRewriter, running);
this.networks = networks;
Expand Down Expand Up @@ -287,9 +287,8 @@ void checkServers() throws InfrastructureException {
startSynchronizer.getMachines().entrySet()) {
String name = entry.getKey();
DockerMachine machine = entry.getValue();
ServersReadinessChecker checker =
new ServersReadinessChecker(
getContext().getIdentity(), name, machine.getServers(), serverCheckerFactory);
ServersChecker checker =
serverCheckerFactory.create(getContext().getIdentity(), name, machine.getServers());
checker.checkOnce(new ServerReadinessHandler(name));
}
}
Expand Down Expand Up @@ -320,9 +319,8 @@ private void startMachine(String name, DockerContainerConfig containerConfig)
}

checkInterruption();
ServersReadinessChecker readinessChecker =
new ServersReadinessChecker(
getContext().getIdentity(), name, machine.getServers(), serverCheckerFactory);
ServersChecker readinessChecker =
serverCheckerFactory.create(getContext().getIdentity(), name, machine.getServers());
readinessChecker.startAsync(new ServerReadinessHandler(name));
readinessChecker.await();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,33 @@

import static org.eclipse.che.workspace.infrastructure.docker.DockerMachine.USER_TOKEN;

import javax.inject.Inject;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.commons.env.EnvironmentContext;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.token.MachineTokenProvider;
import org.eclipse.che.commons.lang.Pair;

/**
* Provides environment variable with a token that should be used by servers in a container to
* access Che master API.
*
* @author Alexander Garagatyi
* @author Sergii Leshchenko
*/
public class UserTokenEnvVarProvider implements ServerEnvironmentVariableProvider {
private final MachineTokenProvider machineTokenProvider;

@Inject
public UserTokenEnvVarProvider(MachineTokenProvider machineTokenProvider) {
this.machineTokenProvider = machineTokenProvider;
}

@Override
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) {
return Pair.of(USER_TOKEN, EnvironmentContext.getCurrent().getSubject().getToken());
try {
return Pair.of(USER_TOKEN, machineTokenProvider.getToken(runtimeIdentity.getWorkspaceId()));
} catch (InfrastructureException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.installer.server.model.impl.InstallerImpl;
import org.eclipse.che.api.workspace.server.DtoConverter;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServersChecker;
import org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory;
import org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalEnvironment;
Expand Down Expand Up @@ -112,6 +113,9 @@ public void setup() throws Exception {
when(internalEnvironment.getMachines())
.thenReturn(
ImmutableMap.of(DEV_MACHINE, internalMachineCfg1, DB_MACHINE, internalMachineCfg2));
ServersCheckerFactory serversCheckerFactory = mock(ServersCheckerFactory.class);
when(serversCheckerFactory.create(any(), anyString(), any()))
.thenReturn(mock(ServersChecker.class));
dockerRuntime =
new DockerInternalRuntime(
runtimeContext,
Expand All @@ -122,7 +126,7 @@ public void setup() throws Exception {
mock(DockerRegistryClient.class),
eventService,
bootstrapperFactory,
mock(ServerCheckerFactory.class),
serversCheckerFactory,
mock(MachineLoggersFactory.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.workspace.server.DtoConverter;
import org.eclipse.che.api.workspace.server.URLRewriter;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServersReadinessChecker;
import org.eclipse.che.api.workspace.server.hc.ServersChecker;
import org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory;
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.spi.InternalRuntime;
Expand All @@ -63,7 +63,7 @@ public class OpenShiftInternalRuntime extends InternalRuntime<OpenShiftRuntimeCo
private static final String POD_FAILED_STATUS = "Failed";

private final EventService eventService;
private final ServerCheckerFactory serverCheckerFactory;
private final ServersCheckerFactory serverCheckerFactory;
private final OpenShiftBootstrapperFactory bootstrapperFactory;
private final Map<String, OpenShiftMachine> machines;
private final int machineStartTimeoutMin;
Expand All @@ -76,7 +76,7 @@ public OpenShiftInternalRuntime(
URLRewriter.NoOpURLRewriter urlRewriter,
EventService eventService,
OpenShiftBootstrapperFactory bootstrapperFactory,
ServerCheckerFactory serverCheckerFactory,
ServersCheckerFactory serverCheckerFactory,
@Named("che.infra.openshift.machine_start_timeout_min") int machineStartTimeoutMin) {
super(context, urlRewriter, false);
this.eventService = eventService;
Expand Down Expand Up @@ -198,12 +198,9 @@ private void bootstrapMachine(OpenShiftMachine machine)
*/
private void checkMachineServers(OpenShiftMachine machine)
throws InfrastructureException, InterruptedException {
final ServersReadinessChecker check =
new ServersReadinessChecker(
getContext().getIdentity(),
machine.getName(),
machine.getServers(),
serverCheckerFactory);
final ServersChecker check =
serverCheckerFactory.create(
getContext().getIdentity(), machine.getName(), machine.getServers());
check.startAsync(new ServerReadinessHandler(machine.getName()));
check.await();
}
Expand Down
Loading

0 comments on commit 95aa8bd

Please sign in to comment.