mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-793 Auth API additions
This commit is contained in:
@@ -645,6 +645,12 @@ public class WebSession implements DBASession, DBAAuthCredentialsProvider, IAdap
|
||||
}
|
||||
}
|
||||
|
||||
public List<WebAuthInfo> getAllAuthInfo() {
|
||||
synchronized (authTokens) {
|
||||
return new ArrayList<>(authTokens);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAuthInfo(@NotNull WebAuthInfo authInfo) throws DBException {
|
||||
WebUser newUser = authInfo.getUser();
|
||||
if (this.user == null && newUser != null) {
|
||||
|
||||
@@ -30,30 +30,56 @@ type AuthProviderInfo {
|
||||
credentialParameters: [AuthCredentialInfo!]!
|
||||
}
|
||||
|
||||
type UserAuthInfo {
|
||||
# User unique identifier
|
||||
userId: String!
|
||||
# Human readable display name. May be null
|
||||
displayName: String
|
||||
# Auth provider ID
|
||||
authProvider: String!
|
||||
type UserAuthToken {
|
||||
# Auth provider used for autgorization
|
||||
provider: ID!
|
||||
|
||||
# Authorization time
|
||||
loginTime: DateTime!
|
||||
|
||||
# Optional login message
|
||||
message: String
|
||||
|
||||
# Auth origin
|
||||
origin: ObjectOrigin!
|
||||
}
|
||||
|
||||
type UserAuthInfo {
|
||||
# User unique identifier
|
||||
userId: String! @deprecated
|
||||
# Human readable display name. May be null
|
||||
displayName: String @deprecated
|
||||
# Auth provider ID
|
||||
authProvider: String! @deprecated
|
||||
|
||||
loginTime: DateTime! @deprecated
|
||||
|
||||
# Optional login message
|
||||
message: String @deprecated
|
||||
|
||||
origin: ObjectOrigin! @deprecated
|
||||
}
|
||||
|
||||
type UserInfo {
|
||||
# User unique identifier
|
||||
userId: String!
|
||||
# Human readable display name. May be null
|
||||
displayName: String
|
||||
|
||||
authTokens: [UserAuthToken!]!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
|
||||
# Authorize user using specified auth provider
|
||||
|
||||
authLogin(provider: ID!, credentials: Object!): UserAuthInfo!
|
||||
# Logouts user. If provider not specified then all authorizations are revoked from session.
|
||||
authLogout(provider: ID): Boolean
|
||||
|
||||
sessionUser: UserAuthInfo
|
||||
activeUser: UserInfo
|
||||
|
||||
sessionUser: UserAuthInfo @deprecated
|
||||
|
||||
authProviders: [AuthProviderInfo!]!
|
||||
|
||||
|
||||
+4
@@ -38,6 +38,10 @@ public interface DBWServiceAuth extends DBWService {
|
||||
@WebAction(requirePermissions = {} )
|
||||
void authLogout(@NotNull WebSession webSession, @Nullable String providerId) throws DBWebException;
|
||||
|
||||
@WebAction(requirePermissions = {})
|
||||
WebUserInfo activeUser(@NotNull WebSession webSession) throws DBWebException;
|
||||
|
||||
@Deprecated
|
||||
@WebAction(requirePermissions = {})
|
||||
WebAuthInfo sessionUser(@NotNull WebSession webSession) throws DBWebException;
|
||||
|
||||
|
||||
+1
@@ -43,6 +43,7 @@ public class WebServiceBindingAuth extends WebServiceBindingBase<DBWServiceAuth>
|
||||
getService(env).authLogout(getWebSession(env), env.getArgument("provider"));
|
||||
return true;
|
||||
})
|
||||
.dataFetcher("activeUser", env -> getService(env).activeUser(getWebSession(env, false)))
|
||||
.dataFetcher("sessionUser", env -> getService(env).sessionUser(getWebSession(env, false)))
|
||||
.dataFetcher("authProviders", env -> getService(env).getAuthProviders(getWebSession(env)))
|
||||
;
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* DBeaver - Universal Database Manager
|
||||
* Copyright (C) 2010-2021 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.service.auth;
|
||||
|
||||
import io.cloudbeaver.model.session.WebAuthInfo;
|
||||
import io.cloudbeaver.model.session.WebSession;
|
||||
import io.cloudbeaver.model.user.WebUser;
|
||||
import org.jkiss.dbeaver.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* WebUserInfo
|
||||
*/
|
||||
public class WebUserInfo {
|
||||
|
||||
private static final Log log = Log.getLog(WebUserInfo.class);
|
||||
|
||||
private final WebSession session;
|
||||
private final WebUser user;
|
||||
|
||||
public WebUserInfo(WebSession session, WebUser user) {
|
||||
this.session = session;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return user.getUserId();
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return user.getDisplayName();
|
||||
}
|
||||
|
||||
public List<WebAuthInfo> getAuthTokens() {
|
||||
return session.getAllAuthInfo();
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -26,6 +26,7 @@ import io.cloudbeaver.registry.WebServiceRegistry;
|
||||
import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.server.CBPlatform;
|
||||
import io.cloudbeaver.service.auth.DBWServiceAuth;
|
||||
import io.cloudbeaver.service.auth.WebUserInfo;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.code.Nullable;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
@@ -127,6 +128,14 @@ public class WebServiceAuthImpl implements DBWServiceAuth {
|
||||
webSession.removeAuthInfo(providerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebUserInfo activeUser(@NotNull WebSession webSession) throws DBWebException {
|
||||
if (webSession.getUser() == null) {
|
||||
return null;
|
||||
}
|
||||
return new WebUserInfo(webSession, webSession.getUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebAuthInfo sessionUser(@NotNull WebSession webSession) throws DBWebException {
|
||||
if (webSession.getUser() == null) {
|
||||
|
||||
Reference in New Issue
Block a user