CB-2268 add session expired exception for sessionState

This commit is contained in:
Ainur Iagudin
2022-08-17 11:01:30 +03:00
parent 35871dd683
commit cda74f44fd
3 changed files with 17 additions and 2 deletions
@@ -27,7 +27,6 @@ import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
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.rm.RMProject;
@@ -126,6 +125,11 @@ public abstract class WebServiceBindingBase<API_TYPE extends DBWService> impleme
getServletRequest(env));
}
public static WebSession findWebSession(DataFetchingEnvironment env, boolean errorOnNotFound) throws DBWebException {
return CBPlatform.getInstance().getSessionManager().findWebSession(
getServletRequest(env), errorOnNotFound);
}
@NotNull
public static WebConnectionInfo getWebConnection(WebSession session, String projectId, String connectionId) throws DBWebException {
return session.getWebConnectionInfo(projectId, connectionId);
@@ -67,7 +67,7 @@ public class WebServiceBindingCore extends WebServiceBindingBase<DBWServiceCore>
getWebSession(env), getProjectReference(env), env.getArgument("path")))
.dataFetcher("sessionPermissions", env -> getService(env).getSessionPermissions(getWebSession(env)))
.dataFetcher("sessionState", env -> getService(env).getSessionState(findWebSession(env)))
.dataFetcher("sessionState", env -> getService(env).getSessionState(findWebSession(env, true)))
.dataFetcher("connectionInfo", env -> getService(env).getConnectionState(
getWebSession(env), getProjectReference(env), env.getArgument("id")))
@@ -149,6 +149,17 @@ public class WebSessionManager {
}
}
public WebSession findWebSession(HttpServletRequest request, boolean errorOnNoFound) throws DBWebException {
WebSession webSession = findWebSession(request);
if (webSession != null) {
return webSession;
}
if (errorOnNoFound) {
throw new DBWebException("Session has expired", DBWebException.ERROR_CODE_SESSION_EXPIRED);
}
return null;
}
public void expireIdleSessions() {
long maxSessionIdleTime = DBWorkbench.getPlatform(CBPlatform.class).getApplication().getMaxSessionIdleTime();
if (CBApplication.getInstance().isConfigurationMode()) {