|
|
|
@ -30,11 +30,13 @@ import org.opensaml.core.xml.XMLObjectBuilder; |
|
|
|
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; |
|
|
|
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; |
|
|
|
import org.opensaml.saml.common.xml.SAMLConstants; |
|
|
|
import org.opensaml.saml.common.xml.SAMLConstants; |
|
|
|
import org.opensaml.saml.saml2.metadata.AssertionConsumerService; |
|
|
|
import org.opensaml.saml.saml2.metadata.AssertionConsumerService; |
|
|
|
|
|
|
|
import org.opensaml.saml.saml2.metadata.EntitiesDescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.EntityDescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.EntityDescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.KeyDescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.KeyDescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.NameIDFormat; |
|
|
|
import org.opensaml.saml.saml2.metadata.NameIDFormat; |
|
|
|
import org.opensaml.saml.saml2.metadata.SPSSODescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.SPSSODescriptor; |
|
|
|
import org.opensaml.saml.saml2.metadata.SingleLogoutService; |
|
|
|
import org.opensaml.saml.saml2.metadata.SingleLogoutService; |
|
|
|
|
|
|
|
import org.opensaml.saml.saml2.metadata.impl.EntitiesDescriptorMarshaller; |
|
|
|
import org.opensaml.saml.saml2.metadata.impl.EntityDescriptorMarshaller; |
|
|
|
import org.opensaml.saml.saml2.metadata.impl.EntityDescriptorMarshaller; |
|
|
|
import org.opensaml.security.credential.UsageType; |
|
|
|
import org.opensaml.security.credential.UsageType; |
|
|
|
import org.opensaml.xmlsec.signature.KeyInfo; |
|
|
|
import org.opensaml.xmlsec.signature.KeyInfo; |
|
|
|
@ -65,6 +67,8 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver { |
|
|
|
|
|
|
|
|
|
|
|
private final EntityDescriptorMarshaller entityDescriptorMarshaller; |
|
|
|
private final EntityDescriptorMarshaller entityDescriptorMarshaller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final EntitiesDescriptorMarshaller entitiesDescriptorMarshaller; |
|
|
|
|
|
|
|
|
|
|
|
private Consumer<EntityDescriptorParameters> entityDescriptorCustomizer = (parameters) -> { |
|
|
|
private Consumer<EntityDescriptorParameters> entityDescriptorCustomizer = (parameters) -> { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@ -72,17 +76,38 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver { |
|
|
|
this.entityDescriptorMarshaller = (EntityDescriptorMarshaller) XMLObjectProviderRegistrySupport |
|
|
|
this.entityDescriptorMarshaller = (EntityDescriptorMarshaller) XMLObjectProviderRegistrySupport |
|
|
|
.getMarshallerFactory().getMarshaller(EntityDescriptor.DEFAULT_ELEMENT_NAME); |
|
|
|
.getMarshallerFactory().getMarshaller(EntityDescriptor.DEFAULT_ELEMENT_NAME); |
|
|
|
Assert.notNull(this.entityDescriptorMarshaller, "entityDescriptorMarshaller cannot be null"); |
|
|
|
Assert.notNull(this.entityDescriptorMarshaller, "entityDescriptorMarshaller cannot be null"); |
|
|
|
|
|
|
|
this.entitiesDescriptorMarshaller = (EntitiesDescriptorMarshaller) XMLObjectProviderRegistrySupport |
|
|
|
|
|
|
|
.getMarshallerFactory().getMarshaller(EntitiesDescriptor.DEFAULT_ELEMENT_NAME); |
|
|
|
|
|
|
|
Assert.notNull(this.entitiesDescriptorMarshaller, "entitiesDescriptorMarshaller cannot be null"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String resolve(RelyingPartyRegistration relyingPartyRegistration) { |
|
|
|
public String resolve(RelyingPartyRegistration relyingPartyRegistration) { |
|
|
|
|
|
|
|
EntityDescriptor entityDescriptor = entityDescriptor(relyingPartyRegistration); |
|
|
|
|
|
|
|
return serialize(entityDescriptor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String resolve(Iterable<RelyingPartyRegistration> relyingPartyRegistrations) { |
|
|
|
|
|
|
|
Collection<EntityDescriptor> entityDescriptors = new ArrayList<>(); |
|
|
|
|
|
|
|
for (RelyingPartyRegistration registration : relyingPartyRegistrations) { |
|
|
|
|
|
|
|
EntityDescriptor entityDescriptor = entityDescriptor(registration); |
|
|
|
|
|
|
|
entityDescriptors.add(entityDescriptor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (entityDescriptors.size() == 1) { |
|
|
|
|
|
|
|
return serialize(entityDescriptors.iterator().next()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
EntitiesDescriptor entities = build(EntitiesDescriptor.DEFAULT_ELEMENT_NAME); |
|
|
|
|
|
|
|
entities.getEntityDescriptors().addAll(entityDescriptors); |
|
|
|
|
|
|
|
return serialize(entities); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EntityDescriptor entityDescriptor(RelyingPartyRegistration registration) { |
|
|
|
EntityDescriptor entityDescriptor = build(EntityDescriptor.DEFAULT_ELEMENT_NAME); |
|
|
|
EntityDescriptor entityDescriptor = build(EntityDescriptor.DEFAULT_ELEMENT_NAME); |
|
|
|
entityDescriptor.setEntityID(relyingPartyRegistration.getEntityId()); |
|
|
|
entityDescriptor.setEntityID(registration.getEntityId()); |
|
|
|
SPSSODescriptor spSsoDescriptor = buildSpSsoDescriptor(relyingPartyRegistration); |
|
|
|
SPSSODescriptor spSsoDescriptor = buildSpSsoDescriptor(registration); |
|
|
|
entityDescriptor.getRoleDescriptors(SPSSODescriptor.DEFAULT_ELEMENT_NAME).add(spSsoDescriptor); |
|
|
|
entityDescriptor.getRoleDescriptors(SPSSODescriptor.DEFAULT_ELEMENT_NAME).add(spSsoDescriptor); |
|
|
|
this.entityDescriptorCustomizer |
|
|
|
this.entityDescriptorCustomizer.accept(new EntityDescriptorParameters(entityDescriptor, registration)); |
|
|
|
.accept(new EntityDescriptorParameters(entityDescriptor, relyingPartyRegistration)); |
|
|
|
return entityDescriptor; |
|
|
|
return serialize(entityDescriptor); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -184,6 +209,16 @@ public final class OpenSamlMetadataResolver implements Saml2MetadataResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String serialize(EntitiesDescriptor entities) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Element element = this.entitiesDescriptorMarshaller.marshall(entities); |
|
|
|
|
|
|
|
return SerializeSupport.prettyPrintXML(element); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) { |
|
|
|
|
|
|
|
throw new Saml2Exception(ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A tuple containing an OpenSAML {@link EntityDescriptor} and its associated |
|
|
|
* A tuple containing an OpenSAML {@link EntityDescriptor} and its associated |
|
|
|
* {@link RelyingPartyRegistration} |
|
|
|
* {@link RelyingPartyRegistration} |
|
|
|
|