Drop single user support on Che Server (#89)
* refactor: removed singleuser support from assembly-wsmaster Signed-off-by: xbaran4 <pbaran@redhat.com> * refactor: lincense format Signed-off-by: xbaran4 <pbaran@redhat.com> * refactor: removed singleuser h2db classes Signed-off-by: xbaran4 <pbaran@redhat.com> * refactor: moved DummyTokenValidator Signed-off-by: xbaran4 <pbaran@redhat.com> * refactor: removed wsmaster-local dependency Signed-off-by: xbaran4 <pbaran@redhat.com> * Removed unused parameter * Cleanup in DS. Removed h2 dependencies * Updated DummyTokenValidator Co-authored-by: Sergii Kabashniuk <skabashniuk@redhat.com>pull/80/head
parent
981c04c41e
commit
cead406cf4
|
|
@ -59,10 +59,6 @@
|
|||
<groupId>com.google.inject.extensions</groupId>
|
||||
<artifactId>guice-servlet</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jaegertracing</groupId>
|
||||
<artifactId>jaeger-client</artifactId>
|
||||
|
|
@ -207,14 +203,6 @@
|
|||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-db</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-db-vendor-h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-db-vendor-mysql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-db-vendor-postgresql</artifactId>
|
||||
|
|
@ -243,10 +231,6 @@
|
|||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-tracing-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>wsmaster-local</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.infrastructure</groupId>
|
||||
<artifactId>infrastructure-distributed</artifactId>
|
||||
|
|
@ -474,8 +458,6 @@
|
|||
<dep>org.slf4j:log4j-over-slf4j</dep>
|
||||
<dep>ch.qos.logback:logback-classic</dep>
|
||||
<dep>net.logstash.logback:logstash-logback-encoder</dep>
|
||||
<dep>com.h2database:h2</dep>
|
||||
<dep>org.eclipse.che.core:che-core-db-vendor-mysql</dep>
|
||||
<dep>org.eclipse.che.core:che-core-sql-schema</dep>
|
||||
<dep>org.eclipse.che.core:che-core-api-ssh-shared</dep>
|
||||
<dep>org.eclipse.che.multiuser:che-multiuser-sql-schema</dep>
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.api;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
import org.eclipse.che.core.db.h2.H2SQLJndiDataSourceFactory;
|
||||
import org.eclipse.che.core.db.postgresql.PostgreSQLJndiDataSourceFactory;
|
||||
|
||||
/**
|
||||
* Creates appropriate JNDI data source factory instance depending on system variable.
|
||||
*
|
||||
* @author Max Shaposhnik (mshaposh@redhat.com)
|
||||
*/
|
||||
public class CommonJndiDataSourceFactory implements ObjectFactory {
|
||||
|
||||
private final ObjectFactory delegate;
|
||||
|
||||
public CommonJndiDataSourceFactory() throws Exception {
|
||||
delegate =
|
||||
Boolean.valueOf(System.getenv("CHE_MULTIUSER"))
|
||||
? new PostgreSQLJndiDataSourceFactory()
|
||||
: new H2SQLJndiDataSourceFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObjectInstance(Object o, Name name, Context context, Hashtable<?, ?> hashtable)
|
||||
throws Exception {
|
||||
return delegate.getObjectInstance(o, name, context, hashtable);
|
||||
}
|
||||
}
|
||||
|
|
@ -47,6 +47,7 @@ import org.eclipse.che.api.infraproxy.server.InfraProxyModule;
|
|||
import org.eclipse.che.api.metrics.WsMasterMetricsModule;
|
||||
import org.eclipse.che.api.system.server.ServiceTermination;
|
||||
import org.eclipse.che.api.system.server.SystemModule;
|
||||
import org.eclipse.che.api.user.server.NotImplementedTokenValidator;
|
||||
import org.eclipse.che.api.user.server.TokenValidator;
|
||||
import org.eclipse.che.api.user.server.jpa.JpaPreferenceDao;
|
||||
import org.eclipse.che.api.user.server.jpa.JpaProfileDao;
|
||||
|
|
@ -75,7 +76,6 @@ import org.eclipse.che.api.workspace.server.spi.provision.env.ProjectsRootEnvVar
|
|||
import org.eclipse.che.api.workspace.server.spi.provision.env.WorkspaceIdEnvVarProvider;
|
||||
import org.eclipse.che.api.workspace.server.spi.provision.env.WorkspaceNameEnvVarProvider;
|
||||
import org.eclipse.che.api.workspace.server.spi.provision.env.WorkspaceNamespaceNameEnvVarProvider;
|
||||
import org.eclipse.che.api.workspace.server.token.MachineTokenProvider;
|
||||
import org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier;
|
||||
import org.eclipse.che.commons.observability.deploy.ExecutorWrapperModule;
|
||||
import org.eclipse.che.core.db.DBTermination;
|
||||
|
|
@ -280,11 +280,7 @@ public class WsMasterModule extends AbstractModule {
|
|||
installDefaultSecureServerExposer(infrastructure);
|
||||
install(new org.eclipse.che.security.oauth1.BitbucketModule());
|
||||
|
||||
if (Boolean.valueOf(System.getenv("CHE_MULTIUSER"))) {
|
||||
configureMultiUserMode(persistenceProperties, infrastructure);
|
||||
} else {
|
||||
configureSingleUserMode(persistenceProperties, infrastructure);
|
||||
}
|
||||
configureMultiUserMode(persistenceProperties, infrastructure);
|
||||
|
||||
install(
|
||||
new com.google.inject.persist.jpa.JpaPersistModule("main")
|
||||
|
|
@ -321,43 +317,6 @@ public class WsMasterModule extends AbstractModule {
|
|||
install(new OpenShiftOAuthModule());
|
||||
}
|
||||
|
||||
private void configureSingleUserMode(
|
||||
Map<String, String> persistenceProperties, String infrastructure) {
|
||||
persistenceProperties.put(
|
||||
PersistenceUnitProperties.EXCEPTION_HANDLER_CLASS,
|
||||
"org.eclipse.che.core.db.h2.jpa.eclipselink.H2ExceptionHandler");
|
||||
bind(TokenValidator.class).to(org.eclipse.che.api.local.DummyTokenValidator.class);
|
||||
bind(MachineTokenProvider.class).to(MachineTokenProvider.EmptyMachineTokenProvider.class);
|
||||
|
||||
bind(DataSource.class).toProvider(org.eclipse.che.core.db.h2.H2DataSourceProvider.class);
|
||||
|
||||
install(new org.eclipse.che.api.user.server.jpa.UserJpaModule());
|
||||
install(new org.eclipse.che.api.workspace.server.jpa.WorkspaceJpaModule());
|
||||
install(new org.eclipse.che.api.devfile.server.jpa.UserDevfileJpaModule());
|
||||
|
||||
bind(org.eclipse.che.api.user.server.CheUserCreator.class);
|
||||
|
||||
bindConstant().annotatedWith(Names.named("che.agents.auth_enabled")).to(false);
|
||||
|
||||
bind(org.eclipse.che.security.oauth.shared.OAuthTokenProvider.class)
|
||||
.to(org.eclipse.che.security.oauth.OAuthAuthenticatorTokenProvider.class);
|
||||
bind(OAuthAPI.class).to(EmbeddedOAuthAPI.class);
|
||||
|
||||
bind(RemoteSubscriptionStorage.class)
|
||||
.to(org.eclipse.che.api.core.notification.InmemoryRemoteSubscriptionStorage.class);
|
||||
bind(WorkspaceLockService.class)
|
||||
.to(org.eclipse.che.api.workspace.server.DefaultWorkspaceLockService.class);
|
||||
bind(WorkspaceStatusCache.class)
|
||||
.to(org.eclipse.che.api.workspace.server.DefaultWorkspaceStatusCache.class);
|
||||
|
||||
install(new org.eclipse.che.api.workspace.activity.inject.WorkspaceActivityModule());
|
||||
|
||||
// In single user mode jwtproxy provisioner isn't actually bound at all, but since
|
||||
// it is the new default, we need to "fake it" by binding the passthrough provisioner
|
||||
// as the jwtproxy impl.
|
||||
configureImpostorJwtProxySecureProvisioner(infrastructure);
|
||||
}
|
||||
|
||||
private void configureMultiUserMode(
|
||||
Map<String, String> persistenceProperties, String infrastructure) {
|
||||
if (OpenShiftInfrastructure.NAME.equals(infrastructure)
|
||||
|
|
@ -436,7 +395,7 @@ public class WsMasterModule extends AbstractModule {
|
|||
install(new OrganizationJpaModule());
|
||||
|
||||
if (Boolean.parseBoolean(System.getenv("CHE_AUTH_NATIVEUSER"))) {
|
||||
bind(TokenValidator.class).to(org.eclipse.che.api.local.DummyTokenValidator.class);
|
||||
bind(TokenValidator.class).to(NotImplementedTokenValidator.class);
|
||||
bind(JwtParser.class).to(DefaultJwtParser.class);
|
||||
bind(ProfileDao.class).to(JpaProfileDao.class);
|
||||
bind(OAuthAPI.class).to(EmbeddedOAuthAPI.class);
|
||||
|
|
|
|||
|
|
@ -45,16 +45,12 @@ public class WsMasterServletModule extends ServletModule {
|
|||
serveRegex("^(?!/websocket.?)(.*)").with(GuiceEverrestServlet.class);
|
||||
install(new org.eclipse.che.swagger.deploy.BasicSwaggerConfigurationModule());
|
||||
|
||||
if (Boolean.valueOf(System.getenv("CHE_MULTIUSER"))) {
|
||||
if (Boolean.parseBoolean(System.getenv("CHE_AUTH_NATIVEUSER"))) {
|
||||
LOG.info("Running in native-user mode ...");
|
||||
configureNativeUserMode();
|
||||
} else {
|
||||
LOG.info("Running in classic multi-user mode ...");
|
||||
configureMultiUserMode();
|
||||
}
|
||||
if (Boolean.parseBoolean(System.getenv("CHE_AUTH_NATIVEUSER"))) {
|
||||
LOG.info("Running in native-user mode ...");
|
||||
configureNativeUserMode();
|
||||
} else {
|
||||
configureSingleUserMode();
|
||||
LOG.info("Running in classic multi-user mode ...");
|
||||
configureMultiUserMode();
|
||||
}
|
||||
|
||||
if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
|
||||
|
|
@ -72,10 +68,6 @@ public class WsMasterServletModule extends ServletModule {
|
|||
}
|
||||
}
|
||||
|
||||
private void configureSingleUserMode() {
|
||||
filter("/*").through(org.eclipse.che.api.local.filters.EnvironmentInitializationFilter.class);
|
||||
}
|
||||
|
||||
private void configureMultiUserMode() {
|
||||
filterRegex(".*").through(MachineLoginFilter.class);
|
||||
install(new KeycloakServletModule());
|
||||
|
|
|
|||
|
|
@ -16,5 +16,5 @@
|
|||
|
||||
<Resource name="jdbc/che" auth="Container"
|
||||
type="javax.sql.DataSource"
|
||||
factory="org.eclipse.che.api.CommonJndiDataSourceFactory"/>
|
||||
factory="org.eclipse.che.core.db.postgresql.PostgreSQLJndiDataSourceFactory"/>
|
||||
</Context>
|
||||
|
|
|
|||
|
|
@ -15,9 +15,6 @@
|
|||
|
||||
### {prod-short} server
|
||||
|
||||
# Folder where {prod-short} stores internal data objects.
|
||||
che.database=${che.home}/storage
|
||||
|
||||
# API service. Browsers initiate REST communications to {prod-short} server with this URL.
|
||||
che.api=http://${CHE_HOST}:${CHE_PORT}/api
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.core.db.h2;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.sql.DataSource;
|
||||
import org.eclipse.che.core.db.JndiDataSourceProvider;
|
||||
|
||||
/**
|
||||
* Provides data source for h2 database.
|
||||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
public class H2DataSourceProvider implements Provider<DataSource> {
|
||||
|
||||
@Inject
|
||||
@Named("che.database")
|
||||
private String storageRoot;
|
||||
|
||||
@Inject private JndiDataSourceProvider jndiDataSourceProvider;
|
||||
|
||||
@Override
|
||||
public DataSource get() {
|
||||
System.setProperty("h2.baseDir", Paths.get(storageRoot).resolve("db").toString());
|
||||
return jndiDataSourceProvider.get();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.core.db.h2;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
|
||||
import org.eclipse.che.core.db.JNDIDataSourceFactory;
|
||||
|
||||
/**
|
||||
* Environment params based JNDI data source factory for H2SQL.
|
||||
*
|
||||
* @author Sergii Kabashniuk
|
||||
*/
|
||||
public class H2SQLJndiDataSourceFactory extends JNDIDataSourceFactory {
|
||||
|
||||
private static final String DEFAULT_USERNAME = "";
|
||||
private static final String DEFAULT_PASSWORD = "";
|
||||
private static final String DEFAULT_URL = "jdbc:h2:che";
|
||||
private static final String DEFAULT_DRIVER__CLASS__NAME = "org.h2.Driver";
|
||||
private static final String DEFAULT_MAX__TOTAL = "8";
|
||||
private static final String DEFAULT_MAX__IDLE = "2";
|
||||
private static final String DEFAULT_MAX__WAIT__MILLIS = "-1";
|
||||
|
||||
public H2SQLJndiDataSourceFactory() throws Exception {
|
||||
super(
|
||||
firstNonNull(
|
||||
nullStringToNullReference(System.getenv("CHE_JDBC_USERNAME")), DEFAULT_USERNAME),
|
||||
firstNonNull(
|
||||
nullStringToNullReference(System.getenv("CHE_JDBC_PASSWORD")), DEFAULT_PASSWORD),
|
||||
firstNonNull(nullStringToNullReference(System.getenv("CHE_JDBC_URL")), DEFAULT_URL),
|
||||
firstNonNull(
|
||||
nullStringToNullReference(System.getenv("CHE_JDBC_DRIVER__CLASS__NAME")),
|
||||
DEFAULT_DRIVER__CLASS__NAME),
|
||||
firstNonNull(
|
||||
nullStringToNullReference(System.getenv("CHE_JDBC_MAX__TOTAL")), DEFAULT_MAX__TOTAL),
|
||||
firstNonNull(
|
||||
nullStringToNullReference(System.getenv("CHE_JDBC_MAX__IDLE")), DEFAULT_MAX__IDLE),
|
||||
firstNonNull(
|
||||
nullStringToNullReference(System.getenv("CHE_JDBC_MAX__WAIT__MILLIS")),
|
||||
DEFAULT_MAX__WAIT__MILLIS));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* Copyright (c) 2012-2021 Red Hat, Inc.
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
|
@ -9,25 +9,17 @@
|
|||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.api.local;
|
||||
package org.eclipse.che.api.user.server;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import org.eclipse.che.api.core.ConflictException;
|
||||
import org.eclipse.che.api.core.model.user.User;
|
||||
import org.eclipse.che.api.user.server.TokenValidator;
|
||||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
|
||||
/**
|
||||
* Dummy implementation of {@link org.eclipse.che.api.user.server.TokenValidator}.
|
||||
*
|
||||
* @author Ann Shumilova
|
||||
* @author Dmitry Shnurenko
|
||||
*/
|
||||
@Singleton
|
||||
public class DummyTokenValidator implements TokenValidator {
|
||||
public class NotImplementedTokenValidator implements TokenValidator {
|
||||
|
||||
@Override
|
||||
public User validateToken(String token) throws ConflictException {
|
||||
return new UserImpl("che", "che", "che@eclipse.org");
|
||||
throw new ConflictException("Token validation do not implemented");
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +45,6 @@
|
|||
<module>che-core-api-factory-bitbucket-server</module>
|
||||
<module>che-core-api-ssh</module>
|
||||
<module>che-core-api-ssh-shared</module>
|
||||
<module>wsmaster-local</module>
|
||||
<module>che-core-sql-schema</module>
|
||||
<module>che-core-api-system</module>
|
||||
<module>che-core-api-system-shared</module>
|
||||
|
|
|
|||
|
|
@ -1,150 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright (c) 2012-2021 Red Hat, Inc.
|
||||
This program and the accompanying materials are made
|
||||
available under the terms of the Eclipse Public License 2.0
|
||||
which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
Contributors:
|
||||
Red Hat, Inc. - initial API and implementation
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>che-master-parent</artifactId>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<version>7.37.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>wsmaster-local</artifactId>
|
||||
<name>Che Core :: API :: Impl Local</name>
|
||||
<properties>
|
||||
<findbugs.failonerror>false</findbugs.failonerror>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.opentracing</groupId>
|
||||
<artifactId>opentracing-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-api-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-api-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-api-user</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-commons-tracing</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-api-workspace-shared</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.inject.extensions</groupId>
|
||||
<artifactId>guice-persist</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-commons-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-db</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-db-vendor-h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-sql-schema</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>javax.persistence</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.everrest</groupId>
|
||||
<artifactId>everrest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-testng</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>resource-dependencies</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeArtifactIds>che-core-sql-schema</includeArtifactIds>
|
||||
<includes>che-schema/</includes>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2021 Red Hat, Inc.
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.api.local.filters;
|
||||
|
||||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
import java.io.IOException;
|
||||
import java.security.Principal;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import org.eclipse.che.commons.env.EnvironmentContext;
|
||||
import org.eclipse.che.commons.subject.Subject;
|
||||
import org.eclipse.che.commons.subject.SubjectImpl;
|
||||
import org.eclipse.che.commons.tracing.TracingTags;
|
||||
|
||||
/**
|
||||
* Fills environment context with information about current subject.
|
||||
*
|
||||
* @author Dmitry Shnurenko
|
||||
*/
|
||||
@Singleton
|
||||
public class EnvironmentInitializationFilter implements Filter {
|
||||
|
||||
@Inject Tracer tracer;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
|
||||
@Override
|
||||
public final void doFilter(
|
||||
ServletRequest request, ServletResponse response, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
final HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
Subject subject = new SubjectImpl("che", "che", "dummy_token", false);
|
||||
final EnvironmentContext environmentContext = EnvironmentContext.getCurrent();
|
||||
try {
|
||||
environmentContext.setSubject(subject);
|
||||
Span activeSpan = tracer.activeSpan();
|
||||
if (activeSpan != null) {
|
||||
TracingTags.USER_ID.set(tracer.activeSpan(), subject.getUserId());
|
||||
}
|
||||
filterChain.doFilter(addUserInRequest(httpRequest, subject), response);
|
||||
} finally {
|
||||
EnvironmentContext.reset();
|
||||
}
|
||||
}
|
||||
|
||||
private HttpServletRequest addUserInRequest(
|
||||
final HttpServletRequest httpRequest, final Subject subject) {
|
||||
return new HttpServletRequestWrapper(httpRequest) {
|
||||
@Override
|
||||
public String getRemoteUser() {
|
||||
return subject.getUserName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Principal getUserPrincipal() {
|
||||
return () -> subject.getUserName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {}
|
||||
}
|
||||
Loading…
Reference in New Issue