Cloud configuration model. AWS model refactoring.

This commit is contained in:
serge-rider
2020-05-30 23:32:35 +03:00
parent 8be2480da7
commit 54d4057285
7 changed files with 37 additions and 12 deletions
@@ -39,6 +39,9 @@ import java.util.Map;
public class DBWebException extends DBException implements GraphQLError {
public static final String ERROR_CODE_SESSION_EXPIRED = "sessionExpired";
public static final String ERROR_CODE_ACCESS_DENIED = "accessDenied";
public static final String ERROR_CODE_IDENT_REQUIRED = "identRequired";
public static final String ERROR_CODE_AUTH_REQUIRED = "authRequired";
private List<Object> path;
private List<SourceLocation> locations;
@@ -21,8 +21,6 @@ package io.cloudbeaver;
*/
public class DBWebExceptionAccessDenied extends DBWebException {
public static final String ERROR_CODE_ACCESS_DENIED = "accessDenied";
public DBWebExceptionAccessDenied(String message) {
super(message, ERROR_CODE_ACCESS_DENIED);
}
@@ -30,6 +30,7 @@ import org.eclipse.core.runtime.Status;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.access.DBASession;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.meta.Association;
@@ -53,7 +54,7 @@ import java.util.function.Function;
* Web session.
* Is the main source of data in web application
*/
public class WebSession {
public class WebSession implements DBASession {
private static final Log log = Log.getLog(WebSession.class);
@@ -104,10 +105,15 @@ public class WebSession {
}
@Property
public String getId() {
public String getSessionId() {
return id;
}
@Override
public boolean isApplicationSession() {
return false;
}
@Property
public String getCreateTime() {
return CBConstants.ISO_DATE_FORMAT.format(createTime);
@@ -95,7 +95,7 @@ public class WebSessionManager {
}
}
log.debug("> New web session '" + webSession.getId() + "'");
log.debug("> New web session '" + webSession.getSessionId() + "'");
} else {
if (updateInfo) {
// Update only once per request
@@ -132,7 +132,7 @@ public class WebSessionManager {
}
for (WebSession session : expiredList) {
log.debug("> Expire session '" + session.getId() + "'");
log.debug("> Expire session '" + session.getSessionId() + "'");
session.close();
}
}
@@ -18,6 +18,10 @@ package io.cloudbeaver.server;
import io.cloudbeaver.auth.provider.local.LocalAuthProvider;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Application configuration
*/
@@ -33,6 +37,7 @@ public class CBAppConfig {
private String[] enabledDrivers = new String[0];
private String[] disabledDrivers = new String[0];
private String defaultAuthProvider = LocalAuthProvider.PROVIDER_ID;
private Map<String, Object> plugins = new LinkedHashMap<>();
public boolean isAuthenticationEnabled() {
return authenticationEnabled;
@@ -77,4 +82,18 @@ public class CBAppConfig {
public String getDefaultAuthProvider() {
return defaultAuthProvider;
}
public Map<String, Object> getPluginConfig(String pluginId) {
Object config = plugins.get(pluginId);
if (config instanceof Map) {
return (Map<String, Object>) config;
} else {
return Collections.emptyMap();
}
}
public <T> T getPluginOption(String pluginId, String option) {
return (T)getPluginConfig(pluginId).get(option);
}
}
@@ -465,7 +465,7 @@ class CBSecurityController implements DBWSecurityController {
try (Connection dbCon = database.openConnection()) {
try (PreparedStatement dbStat = dbCon.prepareStatement(
"INSERT INTO CB_SESSION(SESSION_ID,USER_ID,CREATE_TIME,LAST_ACCESS_TIME,LAST_ACCESS_REMOTE_ADDRESS,LAST_ACCESS_USER_AGENT) VALUES(?,?,?,?,?,?)")) {
dbStat.setString(1, session.getId());
dbStat.setString(1, session.getSessionId());
WebUser user = session.getUser();
if (user == null) {
dbStat.setNull(2, Types.VARCHAR);
@@ -515,7 +515,7 @@ class CBSecurityController implements DBWSecurityController {
dbStat.setNull(4, Types.VARCHAR);
}
dbStat.setString(5, session.getId());
dbStat.setString(5, session.getSessionId());
if (dbStat.executeUpdate() == 0) {
throw new DBCException("Session not exists in database");
}
@@ -17,13 +17,12 @@
package io.cloudbeaver.service.data.transfer.impl;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.model.WebAsyncTaskInfo;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.service.data.transfer.DBWServiceDataTransfer;
import io.cloudbeaver.service.sql.WebSQLContextInfo;
import io.cloudbeaver.service.sql.WebSQLProcessor;
import io.cloudbeaver.service.data.transfer.DBWServiceDataTransfer;
import io.cloudbeaver.service.sql.WebSQLQueryDataContainer;
import io.cloudbeaver.service.sql.WebSQLResultsInfo;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
@@ -102,7 +101,7 @@ public class WebServiceDataTransfer implements DBWServiceDataTransfer {
@NotNull
private String makeUniqueFileName(WebSQLProcessor sqlProcessor, DataTransferProcessorDescriptor processor) {
return sqlProcessor.getWebSession().getId() + "_" + UUID.randomUUID() + "." + WebDataTransferUtils.getProcessorFileExtension(processor);
return sqlProcessor.getWebSession().getSessionId() + "_" + UUID.randomUUID() + "." + WebDataTransferUtils.getProcessorFileExtension(processor);
}
@Override