mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-1394 Update cb-session for GQL API calls pnly
This commit is contained in:
@@ -32,7 +32,6 @@ import org.jkiss.code.NotNull;
|
||||
import org.jkiss.code.Nullable;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
import org.jkiss.dbeaver.Log;
|
||||
import org.jkiss.dbeaver.model.DBConstants;
|
||||
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
|
||||
import org.jkiss.dbeaver.model.access.DBASession;
|
||||
import org.jkiss.dbeaver.model.access.DBASessionPrincipal;
|
||||
@@ -65,7 +64,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Path;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
@@ -80,7 +78,6 @@ public class WebSession implements DBASession, DBAAuthCredentialsProvider, IAdap
|
||||
private static final Log log = Log.getLog(WebSession.class);
|
||||
|
||||
private static final String ATTR_LOCALE = "locale";
|
||||
private static final String SESSION_TEMP_COOKIE = "cb-session";
|
||||
public static final String USER_PROJECTS_FOLDER = "user-projects";
|
||||
|
||||
private static final AtomicInteger TASK_ID = new AtomicInteger();
|
||||
@@ -452,13 +449,6 @@ public class WebSession implements DBASession, DBAAuthCredentialsProvider, IAdap
|
||||
log.error("Error persisting web session", e);
|
||||
}
|
||||
}
|
||||
|
||||
long maxSessionIdleTime = CBApplication.getInstance().getMaxSessionIdleTime();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_ISO_TIMESTAMP_FORMAT);
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String cookieValue = sdf.format(new Date(System.currentTimeMillis() + maxSessionIdleTime));
|
||||
WebServiceUtils.addResponseCookie(
|
||||
response, SESSION_TEMP_COOKIE, cookieValue, maxSessionIdleTime);
|
||||
}
|
||||
|
||||
@Association
|
||||
|
||||
+19
-4
@@ -39,6 +39,7 @@ import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.service.DBWServiceBindingGraphQL;
|
||||
import io.cloudbeaver.service.WebServiceBindingBase;
|
||||
import org.jkiss.dbeaver.Log;
|
||||
import org.jkiss.dbeaver.model.DBConstants;
|
||||
import org.jkiss.utils.IOUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@@ -51,10 +52,8 @@ import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class GraphQLEndpoint extends HttpServlet {
|
||||
@@ -67,6 +66,8 @@ public class GraphQLEndpoint extends HttpServlet {
|
||||
|
||||
private static final String CORE_SCHEMA_FILE_NAME = "schema/schema.graphqls";
|
||||
|
||||
private static final String SESSION_TEMP_COOKIE = "cb-session";
|
||||
|
||||
private final GraphQL graphQL;
|
||||
|
||||
private static Gson gson = new GsonBuilder()
|
||||
@@ -155,6 +156,8 @@ public class GraphQLEndpoint extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
beforeApiCall(request, response);
|
||||
|
||||
String postBody = IOUtils.readToString(request.getReader());
|
||||
JsonElement json = gson.fromJson(postBody, JsonElement.class);
|
||||
if (json instanceof JsonArray) {
|
||||
@@ -200,6 +203,8 @@ public class GraphQLEndpoint extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
beforeApiCall(request, response);
|
||||
|
||||
String path = request.getPathInfo();
|
||||
if (path == null) {
|
||||
path = request.getServletPath();
|
||||
@@ -258,6 +263,16 @@ public class GraphQLEndpoint extends HttpServlet {
|
||||
response.getWriter().print(resString);
|
||||
}
|
||||
|
||||
private void beforeApiCall(HttpServletRequest request, HttpServletResponse response) {
|
||||
long maxSessionIdleTime = CBApplication.getInstance().getMaxSessionIdleTime();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_ISO_TIMESTAMP_FORMAT);
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String cookieValue = sdf.format(new Date(System.currentTimeMillis() + maxSessionIdleTime));
|
||||
|
||||
WebServiceUtils.addResponseCookie(
|
||||
response, SESSION_TEMP_COOKIE, cookieValue, maxSessionIdleTime);
|
||||
}
|
||||
|
||||
private static class WebInstrumentation extends SimpleInstrumentation {
|
||||
@Override
|
||||
public CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionResult executionResult, InstrumentationExecutionParameters parameters) {
|
||||
|
||||
Reference in New Issue
Block a user