diff --git a/services/src/main/java/org/keycloak/protocol/saml/EntityDescriptorDescriptionConverter.java b/services/src/main/java/org/keycloak/protocol/saml/EntityDescriptorDescriptionConverter.java
index 38d0c6a625..5a9d821dfc 100755
--- a/services/src/main/java/org/keycloak/protocol/saml/EntityDescriptorDescriptionConverter.java
+++ b/services/src/main/java/org/keycloak/protocol/saml/EntityDescriptorDescriptionConverter.java
@@ -117,6 +117,15 @@ public class EntityDescriptorDescriptionConverter implements ClientDescriptionCo
attributes.put(SamlProtocol.SAML_ASSERTION_CONSUMER_URL_REDIRECT_ATTRIBUTE, assertionConsumerServiceRedirectBinding);
redirectUris.add(assertionConsumerServiceRedirectBinding);
}
+ if (spDescriptorType.getNameIDFormat() != null) {
+ for (String format : spDescriptorType.getNameIDFormat()) {
+ String attribute = SamlClient.samlNameIDFormatToClientAttribute(format);
+ if (attribute != null) {
+ attributes.put(SamlConfigAttributes.SAML_NAME_ID_FORMAT_ATTRIBUTE, attribute);
+ break;
+ }
+ }
+ }
for (KeyDescriptorType keyDescriptor : spDescriptorType.getKeyDescriptor()) {
X509Certificate cert = null;
diff --git a/services/src/main/java/org/keycloak/protocol/saml/SamlClient.java b/services/src/main/java/org/keycloak/protocol/saml/SamlClient.java
index 09659e4c83..0415a72d77 100755
--- a/services/src/main/java/org/keycloak/protocol/saml/SamlClient.java
+++ b/services/src/main/java/org/keycloak/protocol/saml/SamlClient.java
@@ -74,6 +74,22 @@ public class SamlClient extends ClientConfigResolver {
return nameIdFormat;
}
+
+ public static String samlNameIDFormatToClientAttribute(String nameIdFormat) {
+ if (nameIdFormat.equals(JBossSAMLURIConstants.NAMEID_FORMAT_EMAIL.get())) {
+ return "email";
+ } else if (nameIdFormat.equals(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())) {
+ return "persistent";
+ } else if (nameIdFormat.equals(JBossSAMLURIConstants.NAMEID_FORMAT_TRANSIENT.get())) {
+ return "transient";
+ } else if (nameIdFormat.equals(JBossSAMLURIConstants.NAMEID_FORMAT_UNSPECIFIED.get())) {
+ return "username";
+ }
+ return null;
+
+ }
+
+
public void setNameIDFormat(String format) {
client.setAttribute(SamlConfigAttributes.SAML_NAME_ID_FORMAT_ATTRIBUTE, format);
}
diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTest.java
index 30fe7b6a14..37f2b65c5a 100755
--- a/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTest.java
+++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/keycloaksaml/SamlAdapterTest.java
@@ -17,10 +17,15 @@
package org.keycloak.testsuite.keycloaksaml;
+import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
+import org.keycloak.admin.client.Keycloak;
+import org.keycloak.admin.client.resource.RealmResource;
+import org.keycloak.models.Constants;
+import org.keycloak.representations.idm.ClientRepresentation;
import org.openqa.selenium.WebDriver;
import javax.ws.rs.client.Client;
@@ -28,6 +33,8 @@ import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
+import static org.junit.Assert.assertEquals;
+
/**
* @author Bill Burke
* @version $Revision: 1 $
@@ -190,5 +197,26 @@ public class SamlAdapterTest {
}
+ /**
+ * Test KEYCLOAK-2718
+ */
+ @Test
+ public void testNameIDFormatImport() throws Exception {
+ String resourcePath = "/keycloak-saml/sp-metadata-email-nameid.xml";
+ Keycloak keycloak = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID, null);
+ RealmResource admin = keycloak.realm("demo");
+
+ admin.toRepresentation();
+
+ ClientRepresentation clientRep = admin.convertClientDescription(IOUtils.toString(SamlAdapterTestStrategy.class.getResourceAsStream(resourcePath)));
+ assertEquals("email", clientRep.getAttributes().get("saml_name_id_format"));
+
+
+ keycloak.close();
+
+
+ }
+
+
}
diff --git a/testsuite/integration/src/test/resources/keycloak-saml/sp-metadata-email-nameid.xml b/testsuite/integration/src/test/resources/keycloak-saml/sp-metadata-email-nameid.xml
new file mode 100755
index 0000000000..d0a697c9f9
--- /dev/null
+++ b/testsuite/integration/src/test/resources/keycloak-saml/sp-metadata-email-nameid.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+ urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
+
+
+
+
+
+
+
+ MIIB1DCCAT0CBgFJGP5dZDANBgkqhkiG9w0BAQsFADAwMS4wLAYDVQQDEyVodHRwOi8vbG9jYWxob3N0OjgwODAvc2FsZXMtcG9zdC1zaWcvMB4XDTE0MTAxNjEyNDQyM1oXDTI0MTAxNjEyNDYwM1owMDEuMCwGA1UEAxMlaHR0cDovL2xvY2FsaG9zdDo4MDgwL3NhbGVzLXBvc3Qtc2lnLzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1RvGu8RjemSJA23nnMksoHA37MqY1DDTxOECY4rPAd9egr7GUNIXE0y1MokaR5R2crNpN8RIRwR8phQtQDjXL82c6W+NLQISxztarQJ7rdNJIYwHY0d5ri1XRpDP8zAuxubPYiMAVYcDkIcvlbBpwh/dRM5I2eElRK+eSiaMkCUCAwEAATANBgkqhkiG9w0BAQsFAAOBgQCLms6htnPaY69k1ntm9a5jgwSn/K61cdai8R8B0ccY7zvinn9AfRD7fiROQpFyY29wKn8WCLrJ86NBXfgFUGyR5nLNHVy3FghE36N2oHy53uichieMxffE6vhkKJ4P8ChfJMMOZlmCPsQPDvjoAghHt4mriFiQgRdPgIy/zDjSNw==
+
+
+
+
+
+
+ JBoss
+ JBoss by Red Hat
+ http://localhost:8080/sales-metadata/
+
+
+ The
+ Admin
+ admin@mycompany.com
+
+
+
\ No newline at end of file