Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-skoblikov committed Nov 29, 2024
1 parent af86059 commit 059a029
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.Map;

/**
* Web application
* Servlet application
*/
public abstract class BaseServletApplication extends BaseApplicationImpl implements ServletApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.jkiss.dbeaver.DBException;

public interface ServletAuthApplication extends ServletApplication {

Check warning on line 23 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/ServletAuthApplication.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/ServletAuthApplication.java#L23

Missing a Javadoc comment.
WebAuthConfiguration getAuthConfiguration();
ServletAuthConfiguration getAuthConfiguration();

Check warning on line 24 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/ServletAuthApplication.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/ServletAuthApplication.java#L24

Missing a Javadoc comment.

String getAuthServiceURL();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Application authentication configuration
*/
public interface WebAuthConfiguration {
public interface ServletAuthConfiguration {

String getDefaultAuthProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.cloudbeaver.auth.provider.local.LocalAuthProviderConstants;
import io.cloudbeaver.model.app.BaseWebAppConfiguration;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.app.ServletAuthConfiguration;

Check warning on line 23 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/config/CBAppConfig.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/config/CBAppConfig.java#L23

Wrong lexicographical order for io.cloudbeaver.model.app.ServletAuthConfiguration import. Should be before io.cloudbeaver.model.app.WebAppConfiguration.
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
import org.jkiss.code.NotNull;
Expand All @@ -37,7 +37,7 @@
/**
* Application configuration
*/
public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfiguration, WebAppConfiguration {
public class CBAppConfig extends BaseWebAppConfiguration implements ServletAuthConfiguration, WebAppConfiguration {
private static final Log log = Log.getLog(CBAppConfig.class);

public static final DataSourceNavigatorSettings DEFAULT_VIEW_SETTINGS = PRESET_WEB.getSettings();
Expand Down Expand Up @@ -162,6 +162,7 @@ public boolean isRedirectOnFederatedAuth() {
return redirectOnFederatedAuth;
}

@NotNull
public String[] getEnabledDrivers() {
return enabledDrivers;
}
Expand All @@ -170,6 +171,7 @@ public void setEnabledDrivers(String[] enabledDrivers) {
this.enabledDrivers = enabledDrivers;
}

@NotNull
public String[] getDisabledDrivers() {
return disabledDrivers;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.cloudbeaver.DBWUserIdentity;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.auth.SMAuthProviderExternal;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.model.user.WebUser;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
Expand Down Expand Up @@ -127,7 +127,7 @@ private List<WebAuthInfo> finishWebSessionAuthorization(SMAuthInfo authInfo) thr

DBWUserIdentity userIdentity = null;
var providerConfigId = authConfiguration.getAuthProviderConfigurationId();
var providerConfig = ServletAppUtils.getWebAuthApplication()
var providerConfig = ServletAppUtils.getAuthApplication()
.getAuthConfiguration()
.getAuthProviderConfiguration(providerConfigId);
if (authProviderExternal != null) {
Expand Down Expand Up @@ -194,7 +194,7 @@ private WebAuthProviderDescriptor getAuthProvider(String providerId) throws DBWe
}

private boolean isProviderEnabled(@NotNull String providerId) {
WebAuthConfiguration appConfiguration = (WebAuthConfiguration) ServletAppUtils.getServletApplication()
ServletAuthConfiguration appConfiguration = (ServletAuthConfiguration) ServletAppUtils.getServletApplication()
.getAppConfiguration();
return appConfiguration.isAuthProviderEnabled(providerId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static ServletApplication getServletApplication() {
return (ServletApplication) DBWorkbench.getPlatform().getApplication();
}

public static ServletAuthApplication getWebAuthApplication() throws DBException {
public static ServletAuthApplication getAuthApplication() throws DBException {

Check warning on line 62 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/ServletAppUtils.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/ServletAppUtils.java#L62

Missing a Javadoc comment.
ServletApplication application = getServletApplication();
if (!ServletAuthApplication.class.isAssignableFrom(application.getClass())) {
throw new DBException("The current application doesn't contain authorization configuration");
Expand Down Expand Up @@ -169,7 +169,7 @@ public static String removeSideSlashes(String action) {

@NotNull
public static StringBuilder getAuthApiPrefix(String serviceId) throws DBException {
return getAuthApiPrefix(getWebAuthApplication(), serviceId);
return getAuthApiPrefix(getAuthApplication(), serviceId);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.cloudbeaver.model.WebServerConfig;
import io.cloudbeaver.model.app.BaseServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.config.CBServerConfig;
import io.cloudbeaver.model.config.SMControllerConfiguration;
Expand Down Expand Up @@ -177,7 +177,7 @@ public T getServerConfiguration() {
}

@Override
public WebAuthConfiguration getAuthConfiguration() {
public ServletAuthConfiguration getAuthConfiguration() {
return getAppConfiguration();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ protected synchronized void initialize() {
}

protected void scheduleServerJobs() {
new WebSessionMonitorJob(this, getSessionManager())
new WebSessionMonitorJob(this, application.getSessionManager())
.scheduleMonitor();

new SessionStateJob(this, getSessionManager())
new SessionStateJob(this, application.getSessionManager())
.scheduleMonitor();

new WebDataSourceMonitorJob(this, getSessionManager())
new WebDataSourceMonitorJob(this, application.getSessionManager())
.scheduleMonitor();

new AbstractJob("Delete temp folder") {
Expand Down Expand Up @@ -120,7 +120,7 @@ public synchronized void dispose() {

@NotNull
@Override
public WebApplication getApplication() {
public CBApplication<?> getApplication() {
return application;
}

Expand All @@ -140,10 +140,6 @@ public boolean isShuttingDown() {
return false;
}

public CBSessionManager getSessionManager() {
return application.getSessionManager();
}

public void refreshApplicableDrivers() {
this.applicableDrivers.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void handleEvent(@NotNull WSObjectPermissionEvent event) {
return;
}
log.debug(event.getTopicId() + " event handled");
Collection<BaseWebSession> allSessions = CBPlatform.getInstance().getSessionManager().getAllActiveSessions();
Collection<BaseWebSession> allSessions = CBApplication.getInstance().getSessionManager().getAllActiveSessions();
for (var activeUserSession : allSessions) {
if (!isAcceptableInSession(activeUserSession, event)) {
log.debug("Cannot handle %s event '%s' in session %s".formatted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.cloudbeaver.server.events;

import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.websocket.WSEventHandler;
Expand All @@ -31,7 +32,7 @@ public void handleEvent(@NotNull EVENT event) {
if (eventType == null) {
return;
}
var sessionManager = CBPlatform.getInstance().getSessionManager();
var sessionManager = CBApplication.getInstance().getSessionManager();
switch (eventType) {
case CLOSE_USER_SESSIONS:
if (event instanceof WSUserCloseSessionsEvent closeSessionsEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}
String uri = request.getPathInfo();
try {
WebSession webSession = CBPlatform.getInstance().getSessionManager().getWebSession(
WebSession webSession = CBApplication.getInstance().getSessionManager().getWebSession(
request, response, false);
performAutoLoginIfNeeded(request, webSession);
WebActionParameters webActionParameters = WebActionParameters.fromSession(webSession, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.WebServiceBindingBase;

/**
* extends the base gql model, to avoid unnecessary fields in other applications
*/
public class CECoreModelExtender extends WebServiceBindingBase<DBWVoidService> {
public CECoreModelExtender() {
super(DBWVoidService.class, new DBWVoidService(), "schema/service.core.graphqls");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public static List<WebAuthProviderDescriptor> getEnabledAuthProviders() {
List<WebAuthProviderDescriptor> result = new ArrayList<>();
String[] authProviders = null;
try {
authProviders = ServletAppUtils.getWebAuthApplication().getAuthConfiguration().getEnabledAuthProviders();
authProviders = ServletAppUtils.getAuthApplication().getAuthConfiguration().getEnabledAuthProviders();
} catch (DBException e) {
log.error(e.getMessage(), e);
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ private void initTempFolder(@NotNull DBRProgressMonitor monitor) {
@NotNull
public abstract WebApplication getApplication();

public abstract WebAppSessionManager getSessionManager();

protected abstract void scheduleServerJobs();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ protected static DBWBindingContext getBindingContext(DataFetchingEnvironment env
}

protected static WebSession getWebSession(DataFetchingEnvironment env) throws DBWebException {
return WebAppUtils.getWebPlatform().getSessionManager().getWebSession(
return WebAppUtils.getWebApplication().getSessionManager().getWebSession(
getServletRequest(env), getServletResponse(env));
}

protected static WebSession getWebSession(DataFetchingEnvironment env, boolean errorOnNotFound) throws DBWebException {
return WebAppUtils.getWebPlatform().getSessionManager().getWebSession(
return WebAppUtils.getWebApplication().getSessionManager().getWebSession(
getServletRequest(env), getServletResponse(env), errorOnNotFound);
}

Expand All @@ -127,12 +127,12 @@ protected static WebConnectionInfo getWebConnection(DataFetchingEnvironment env)
*/
@Nullable
public static WebSession findWebSession(DataFetchingEnvironment env) {
return WebAppUtils.getWebPlatform().getSessionManager().findWebSession(
return WebAppUtils.getWebApplication().getSessionManager().findWebSession(
getServletRequest(env));
}

public static WebSession findWebSession(DataFetchingEnvironment env, boolean errorOnNotFound) throws DBWebException {
return WebAppUtils.getWebPlatform().getSessionManager().findWebSession(
return WebAppUtils.getWebApplication().getSessionManager().findWebSession(
getServletRequest(env), errorOnNotFound);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.cloudbeaver.model.WebNetworkHandlerConfigInput;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.BaseWebPlatform;
import io.cloudbeaver.server.WebAppSessionManager;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
import io.cloudbeaver.service.DBWBindingContext;
Expand All @@ -49,8 +50,7 @@ public WebServiceBindingCore() {

@Override
public void bindWiring(DBWBindingContext model) throws DBWebException {
BaseWebPlatform platform = WebAppUtils.getWebPlatform();
var sessionManager = platform.getSessionManager();
WebAppSessionManager sessionManager = WebAppUtils.getWebApplication().getSessionManager();
model.getQueryType()
.dataFetcher("serverConfig", env -> getService(env).getServerConfig())
.dataFetcher("productSettings", env -> getService(env).getProductSettings(getWebSession(env)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public List<WebServerMessage> readSessionLog(
@Override
public boolean closeSession(HttpServletRequest request) throws DBWebException {
try {
var baseWebSession = WebAppUtils.getWebPlatform().getSessionManager().closeSession(request);
var baseWebSession = WebAppUtils.getWebApplication().getSessionManager().closeSession(request);
if (baseWebSession instanceof WebSession webSession) {
for (WebSessionHandlerDescriptor hd : WebHandlerRegistry.getInstance().getSessionHandlers()) {
try {
Expand All @@ -288,22 +288,22 @@ public boolean closeSession(HttpServletRequest request) throws DBWebException {
@Override
@Deprecated
public boolean touchSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws DBWebException {
return WebAppUtils.getWebPlatform().getSessionManager().touchSession(request, response);
return WebAppUtils.getWebApplication().getSessionManager().touchSession(request, response);
}

@Override
@Deprecated
public WebSession updateSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
throws DBWebException {
var sessionManager = WebAppUtils.getWebPlatform().getSessionManager();
var sessionManager = WebAppUtils.getWebApplication().getSessionManager();
sessionManager.touchSession(request, response);
return sessionManager.getWebSession(request, response, true);
}

@Override
public boolean refreshSessionConnections(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
throws DBWebException {
WebSession session = WebAppUtils.getWebPlatform().getSessionManager().getWebSession(request, response);
WebSession session = WebAppUtils.getWebApplication().getSessionManager().getWebSession(request, response);
if (session == null) {
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.auth.SMAuthProviderExternal;
import io.cloudbeaver.auth.provider.rp.RPAuthProvider;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.session.WebSessionAuthProcessor;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
Expand All @@ -46,7 +46,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class RPSessionHandler implements DBWSessionHandler {

Expand All @@ -57,7 +56,7 @@ public class RPSessionHandler implements DBWSessionHandler {
public boolean handleSessionOpen(WebSession webSession, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException {

Check warning on line 56 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/RPSessionHandler.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Line is longer than 140 characters (found 151). Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/RPSessionHandler.java:56:0: warning: Line is longer than 140 characters (found 151). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
boolean configMode = CBApplication.getInstance().isConfigurationMode();
//checks if the app is not in configuration mode and reverse proxy auth is enabled in the config file
WebAuthConfiguration appConfiguration = (WebAuthConfiguration) ServletAppUtils.getServletApplication()
ServletAuthConfiguration appConfiguration = (ServletAuthConfiguration) ServletAppUtils.getServletApplication()
.getAppConfiguration();
boolean isReverseProxyAuthEnabled = appConfiguration.isAuthProviderEnabled(RPAuthProvider.AUTH_PROVIDER);
if (!configMode && isReverseProxyAuthEnabled) {
Expand All @@ -73,7 +72,7 @@ public void reverseProxyAuthentication(@NotNull HttpServletRequest request, @Not
throw new DBWebException("Auth provider " + RPAuthProvider.AUTH_PROVIDER + " not found");
}
SMAuthProviderExternal<?> authProviderExternal = (SMAuthProviderExternal<?>) authProvider.getInstance();

Check warning on line 74 in server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/RPSessionHandler.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Distance between variable 'authProviderExternal' declaration and its first usage is 4, but allowed 3. Consider making that variable final if you still need to store its value in advance (before method calls that might have side effects on the original value). Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.auth/src/io/cloudbeaver/service/auth/RPSessionHandler.java:74:9: warning: Distance between variable 'authProviderExternal' declaration and its first usage is 4, but allowed 3. Consider making that variable final if you still need to store its value in advance (before method calls that might have side effects on the original value). (com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck)
SMAuthProviderCustomConfiguration configuration = ServletAppUtils.getWebAuthApplication()
SMAuthProviderCustomConfiguration configuration = ServletAppUtils.getAuthApplication()
.getAuthConfiguration()
.getAuthCustomConfigurations()
.stream()
Expand Down
Loading

0 comments on commit 059a029

Please sign in to comment.