mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-4161 auth fix (#2084)
* CB-4161 auth fix * CB-4161 validate custom config status --------- Co-authored-by: EvgeniaBzzz <139753579+EvgeniaBzzz@users.noreply.github.com>
This commit is contained in:
co-authored by
EvgeniaBzzz
parent
d3cf9e3938
commit
390f53f36b
-11
@@ -17,7 +17,6 @@
|
||||
|
||||
package io.cloudbeaver.model.session;
|
||||
|
||||
import io.cloudbeaver.DBWConstants;
|
||||
import io.cloudbeaver.DBWUserIdentity;
|
||||
import io.cloudbeaver.DBWebException;
|
||||
import io.cloudbeaver.auth.SMAuthProviderExternal;
|
||||
@@ -38,7 +37,6 @@ import org.jkiss.utils.CommonUtils;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -114,15 +112,6 @@ public class WebSessionAuthProcessor {
|
||||
SMAuthProviderExternal<?> authProviderExternal = authProviderInstance instanceof SMAuthProviderExternal<?> ?
|
||||
(SMAuthProviderExternal<?>) authProviderInstance : null;
|
||||
|
||||
boolean providerDisabled = !isProviderEnabled(providerId);
|
||||
if (configMode || webSession.hasPermission(DBWConstants.PERMISSION_ADMIN)) {
|
||||
// 1. Admin can authorize in any providers
|
||||
// 2. When it authorizes in non-local provider for the first time we force linkUser flag
|
||||
if (providerDisabled && webSession.getUser() != null) {
|
||||
linkWithActiveUser = true;
|
||||
}
|
||||
}
|
||||
|
||||
SMSession authSession;
|
||||
|
||||
if (authProviderExternal != null && !configMode && !alreadyLoggedIn) {
|
||||
|
||||
+5
@@ -68,6 +68,11 @@ public class WebServiceAuthImpl implements DBWServiceAuth {
|
||||
if (CommonUtils.isEmpty(providerId)) {
|
||||
throw new DBWebException("Missing auth provider parameter");
|
||||
}
|
||||
WebAuthProviderDescriptor authProviderDescriptor = WebAuthProviderRegistry.getInstance()
|
||||
.getAuthProvider(providerId);
|
||||
if (authProviderDescriptor.isTrusted()) {
|
||||
throw new DBWebException(authProviderDescriptor.getLabel() + " not allowed for authorization via GQL API");
|
||||
}
|
||||
if (authParameters == null) {
|
||||
authParameters = Map.of();
|
||||
}
|
||||
|
||||
+16
-2
@@ -1241,6 +1241,9 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
|
||||
|
||||
@Override
|
||||
public SMAuthInfo authenticateAnonymousUser(@NotNull String appSessionId, @NotNull Map<String, Object> sessionParameters, @NotNull SMSessionType sessionType) throws DBException {
|
||||
if (!application.getAppConfiguration().isAnonymousAccessEnabled()) {
|
||||
throw new SMException("Anonymous access restricted");
|
||||
}
|
||||
try (Connection dbCon = database.openConnection()) {
|
||||
try (JDBCTransaction txn = new JDBCTransaction(dbCon)) {
|
||||
var smSessionId = createSmSession(appSessionId, null, sessionParameters, sessionType, dbCon);
|
||||
@@ -1276,6 +1279,9 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
|
||||
@Nullable String authProviderConfigurationId,
|
||||
@NotNull Map<String, Object> userCredentials
|
||||
) throws DBException {
|
||||
if (isProviderDisabled(authProviderId, authProviderConfigurationId)) {
|
||||
throw new SMException("Unsupported authentication provider: " + authProviderId);
|
||||
}
|
||||
var authProgressMonitor = new LoggingProgressMonitor(log);
|
||||
try (Connection dbCon = database.openConnection()) {
|
||||
try (JDBCTransaction txn = new JDBCTransaction(dbCon)) {
|
||||
@@ -2726,9 +2732,17 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
|
||||
return activeUserCredentials.getUserId();
|
||||
}
|
||||
|
||||
private boolean isProviderEnabled(@NotNull String providerId) {
|
||||
private boolean isProviderDisabled(@NotNull String providerId, @Nullable String authConfigurationId) {
|
||||
WebAuthConfiguration appConfiguration = application.getAuthConfiguration();
|
||||
return appConfiguration.isAuthProviderEnabled(providerId);
|
||||
if (!appConfiguration.isAuthProviderEnabled(providerId)) {
|
||||
return true;
|
||||
}
|
||||
if (authConfigurationId != null) {
|
||||
SMAuthProviderCustomConfiguration configuration =
|
||||
appConfiguration.getAuthProviderConfiguration(authConfigurationId);
|
||||
return configuration == null || configuration.isDisabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clearOldAuthAttemptInfo() throws DBException {
|
||||
|
||||
Reference in New Issue
Block a user