Skip to content

Commit 3b3288c

Browse files
committed
Make strictScope return null when id is null
1 parent 2fe8d53 commit 3b3288c

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public T valueInScope(Scope scope, Long id) {
426426

427427
public T valueInScope(Scope scope, Long id, boolean strictScope) {
428428
if (id == null) {
429-
return value();
429+
return strictScope ? null : value();
430430
}
431431
String value = s_depot != null ? s_depot.getConfigStringValue(_name, scope, id) : null;
432432
if (value == null) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public boolean start() {
7979
}
8080

8181
protected boolean isOAuthPluginEnabled(Long domainId) {
82+
if (domainId == null) {
83+
return Boolean.TRUE.equals(OAuth2IsPluginEnabled.value());
84+
}
8285
return Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true));
8386
}
8487

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public String encode(String password) {
9292
}
9393

9494
protected boolean isOAuthPluginEnabled(Long domainId) {
95+
if (domainId == null) {
96+
return Boolean.TRUE.equals(OAuth2IsPluginEnabled.value());
97+
}
9598
return Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true));
9699
}
97100
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
144144
domainId = userDomain.getId();
145145
}
146146

147-
if (!Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true))) {
147+
boolean oauthEnabled = domainId == null
148+
? Boolean.TRUE.equals(OAuth2IsPluginEnabled.value())
149+
: Boolean.TRUE.equals(OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainId, true));
150+
if (!oauthEnabled) {
148151
throw new CloudAuthenticationException("OAuth is not enabled, users cannot login using OAuth");
149152
}
150153

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ public void execute() {
127127
String name = authenticator.getName();
128128
authenticatorPluginNames.add(name);
129129
}
130-
if (Boolean.TRUE.equals(OAuth2AuthManager.OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, result.getDomainId(), true)) && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
130+
boolean oauthEnabled = result.getDomainId() == null
131+
? Boolean.TRUE.equals(OAuth2AuthManager.OAuth2IsPluginEnabled.value())
132+
: Boolean.TRUE.equals(OAuth2AuthManager.OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, result.getDomainId(), true));
133+
if (oauthEnabled && authenticatorPluginNames.contains(result.getProvider()) && result.isEnabled()) {
131134
r.setEnabled(true);
132135
} else {
133136
r.setEnabled(false);

0 commit comments

Comments
 (0)