109 metadata = SAMLParser.getInstance().parse(is);
110 }
catch (ParsingException e) {
111 throw new RuntimeException(e);
113 EntitiesDescriptorType entities;
115 if (EntitiesDescriptorType.class.isInstance(metadata)) {
116 entities = (EntitiesDescriptorType) metadata;
118 entities =
new EntitiesDescriptorType();
119 entities.addEntityDescriptor(metadata);
122 if (entities.getEntityDescriptor().size() != 1) {
123 throw new RuntimeException(
"Expected one entity descriptor");
126 EntityDescriptorType entity = (EntityDescriptorType) entities.getEntityDescriptor().get(0);
127 String entityId = entity.getEntityID();
129 ClientRepresentation app =
new ClientRepresentation();
130 app.setClientId(entityId);
132 Map<String, String> attributes =
new HashMap<>();
133 app.setAttributes(attributes);
135 List<String> redirectUris =
new LinkedList<>();
136 app.setRedirectUris(redirectUris);
138 app.setFullScopeAllowed(
true);
139 app.setProtocol(SamlProtocol.LOGIN_PROTOCOL);
140 attributes.put(SamlConfigAttributes.SAML_SERVER_SIGNATURE, SamlProtocol.ATTRIBUTE_TRUE_VALUE);
141 attributes.put(SamlConfigAttributes.SAML_SERVER_SIGNATURE_KEYINFO_EXT, SamlProtocol.ATTRIBUTE_FALSE_VALUE);
142 attributes.put(SamlConfigAttributes.SAML_SIGNATURE_ALGORITHM, SignatureAlgorithm.RSA_SHA256.toString());
143 attributes.put(SamlConfigAttributes.SAML_AUTHNSTATEMENT, SamlProtocol.ATTRIBUTE_TRUE_VALUE);
145 if (spDescriptorType.isWantAssertionsSigned()) {
146 attributes.put(SamlConfigAttributes.SAML_ASSERTION_SIGNATURE, SamlProtocol.ATTRIBUTE_TRUE_VALUE);
148 String logoutPost =
getLogoutLocation(spDescriptorType, JBossSAMLURIConstants.SAML_HTTP_POST_BINDING.get());
149 if (logoutPost != null) attributes.put(SamlProtocol.SAML_SINGLE_LOGOUT_SERVICE_URL_POST_ATTRIBUTE, logoutPost);
150 String logoutRedirect =
getLogoutLocation(spDescriptorType, JBossSAMLURIConstants.SAML_HTTP_REDIRECT_BINDING.get());
151 if (logoutRedirect != null) attributes.put(SamlProtocol.SAML_SINGLE_LOGOUT_SERVICE_URL_REDIRECT_ATTRIBUTE, logoutRedirect);
153 String assertionConsumerServicePostBinding =
getServiceURL(spDescriptorType, JBossSAMLURIConstants.SAML_HTTP_POST_BINDING.get());
154 if (assertionConsumerServicePostBinding != null) {
155 attributes.put(SamlProtocol.SAML_ASSERTION_CONSUMER_URL_POST_ATTRIBUTE, assertionConsumerServicePostBinding);
156 redirectUris.add(assertionConsumerServicePostBinding);
158 String assertionConsumerServiceRedirectBinding =
getServiceURL(spDescriptorType, JBossSAMLURIConstants.SAML_HTTP_REDIRECT_BINDING.get());
159 if (assertionConsumerServiceRedirectBinding != null) {
160 attributes.put(SamlProtocol.SAML_ASSERTION_CONSUMER_URL_REDIRECT_ATTRIBUTE, assertionConsumerServiceRedirectBinding);
161 redirectUris.add(assertionConsumerServiceRedirectBinding);
163 String assertionConsumerServiceSoapBinding =
getServiceURL(spDescriptorType, JBossSAMLURIConstants.SAML_SOAP_BINDING.get());
164 if (assertionConsumerServiceSoapBinding != null) {
165 redirectUris.add(assertionConsumerServiceSoapBinding);
167 String assertionConsumerServicePaosBinding =
getServiceURL(spDescriptorType, JBossSAMLURIConstants.SAML_PAOS_BINDING.get());
168 if (assertionConsumerServicePaosBinding != null) {
169 redirectUris.add(assertionConsumerServicePaosBinding);
171 if (spDescriptorType.getNameIDFormat() != null) {
172 for (String format : spDescriptorType.getNameIDFormat()) {
173 String attribute = SamlClient.samlNameIDFormatToClientAttribute(format);
174 if (attribute != null) {
175 attributes.put(SamlConfigAttributes.SAML_NAME_ID_FORMAT_ATTRIBUTE, attribute);
181 for (KeyDescriptorType keyDescriptor : spDescriptorType.getKeyDescriptor()) {
182 X509Certificate cert = null;
184 cert = SAMLMetadataUtil.getCertificate(keyDescriptor);
185 }
catch (ConfigurationException e) {
186 throw new RuntimeException(e);
187 }
catch (ProcessingException e) {
188 throw new RuntimeException(e);
190 String certPem = KeycloakModelUtils.getPemFromCertificate(cert);
191 if (keyDescriptor.getUse() == KeyTypes.SIGNING) {
192 attributes.put(SamlConfigAttributes.SAML_CLIENT_SIGNATURE_ATTRIBUTE, SamlProtocol.ATTRIBUTE_TRUE_VALUE);
193 attributes.put(SamlConfigAttributes.SAML_SIGNING_CERTIFICATE_ATTRIBUTE, certPem);
194 }
else if (keyDescriptor.getUse() == KeyTypes.ENCRYPTION) {
195 attributes.put(SamlConfigAttributes.SAML_ENCRYPT, SamlProtocol.ATTRIBUTE_TRUE_VALUE);
196 attributes.put(SamlConfigAttributes.SAML_ENCRYPTION_CERTIFICATE_ATTRIBUTE, certPem);
static String getServiceURL(SPSSODescriptorType sp, String bindingURI)
Definition: EntityDescriptorDescriptionConverter.java:95
static SPSSODescriptorType getSPDescriptor(EntityDescriptorType entityDescriptor)
Definition: EntityDescriptorDescriptionConverter.java:78
static String getLogoutLocation(SPSSODescriptorType idp, String bindingURI)
Definition: EntityDescriptorDescriptionConverter.java:203