-
Notifications
You must be signed in to change notification settings - Fork 536
Dbeaver/cloudbeaver#4120 support token header #4259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serge-rider
merged 25 commits into
devel
from
dbeaver/cloudbeaver#4120-support-token-header
May 11, 2026
Merged
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5e7159c
dbeaver/cloudbeaver#4120 support token header
HocKu7 a2fe997
Merge branch 'devel' into dbeaver/cloudbeaver#4120-support-token-header
HocKu7 e9816e5
dbeaver/cloudbeaver#4120 support token header
HocKu7 ecfb5fb
dbeaver/cloudbeaver#4120 support token header
HocKu7 2ef8546
dbeaver/cloudbeaver#4120 support token header
HocKu7 c3ef7e2
dbeaver/cloudbeaver#4120 support token header
HocKu7 178a049
dbeaver/cloudbeaver#4120 support token header
HocKu7 61d6af1
dbeaver/cloudbeaver#4120 support token header
HocKu7 f895e85
Merge branch 'devel' into dbeaver/cloudbeaver#4120-support-token-header
HocKu7 991c548
dbeaver/pro#4120 added tests, now session in session holder
HocKu7 5d33595
dbeaver/pro#4120 review fix naming
HocKu7 02bc848
dbeaver/pro#4120 review fixes
HocKu7 4861126
Merge branch 'refs/heads/devel' into dbeaver/cloudbeaver#4120-support…
HocKu7 3dff740
dbeaver/cloudbeaver#4120 review fixes
HocKu7 881ddda
Merge branch 'devel' into dbeaver/cloudbeaver#4120-support-token-header
serge-rider 83ec357
dbeaver/cloudbeaver#4120 session type now final
HocKu7 cb1d13c
Merge branch 'devel' into dbeaver/cloudbeaver#4120-support-token-header
HocKu7 6fdf355
dbeaver/cloudbeaver#4120 remove part from ce
HocKu7 5c2f2ef
dbeaver/cloudbeaver#4120 remove part from ce
HocKu7 862ea72
Merge branch 'devel' into dbeaver/cloudbeaver#4120-support-token-header
HocKu7 9e32e7c
dbeaver/cloudbeaver#4120 fix header name
HocKu7 1dc9370
dbeaver/cloudbeaver#4120 review fix
HocKu7 91f1f8d
dbeaver/cloudbeaver#4120 review fix
HocKu7 24f075c
dbeaver/cloudbeaver#4120 fix review
HocKu7 fbdf2f6
Merge branch 'devel' into dbeaver/cloudbeaver#4120-support-token-header
EvgeniaBzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/SessionType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * DBeaver - Universal Database Manager | ||
| * Copyright (C) 2010-2026 DBeaver Corp and others | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.cloudbeaver.model.session; | ||
|
|
||
| public enum SessionType { | ||
| WEB, | ||
| HEADLESS, | ||
| API_TOKEN | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,8 @@ | |
| import io.cloudbeaver.model.apilog.ApiCallInterceptor; | ||
| import io.cloudbeaver.model.session.WebSession; | ||
| import io.cloudbeaver.registry.WebServiceRegistry; | ||
| import io.cloudbeaver.server.CBConstants; | ||
| import io.cloudbeaver.server.WebAppSessionManager; | ||
| import io.cloudbeaver.server.WebAppUtils; | ||
| import io.cloudbeaver.service.DBWBindingContext; | ||
| import io.cloudbeaver.service.DBWServiceBindingGraphQL; | ||
|
|
@@ -43,6 +45,7 @@ | |
| import jakarta.servlet.http.HttpServletResponse; | ||
| 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.data.json.JSONUtils; | ||
| import org.jkiss.dbeaver.utils.MimeTypes; | ||
|
|
@@ -239,6 +242,32 @@ private void executeQuery( | |
| @Nullable Map<String, Object> variables, | ||
| @Nullable String operationName | ||
| ) throws IOException { | ||
|
|
||
|
|
||
| WebAppSessionManager sessionManager = WebAppUtils.getWebApplication().getSessionManager(); | ||
| String userId = GraphQLLoggerUtil.getUserId(request); | ||
| LocalDateTime startTime = LocalDateTime.now(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to pass these params to isQueryHandledBeforeExecution and notifyApiCallInterceptor, they can be extracted from request on demand. |
||
| String token = request.getHeader(CBConstants.HEADER_API_TOKEN); | ||
| if (token != null) { | ||
| try { | ||
| sessionManager.getWebSessionByToken(request, token); | ||
| } catch (DBException e) { | ||
| log.error("Error obtaining web session by token", e); | ||
| DBWebException webException = new DBWebException( | ||
| "Error obtaining web session by token: " + e.getMessage(), | ||
| DBWebException.ERROR_CODE_AUTH_REQUIRED, | ||
| e | ||
| ); | ||
| ExecutionResult executionResult = ExecutionResult.newExecutionResult() | ||
| .addError(webException) | ||
| .build(); | ||
| notifyApiCallInterceptor(request, variables, operationName, userId, startTime, webException.getMessage()); | ||
| writeExecutionResult(request, response, executionResult); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| Map<String, Object> mapOfContext = | ||
| Map.of( | ||
| "request", request, | ||
|
|
@@ -254,8 +283,6 @@ private void executeQuery( | |
| if (operationName != null) { | ||
| contextBuilder.operationName(operationName); | ||
| } | ||
| String userId = GraphQLLoggerUtil.getUserId(request); | ||
| LocalDateTime startTime = LocalDateTime.now(); | ||
| ExecutionInput executionInput = contextBuilder.build(); | ||
| ExecutionResult executionResult = null; | ||
| Exception executionException = null; | ||
|
|
@@ -271,23 +298,44 @@ private void executeQuery( | |
| } else if (executionException != null) { | ||
| errorMessage = executionException.getMessage(); | ||
| } | ||
| if (WebAppUtils.getWebApplication() instanceof ApiCallInterceptor apiCallInterceptor) { | ||
| apiCallInterceptor.onApiCallEvent( | ||
| request, | ||
| variables, | ||
| CommonUtils.notEmpty(operationName), userId, startTime, | ||
| errorMessage, | ||
| API_PROTOCOL | ||
| ); | ||
| } | ||
| notifyApiCallInterceptor(request, variables, operationName, userId, startTime, errorMessage); | ||
| } | ||
|
|
||
| if (executionResult != null) { | ||
| Map<String, Object> resJSON = executionResult.toSpecification(); | ||
| String resString = gson.toJson(resJSON); | ||
| setDevelHeaders(request, response); | ||
| response.setContentType(GraphQLConstants.CONTENT_TYPE_JSON_UTF8); | ||
| response.getWriter().print(resString); | ||
| writeExecutionResult(request, response, executionResult); | ||
| } | ||
| } | ||
|
|
||
| private void writeExecutionResult( | ||
| @NotNull HttpServletRequest request, | ||
| @NotNull HttpServletResponse response, | ||
| @NotNull ExecutionResult executionResult | ||
| ) throws IOException { | ||
| Map<String, Object> resJSON = executionResult.toSpecification(); | ||
| String resString = gson.toJson(resJSON); | ||
| setDevelHeaders(request, response); | ||
| response.setContentType(GraphQLConstants.CONTENT_TYPE_JSON_UTF8); | ||
| response.getWriter().print(resString); | ||
| } | ||
|
|
||
| private void notifyApiCallInterceptor( | ||
| @NotNull HttpServletRequest request, | ||
| @Nullable Map<String, Object> variables, | ||
| @Nullable String operationName, | ||
| @Nullable String userId, | ||
| @NotNull LocalDateTime startTime, | ||
| @Nullable String errorMessage | ||
| ) { | ||
| if (WebAppUtils.getWebApplication() instanceof ApiCallInterceptor apiCallInterceptor) { | ||
| apiCallInterceptor.onApiCallEvent( | ||
| request, | ||
| variables, | ||
| CommonUtils.notEmpty(operationName), | ||
| userId, | ||
| startTime, | ||
| errorMessage, | ||
| API_PROTOCOL | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.