Skip to content

Commit 57c837c

Browse files
committed
Add strictScope to ConfigKey to disable global fallback for domain-scoped oauth2.enabled
1 parent 7a55ecb commit 57c837c

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,18 @@ protected T valueInGlobalOrAvailableParentScope(Scope scope, Long id) {
421421
}
422422

423423
public T valueInScope(Scope scope, Long id) {
424+
return valueInScope(scope, id, false);
425+
}
426+
427+
public T valueInScope(Scope scope, Long id, boolean strictScope) {
424428
if (id == null) {
425429
return value();
426430
}
427431
String value = s_depot != null ? s_depot.getConfigStringValue(_name, scope, id) : null;
428432
if (value == null) {
433+
if (strictScope) {
434+
return null;
435+
}
429436
return valueInGlobalOrAvailableParentScope(scope, id);
430437
}
431438
logger.trace("Scope({}) value for config ({}): {}", scope, _name, _value);

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean start() {
7070
}
7171

7272
protected boolean isOAuthPluginEnabled(Long domainId) {
73-
return OAuth2IsPluginEnabled.valueIn(domainId);
73+
return Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true));
7474
}
7575

7676
@Override

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.ApiConstants;
2828
import org.apache.cloudstack.auth.UserAuthenticator;
2929
import org.apache.cloudstack.auth.UserOAuth2Authenticator;
30+
import org.apache.cloudstack.framework.config.ConfigKey;
3031

3132
import javax.inject.Inject;
3233
import java.util.Map;
@@ -91,6 +92,6 @@ public String encode(String password) {
9192
}
9293

9394
protected boolean isOAuthPluginEnabled(Long domainId) {
94-
return OAuth2IsPluginEnabled.valueIn(domainId);
95+
return Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true));
9596
}
9697
}

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.cloudstack.api.response.DomainResponse;
4242
import org.apache.cloudstack.api.response.ListResponse;
4343
import org.apache.cloudstack.auth.UserOAuth2Authenticator;
44+
import org.apache.cloudstack.framework.config.ConfigKey;
4445
import org.apache.cloudstack.oauth2.OAuth2AuthManager;
4546
import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse;
4647
import org.apache.cloudstack.oauth2.vo.OauthProviderVO;
@@ -138,7 +139,7 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
138139
Domain domain = result.getDomainId() != null ? ApiDBUtils.findDomainById(result.getDomainId()) : null;
139140
OauthProviderResponse r = new OauthProviderResponse(result.getUuid(), result.getProvider(),
140141
result.getDescription(), result.getClientId(), result.getSecretKey(), result.getRedirectUri(), domain);
141-
if (OAuth2AuthManager.OAuth2IsPluginEnabled.valueIn(result.getDomainId()) && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
142+
if (Boolean.TRUE.equals(OAuth2AuthManager.OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, result.getDomainId(), true)) && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
142143
r.setEnabled(true);
143144
} else {
144145
r.setEnabled(false);

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import java.util.Map;
5151
import java.net.InetAddress;
5252

53+
import org.apache.cloudstack.framework.config.ConfigKey;
54+
5355
import static org.apache.cloudstack.oauth2.OAuth2AuthManager.OAuth2IsPluginEnabled;
5456

5557
@APICommand(name = "oauthlogin", description = "Logs a user into the CloudStack after successful verification of OAuth secret code from the particular provider." +
@@ -142,7 +144,7 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
142144
domainId = userDomain.getId();
143145
}
144146

145-
if (!OAuth2IsPluginEnabled.valueIn(domainId)) {
147+
if (!Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true))) {
146148
throw new CloudAuthenticationException("OAuth is not enabled, users cannot login using OAuth");
147149
}
148150

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/UpdateOAuthProviderCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.cloud.domain.Domain;
2121
import org.apache.cloudstack.api.ApiCommandResourceType;
2222
import org.apache.cloudstack.auth.UserOAuth2Authenticator;
23+
import org.apache.cloudstack.framework.config.ConfigKey;
2324
import org.apache.cloudstack.oauth2.OAuth2AuthManager;
2425
import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse;
2526
import org.apache.cloudstack.oauth2.vo.OauthProviderVO;
@@ -126,7 +127,7 @@ public void execute() {
126127
String name = authenticator.getName();
127128
authenticatorPluginNames.add(name);
128129
}
129-
if (OAuth2AuthManager.OAuth2IsPluginEnabled.valueIn(result.getDomainId()) && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
130+
if (Boolean.TRUE.equals(OAuth2AuthManager.OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, result.getDomainId(), true)) && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
130131
r.setEnabled(true);
131132
} else {
132133
r.setEnabled(false);

0 commit comments

Comments
 (0)