use of org.opensaml.saml2.metadata.EntityDescriptor in project verify-hub by alphagov.
the class SamlEntityDescriptorValidatorTest method decorate_shouldThrowExceptionWhenBothValidUntilAndCacheDurationAreMissing.
@Test
public void decorate_shouldThrowExceptionWhenBothValidUntilAndCacheDurationAreMissing() throws Exception {
EntityDescriptor entityDescriptor = anEntityDescriptor().withValidUntil(null).withCacheDuration(null).build();
assertExceptionMessage(entityDescriptor, SamlTransformationErrorFactory.missingCacheDurationAndValidUntil());
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project verify-hub by alphagov.
the class HubIdentityProviderMetadataDtoToEntityDescriptorTransformerTest method transform_shouldTransformIdpSigningCertificates.
@Test
public void transform_shouldTransformIdpSigningCertificates() {
String idpOneIssuerId = UUID.randomUUID().toString();
String idpTwoIssuerId = UUID.randomUUID().toString();
final Certificate idpCertOne = aCertificate().withIssuerId(idpOneIssuerId).build();
final Certificate idpCertTwo = aCertificate().withIssuerId(idpTwoIssuerId).build();
final EntityDescriptor result = transformer.apply(IdentityProviderMetadataDtoBuilder.anIdentityProviderMetadataDto().addIdpSigningCertificate(idpCertOne).addIdpSigningCertificate(idpCertTwo).build());
final List<KeyDescriptor> keyDescriptors = result.getIDPSSODescriptor(SAMLConstants.SAML20P_NS).getKeyDescriptors();
Assertions.assertThat(keyDescriptors.size()).isEqualTo(4);
assertCertificateCorrect(keyDescriptors.get(1), idpOneIssuerId, idpCertOne);
assertCertificateCorrect(keyDescriptors.get(2), idpTwoIssuerId, idpCertTwo);
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project verify-hub by alphagov.
the class HubAsIdpMetadataHandler method getMetadataAsAnIdentityProvider.
public HubIdentityProviderMetadataDto getMetadataAsAnIdentityProvider() {
URI hubFrontend = samlProxyConfiguration.getFrontendExternalUri();
SamlEndpointDto binding = new SamlEndpointDto(SamlEndpointDto.Binding.POST, URI.create(hubFrontend + SAML2_SSO_REQUEST_ENDPOINT));
Iterable<EntityDescriptor> entityDescriptors;
try {
CriteriaSet criteria = new CriteriaSet(new EntitiesDescriptorNameCriterion(hubFederationId));
entityDescriptors = metadataResolver.resolve(criteria);
LOG.info("Retrieved metadata from " + samlProxyConfiguration.getMetadataConfiguration().getUri());
} catch (ResolverException e) {
throw ApplicationException.createUnauditedException(ExceptionType.METADATA_PROVIDER_EXCEPTION, e.getMessage(), e);
}
final Iterable<EntityDescriptor> idpEntityDescriptors = StreamSupport.stream(entityDescriptors.spliterator(), false).filter(input -> input.getIDPSSODescriptor(SAMLConstants.SAML20P_NS) != null).collect(Collectors.toList());
final Iterable<EntityDescriptor> hubEntityDescriptors = StreamSupport.stream(entityDescriptors.spliterator(), false).filter(input -> input.getEntityID().equals(hubEntityId)).collect(Collectors.toList());
final Iterable<List<Certificate>> idpSigningCertificates = StreamSupport.stream(idpEntityDescriptors.spliterator(), false).map(this::getIDPSigningCertificates).collect(Collectors.toList());
final Iterable<Certificate> hubEncryptionCertificate = StreamSupport.stream(hubEntityDescriptors.spliterator(), false).map(this::getHubEncryptionCertificate).collect(Collectors.toList());
final Iterable<List<Certificate>> hubSigningCertificates = StreamSupport.stream(hubEntityDescriptors.spliterator(), false).map(this::getHubSigningCertificates).collect(Collectors.toList());
return new HubIdentityProviderMetadataDto(singletonList(binding), hubEntityId, organisationDto, Collections.emptySet(), ImmutableList.copyOf(Iterables.concat(idpSigningCertificates)), DateTime.now().plus(samlProxyConfiguration.getMetadataValidDuration().toMilliseconds()), ImmutableList.copyOf(Iterables.concat(hubSigningCertificates)), hubEncryptionCertificate.iterator().next());
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project hub-alert by blackducksoftware.
the class SAMLManager method createMemoryProvider.
// This needs to be created in order for Azure AD SAML configuration to work. The entity id in the metadata is different
// than the entity id configured in Azure. This allows the the entity id to get mapped and found correctly for the application.
private Optional<ExtendedMetadataDelegate> createMemoryProvider() throws MetadataProviderException {
EntityDescriptor descriptor = metadataGenerator.generateMetadata();
MetadataMemoryProvider provider = new MetadataMemoryProvider(descriptor);
provider.initialize();
return Optional.of(createDelegate(provider));
}
use of org.opensaml.saml2.metadata.EntityDescriptor in project ddf by codice.
the class AssertionConsumerService method retrieveMetadata.
@GET
@Path("/metadata")
@Produces("application/xml")
public Response retrieveMetadata() throws WSSecurityException, CertificateEncodingException {
List<String> nameIdFormats = new ArrayList<>();
nameIdFormats.add(SAML2Constants.NAMEID_FORMAT_PERSISTENT);
nameIdFormats.add(SAML2Constants.NAMEID_FORMAT_UNSPECIFIED);
nameIdFormats.add(SAML2Constants.NAMEID_FORMAT_X509_SUBJECT_NAME);
X509Certificate issuerCert = findCertificate(systemCrypto.getSignatureAlias(), systemCrypto.getSignatureCrypto());
X509Certificate encryptionCert = findCertificate(systemCrypto.getEncryptionAlias(), systemCrypto.getEncryptionCrypto());
String entityId = SystemBaseUrl.EXTERNAL.constructUrl("/saml", true);
String logoutLocation = SystemBaseUrl.EXTERNAL.constructUrl("/saml/logout", true);
String assertionConsumerServiceLocation = SystemBaseUrl.EXTERNAL.constructUrl("/saml/sso", true);
EntityDescriptor entityDescriptor = SamlProtocol.createSpMetadata(entityId, Base64.getEncoder().encodeToString(issuerCert.getEncoded()), Base64.getEncoder().encodeToString(encryptionCert.getEncoded()), nameIdFormats, logoutLocation, assertionConsumerServiceLocation, assertionConsumerServiceLocation, assertionConsumerServiceLocation);
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
return Response.ok(DOM2Writer.nodeToString(OpenSAMLUtil.toDom(entityDescriptor, doc, false))).build();
}
Aggregations