Skip to content

Commit 5d5fa04

Browse files
Marcus SorensenMarcus Sorensen
andauthored
saml: Add EncryptedElementType key resolver to SAML plugin (#7268)
There are multiple ways in which a SAML response can be formatted, especially when encryption is enabled. This PR removes the hardcoding of EncryptedKeyResolver= InlineEncryptedKeyResolver in favor of using a ChainingEncryptedKeyResolver which will try multiple resolvers. It preserves the InlineEncryptedKeyResolver as the first option but adds EncryptedElementTypeEncryptedKeyResolver to the chain of resolvers to try. ChainingEncryptedKeyResolver is a bit finicky in that you can't provide it a list of resolvers, you can only fetch its internal list and add to it. Theoretically we could add all of the resolver types to the chain, but for now just preserving the ones known to be in use. Co-authored-by: Marcus Sorensen <mls@apple.com>
1 parent ce98157 commit 5d5fa04

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@
5555
import org.opensaml.saml2.core.Response;
5656
import org.opensaml.saml2.core.StatusCode;
5757
import org.opensaml.saml2.encryption.Decrypter;
58+
import org.opensaml.saml2.encryption.EncryptedElementTypeEncryptedKeyResolver;
5859
import org.opensaml.xml.ConfigurationException;
60+
import org.opensaml.xml.encryption.ChainingEncryptedKeyResolver;
5961
import org.opensaml.xml.encryption.DecryptionException;
60-
import org.opensaml.xml.encryption.EncryptedKeyResolver;
6162
import org.opensaml.xml.encryption.InlineEncryptedKeyResolver;
6263
import org.opensaml.xml.io.UnmarshallingException;
6364
import org.opensaml.xml.security.SecurityHelper;
@@ -253,7 +254,9 @@ public String authenticate(final String command, final Map<String, Object[]> par
253254
Credential credential = SecurityHelper.getSimpleCredential(idpMetadata.getEncryptionCertificate().getPublicKey(),
254255
spMetadata.getKeyPair().getPrivate());
255256
StaticKeyInfoCredentialResolver keyInfoResolver = new StaticKeyInfoCredentialResolver(credential);
256-
EncryptedKeyResolver keyResolver = new InlineEncryptedKeyResolver();
257+
ChainingEncryptedKeyResolver keyResolver = new ChainingEncryptedKeyResolver();
258+
keyResolver.getResolverChain().add(new InlineEncryptedKeyResolver());
259+
keyResolver.getResolverChain().add(new EncryptedElementTypeEncryptedKeyResolver());
257260
Decrypter decrypter = new Decrypter(null, keyInfoResolver, keyResolver);
258261
decrypter.setRootInNewDocument(true);
259262
List<EncryptedAssertion> encryptedAssertions = processedSAMLResponse.getEncryptedAssertions();

0 commit comments

Comments
 (0)