use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.
the class SAML2IdentityProviderMetadataResolverTest method resolveMetadataEntityId.
@Test
public void resolveMetadataEntityId() throws Exception {
MetadataResolver resolver = metadataResolver.resolve();
CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion("mmoayyed.example.net"));
final EntityDescriptor entity = resolver.resolveSingle(criteria);
assertEquals(entity.getEntityID(), "mmoayyed.example.net");
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.
the class SAML2MetadataGenerator method getMetadata.
@Override
public final String getMetadata() throws Exception {
final EntityDescriptor md = buildEntityDescriptor();
final Element entityDescriptorElement = this.marshallerFactory.getMarshaller(md).marshall(md);
return SerializeSupport.nodeToString(entityDescriptorElement);
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.
the class SAML2MetadataGenerator method buildEntityDescriptor.
@Override
public final EntityDescriptor buildEntityDescriptor() {
final SAMLObjectBuilder<EntityDescriptor> builder = (SAMLObjectBuilder<EntityDescriptor>) this.builderFactory.getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME);
final EntityDescriptor descriptor = builder.buildObject();
descriptor.setEntityID(this.entityId);
descriptor.setValidUntil(DateTime.now(DateTimeZone.UTC).plusYears(20));
descriptor.setID(generateEntityDescriptorId());
descriptor.setExtensions(generateMetadataExtensions());
descriptor.getRoleDescriptors().add(buildSPSSODescriptor());
return descriptor;
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.
the class SAML2MetadataGenerator method buildMetadataResolver.
@Override
public final MetadataResolver buildMetadataResolver() throws Exception {
final EntityDescriptor md = buildEntityDescriptor();
final Element entityDescriptorElement = this.marshallerFactory.getMarshaller(md).marshall(md);
final DOMMetadataResolver resolver = new DOMMetadataResolver(entityDescriptorElement);
resolver.setRequireValidMetadata(true);
resolver.setFailFastInitialization(true);
resolver.setId(resolver.getClass().getCanonicalName());
resolver.initialize();
return resolver;
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.
the class SAML2IdentityProviderMetadataResolver method resolve.
@Override
public final MetadataResolver resolve() {
// Usage of locks will adversly impact performance.
if (idpMetadataProvider != null) {
return idpMetadataProvider;
}
try {
if (this.idpMetadataResource == null) {
throw new XMLParserException("idp metadata cannot be resolved from " + this.idpMetadataResource);
}
try (final InputStream in = this.idpMetadataResource.getInputStream()) {
final Document inCommonMDDoc = Configuration.getParserPool().parse(in);
final Element metadataRoot = inCommonMDDoc.getDocumentElement();
idpMetadataProvider = new DOMMetadataResolver(metadataRoot);
idpMetadataProvider.setParserPool(Configuration.getParserPool());
idpMetadataProvider.setFailFastInitialization(true);
idpMetadataProvider.setRequireValidMetadata(true);
idpMetadataProvider.setId(idpMetadataProvider.getClass().getCanonicalName());
idpMetadataProvider.initialize();
} catch (final FileNotFoundException e) {
throw new TechnicalException("Error loading idp Metadata");
}
// If no idpEntityId declared, select first EntityDescriptor entityId as our IDP entityId
if (this.idpEntityId == null) {
final Iterator<EntityDescriptor> it = idpMetadataProvider.iterator();
while (it.hasNext()) {
final EntityDescriptor entityDescriptor = it.next();
if (this.idpEntityId == null) {
this.idpEntityId = entityDescriptor.getEntityID();
}
}
}
if (this.idpEntityId == null) {
throw new SAMLException("No idp entityId found");
}
} catch (final ComponentInitializationException e) {
throw new SAMLException("Error initializing idpMetadataProvider", e);
} catch (final XMLParserException e) {
throw new TechnicalException("Error parsing idp Metadata", e);
} catch (final IOException e) {
throw new TechnicalException("Error getting idp Metadata resource", e);
}
return idpMetadataProvider;
}
Aggregations