Skip to content

Commit 652094d

Browse files
Vitor Hugo Homem Marzarottoerikbocks
authored andcommitted
Adds configuration for behaviour, when SAML SSO is disabled for a user
1 parent 14a7871 commit 652094d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public interface SAML2AuthManager extends PluggableAPIAuthenticator, PluggableSe
8282
ConfigKey<Boolean> SAMLRequirePasswordLogin = new ConfigKey<Boolean>("Advanced", Boolean.class, "saml2.require.password", "true",
8383
"When enabled SAML2 will validate that the SAML login was performed with a password. If disabled, other forms of authentication are allowed (two-factor, certificate, etc) on the SAML Authentication Provider", true);
8484

85+
ConfigKey<Boolean> EnableLoginAfterSAMLDisable = new ConfigKey<>("Advanced", Boolean.class, "enable.login.saml.unathourized", "true", "When enabled, if SAML SSO is disabled, enables user to login with user and password, otherwise a user with SAML SSO disabled cannot login", true);
86+
87+
8588

8689
SAMLProviderMetadata getSPMetadata();
8790
SAMLProviderMetadata getIdPMetadata(String entityId);

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,13 @@ public boolean authorizeUser(Long userId, String entityId, boolean enable) {
451451
user.setExternalEntity(entityId);
452452
user.setSource(User.Source.SAML2);
453453
} else {
454+
boolean enableLoginAfterSAMLDisable = SAML2AuthManager.EnableLoginAfterSAMLDisable.value();
454455
if (user.getSource().equals(User.Source.SAML2)) {
455-
user.setSource(User.Source.SAML2DISABLED);
456+
if(enableLoginAfterSAMLDisable) {
457+
user.setSource(User.Source.UNKNOWN);
458+
} else {
459+
user.setSource(User.Source.SAML2DISABLED);
460+
}
456461
} else {
457462
return false;
458463
}
@@ -541,6 +546,6 @@ public ConfigKey<?>[] getConfigKeys() {
541546
SAMLCloudStackRedirectionUrl, SAMLUserAttributeName,
542547
SAMLIdentityProviderMetadataURL, SAMLDefaultIdentityProviderId,
543548
SAMLSignatureAlgorithm, SAMLAppendDomainSuffix, SAMLTimeout, SAMLCheckSignature,
544-
SAMLForceAuthn, SAMLUserSessionKeyPathAttribute, SAMLRequirePasswordLogin};
549+
SAMLForceAuthn, SAMLUserSessionKeyPathAttribute, SAMLRequirePasswordLogin, EnableLoginAfterSAMLDisable};
545550
}
546551
}

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2877,7 +2877,7 @@ private UserAccount getUserAccount(String username, String password, Long domain
28772877
for (UserAuthenticator authenticator : _userAuthenticators) {
28782878
final String[] secretCodeArray = (String[])requestParameters.get(ApiConstants.SECRET_CODE);
28792879
String secretCode = ((secretCodeArray == null) ? null : secretCodeArray[0]);
2880-
if (userSource != User.Source.UNKNOWN && userSource != User.Source.SAML2DISABLED && secretCode == null) {
2880+
if (userSource != User.Source.UNKNOWN && secretCode == null) {
28812881
if (!authenticator.getName().equalsIgnoreCase(userSource.name())) {
28822882
continue;
28832883
}

0 commit comments

Comments
 (0)