Skip to content

Commit 8fac94f

Browse files
vits-hugsVitor Hugo Homem Marzarottoerikbocks
authored andcommitted
Fix saml bug unable to login (apache#10868)
* Fix check * Adds configuration for behaviour, when SAML SSO is disabled for a user * set default configuration value to false and rename it to enable.login.with.disabled.saml --------- Co-authored-by: Vitor Hugo Homem Marzarotto <vitor.marzarotto@scclouds.com.br> Co-authored-by: erikbocks <erik.bock@outlook.com>
1 parent 44d5d62 commit 8fac94f

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

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
@@ -85,6 +85,9 @@ public interface SAML2AuthManager extends PluggableAPIAuthenticator, PluggableSe
8585
ConfigKey<Boolean> SAMLRequirePasswordLogin = new ConfigKey<Boolean>("Advanced", Boolean.class, "saml2.require.password", "true",
8686
"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);
8787

88+
ConfigKey<Boolean> EnableLoginAfterSAMLDisable = new ConfigKey<>("Advanced", Boolean.class, "enable.login.with.disabled.saml", "false", "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);
89+
90+
8891

8992
SAMLProviderMetadata getSPMetadata();
9093
SAMLProviderMetadata getIdPMetadata(String entityId);

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

Lines changed: 8 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
}
@@ -542,6 +547,7 @@ public ConfigKey<?>[] getConfigKeys() {
542547
SAMLIdentityProviderMetadataURL, SAMLDefaultIdentityProviderId,
543548
SAMLSignatureAlgorithm, SAMLAppendDomainSuffix, SAMLTimeout, SAMLCheckSignature,
544549
SAMLForceAuthn, SAMLUserSessionKeyPathAttribute, SAMLFailedLoginRedirectUrl, SAMLRequirePasswordLogin,
545-
SAML2Config.SAMLIdentityProviderPortalUrl, SAML2Config.SAMLIdentityProviderPassword};
550+
SAML2Config.SAMLIdentityProviderPortalUrl, SAML2Config.SAMLIdentityProviderPassword, EnableLoginAfterSAMLDisable
551+
};
546552
}
547553
}

0 commit comments

Comments
 (0)