Skip to content

Commit

Permalink
CB-4257 validate required features for providers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-skoblikov committed Jan 23, 2024
1 parent 76454a3 commit 88eb789
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class WebAuthProviderDescriptor extends AbstractDescriptor {
private final Map<SMSubjectType, List<DBPPropertyDescriptor>> metaParameters = new HashMap<>();
private SMAuthProvider<?> instance;
private final DBPImage icon;
private final Map<String, PropertyDescriptor> configurationParameters = new LinkedHashMap<>();
private final Map<String, WebAuthProviderProperty> configurationParameters = new LinkedHashMap<>();
private final List<SMAuthCredentialsProfile> credentialProfiles = new ArrayList<>();
private final boolean configurable;
private final boolean trusted;
Expand All @@ -72,7 +72,7 @@ public WebAuthProviderDescriptor(IConfigurationElement cfg) {
String category = propGroup.getAttribute(PropertyDescriptor.ATTR_LABEL);
IConfigurationElement[] propElements = propGroup.getChildren(PropertyDescriptor.TAG_PROPERTY);
for (IConfigurationElement prop : propElements) {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(category, prop);
WebAuthProviderProperty propertyDescriptor = new WebAuthProviderProperty(category, prop);
configurationParameters.put(CommonUtils.toString(propertyDescriptor.getId()), propertyDescriptor);
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public boolean isRequired() {
return isRequired;
}

public List<PropertyDescriptor> getConfigurationParameters() {
public List<WebAuthProviderProperty> getConfigurationParameters() {
return new ArrayList<>(configurationParameters.values());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.registry;

import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.impl.PropertyDescriptor;

public class WebAuthProviderProperty extends PropertyDescriptor {
private final String[] requiredFeatures;

public WebAuthProviderProperty(String category, IConfigurationElement config) {
super(category, config);
String featuresAttr = config.getAttribute("requiredFeatures");
this.requiredFeatures = featuresAttr == null ? new String[0] : featuresAttr.split(",");
}

@NotNull
public String[] getRequiredFeatures() {
return requiredFeatures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,20 @@ public List<WebPropertyInfo> listAuthProviderConfigurationParameters(@NotNull We
if (authProvider == null) {
throw new DBWebException("Invalid provider ID " + providerId);
}
var application = CBApplication.getInstance();
return authProvider.getConfigurationParameters().stream().filter(p -> {
if (p.hasFeature("distributed")) {
return CBApplication.getInstance().isDistributed();
boolean allFeaturesEnabled = true;
for (String feature : p.getRequiredFeatures()) {
if (feature.equals("distributed")) {
allFeaturesEnabled = CBApplication.getInstance().isDistributed();
} else {
allFeaturesEnabled = application.getAppConfiguration().isFeatureEnabled(feature);
}
if (!allFeaturesEnabled) {
break;
}
}
return true;
return allFeaturesEnabled;
}).map(p -> new WebPropertyInfo(webSession, p)).collect(Collectors.toList());
}

Expand Down

0 comments on commit 88eb789

Please sign in to comment.