Skip to content

Commit a578d56

Browse files
author
Vitor Hugo Homem Marzarotto
committed
Adds configuration for behaviour, when SAML SSO is disabled for a user
1 parent a489d07 commit a578d56

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
@@ -453,8 +453,13 @@ public boolean authorizeUser(Long userId, String entityId, boolean enable) {
453453
user.setExternalEntity(entityId);
454454
user.setSource(User.Source.SAML2);
455455
} else {
456+
boolean enableLoginAfterSAMLDisable = SAML2AuthManager.EnableLoginAfterSAMLDisable.value();
456457
if (user.getSource().equals(User.Source.SAML2)) {
457-
user.setSource(User.Source.SAML2DISABLED);
458+
if(enableLoginAfterSAMLDisable) {
459+
user.setSource(User.Source.UNKNOWN);
460+
} else {
461+
user.setSource(User.Source.SAML2DISABLED);
462+
}
458463
} else {
459464
return false;
460465
}
@@ -543,6 +548,6 @@ public ConfigKey<?>[] getConfigKeys() {
543548
SAMLCloudStackRedirectionUrl, SAMLUserAttributeName,
544549
SAMLIdentityProviderMetadataURL, SAMLDefaultIdentityProviderId,
545550
SAMLSignatureAlgorithm, SAMLAppendDomainSuffix, SAMLTimeout, SAMLCheckSignature,
546-
SAMLForceAuthn, SAMLUserSessionKeyPathAttribute, SAMLRequirePasswordLogin};
551+
SAMLForceAuthn, SAMLUserSessionKeyPathAttribute, SAMLRequirePasswordLogin, EnableLoginAfterSAMLDisable};
547552
}
548553
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ private UserAccount getUserAccount(String username, String password, Long domain
27232723
for (UserAuthenticator authenticator : _userAuthenticators) {
27242724
final String[] secretCodeArray = (String[])requestParameters.get(ApiConstants.SECRET_CODE);
27252725
String secretCode = ((secretCodeArray == null) ? null : secretCodeArray[0]);
2726-
if (userSource != User.Source.UNKNOWN && userSource != User.Source.SAML2DISABLED && secretCode == null) {
2726+
if (userSource != User.Source.UNKNOWN && secretCode == null) {
27272727
if (!authenticator.getName().equalsIgnoreCase(userSource.name())) {
27282728
continue;
27292729
}

0 commit comments

Comments
 (0)