From 1960c608cdb9ece44b27de3f346d37c8d76cc1f3 Mon Sep 17 00:00:00 2001 From: pedroigor Date: Thu, 29 Jan 2015 00:04:02 -0200 Subject: [PATCH] [KEYCLOAK-883] - Initial tests for SAML brokering. --- .../broker/saml/SAMLIdentityProvider.java | 2 +- .../saml/SAMLIdentityProviderConfig.java | 12 +- .../saml/SAMLIdentityProviderFactory.java | 14 +- .../realm-identity-provider-saml.html | 6 +- .../models/cache/entities/CachedRealm.java | 7 +- .../services/resources/flows/Urls.java | 2 +- .../broker/AbstractIdentityProviderTest.java | 137 +++++++++++++ .../IdentityProviderRegistrationTest.java | 2 +- .../broker/ImportIdentityProviderTest.java | 18 +- .../SAMLKeyCloakServerBrokerBasicTest.java | 34 ++++ ...KeyCloakServerBrokerWithSignatureTest.java | 34 ++++ .../social/CustomSocialProvider.java | 2 +- .../social/CustomSocialProviderFactory.java | 2 +- .../broker/util/UserSessionStatusServlet.java | 80 ++++++++ .../testsuite/rule/AbstractKeycloakRule.java | 7 + ...cloak.social.SocialIdentityProviderFactory | 2 +- .../broker-test/test-app-keycloak.json | 11 ++ ...broker-realm-with-saml-with-signature.json | 46 +++++ .../test-broker-realm-with-saml.json | 40 ++++ .../broker-test/test-realm-with-broker.json | 145 ++++++++++++++ .../test-realm-with-identity-provider.json | 183 ------------------ 21 files changed, 573 insertions(+), 213 deletions(-) create mode 100644 testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java create mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerBasicTest.java create mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/broker/SAMLKeyCloakServerBrokerWithSignatureTest.java rename testsuite/integration/src/test/java/org/keycloak/testsuite/broker/{ => provider}/social/CustomSocialProvider.java (96%) rename testsuite/integration/src/test/java/org/keycloak/testsuite/broker/{ => provider}/social/CustomSocialProviderFactory.java (96%) create mode 100644 testsuite/integration/src/test/java/org/keycloak/testsuite/broker/util/UserSessionStatusServlet.java create mode 100755 testsuite/integration/src/test/resources/broker-test/test-app-keycloak.json create mode 100755 testsuite/integration/src/test/resources/broker-test/test-broker-realm-with-saml-with-signature.json create mode 100755 testsuite/integration/src/test/resources/broker-test/test-broker-realm-with-saml.json create mode 100755 testsuite/integration/src/test/resources/broker-test/test-realm-with-broker.json delete mode 100755 testsuite/integration/src/test/resources/model/test-realm-with-identity-provider.json diff --git a/broker/saml/src/main/java/org/keycloak/broker/saml/SAMLIdentityProvider.java b/broker/saml/src/main/java/org/keycloak/broker/saml/SAMLIdentityProvider.java index c389b1df4a..8dc36a1193 100644 --- a/broker/saml/src/main/java/org/keycloak/broker/saml/SAMLIdentityProvider.java +++ b/broker/saml/src/main/java/org/keycloak/broker/saml/SAMLIdentityProvider.java @@ -199,7 +199,7 @@ public class SAMLIdentityProvider extends AbstractIdentityProvider keyDescriptor = idpDescriptor.getKeyDescriptor(); - String defaultPublicKey = null; + String defaultCertificate = null; if (keyDescriptor != null) { for (KeyDescriptorType keyDescriptorType : keyDescriptor) { @@ -91,22 +91,22 @@ public class SAMLIdentityProviderFactory extends AbstractIdentityProviderFactory Element x509KeyInfo = DocumentUtil.getChildElement(keyInfo, new QName("dsig", "X509Certificate")); if (KeyTypes.SIGNING.equals(keyDescriptorType.getUse())) { - samlIdentityProviderConfig.setSigningPublicKey(x509KeyInfo.getTextContent()); + samlIdentityProviderConfig.setSigningCertificate(x509KeyInfo.getTextContent()); } else if (KeyTypes.ENCRYPTION.equals(keyDescriptorType.getUse())) { samlIdentityProviderConfig.setEncryptionPublicKey(x509KeyInfo.getTextContent()); } else if (keyDescriptorType.getUse() == null) { - defaultPublicKey = x509KeyInfo.getTextContent(); + defaultCertificate = x509KeyInfo.getTextContent(); } } } - if (defaultPublicKey != null) { - if (samlIdentityProviderConfig.getSigningPublicKey() == null) { - samlIdentityProviderConfig.setSigningPublicKey(defaultPublicKey); + if (defaultCertificate != null) { + if (samlIdentityProviderConfig.getSigningCertificate() == null) { + samlIdentityProviderConfig.setSigningCertificate(defaultCertificate); } if (samlIdentityProviderConfig.getEncryptionPublicKey() == null) { - samlIdentityProviderConfig.setEncryptionPublicKey(defaultPublicKey); + samlIdentityProviderConfig.setEncryptionPublicKey(defaultCertificate); } } diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-identity-provider-saml.html b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-identity-provider-saml.html index 5a87057295..e5ba81f2ac 100755 --- a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-identity-provider-saml.html +++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-identity-provider-saml.html @@ -52,11 +52,11 @@
- +
-