Search in sources :

Example 1 with ResolverException

use of net.shibboleth.utilities.java.support.resolver.ResolverException in project verify-hub by alphagov.

the class CountrySingleSignOnServiceHelper method getSingleSignOn.

public URI getSingleSignOn(String entityId) {
    EidasMetadataResolver metadataResolver = new EidasMetadataResolver(new Timer(), client, URI.create(entityId));
    try {
        EntityDescriptor idpEntityDescriptor;
        try {
            CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(entityId));
            idpEntityDescriptor = metadataResolver.resolveSingle(criteria);
        } catch (ResolverException e) {
            LOG.error(format("Exception when accessing metadata: {0}", e));
            throw propagate(e);
        }
        if (idpEntityDescriptor != null) {
            final IDPSSODescriptor idpssoDescriptor = idpEntityDescriptor.getIDPSSODescriptor(SAMLConstants.SAML20P_NS);
            final List<SingleSignOnService> singleSignOnServices = idpssoDescriptor.getSingleSignOnServices();
            if (singleSignOnServices.isEmpty()) {
                LOG.error(format("No singleSignOnServices present for IDP entityId: {0}", entityId));
            } else {
                if (singleSignOnServices.size() > 1) {
                    LOG.warn(format("More than one singleSignOnService present: {0} for {1}", singleSignOnServices.size(), entityId));
                }
                return URI.create(singleSignOnServices.get(0).getLocation());
            }
        }
        throw ApplicationException.createUnauditedException(ExceptionType.NOT_FOUND, UUID.randomUUID(), new RuntimeException(format("no entity descriptor for IDP: {0}", entityId)));
    } finally {
        if (metadataResolver != null) {
            metadataResolver.destroy();
        }
    }
}
Also used : EidasMetadataResolver(uk.gov.ida.hub.samlengine.EidasMetadataResolver) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) Timer(java.util.Timer) IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SingleSignOnService(org.opensaml.saml.saml2.metadata.SingleSignOnService)

Example 2 with ResolverException

use of net.shibboleth.utilities.java.support.resolver.ResolverException in project pac4j by pac4j.

the class SAML2Client method initChainingMetadataResolver.

protected ChainingMetadataResolver initChainingMetadataResolver(final MetadataResolver idpMetadataProvider, final MetadataResolver spMetadataProvider) {
    final ChainingMetadataResolver metadataManager = new ChainingMetadataResolver();
    metadataManager.setId(ChainingMetadataResolver.class.getCanonicalName());
    try {
        final List<MetadataResolver> list = new ArrayList<>();
        list.add(idpMetadataProvider);
        list.add(spMetadataProvider);
        metadataManager.setResolvers(list);
        metadataManager.initialize();
    } catch (final ResolverException e) {
        throw new TechnicalException("Error adding idp or sp metadatas to manager", e);
    } catch (final ComponentInitializationException e) {
        throw new TechnicalException("Error initializing manager", e);
    }
    return metadataManager;
}
Also used : ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) TechnicalException(org.pac4j.core.exception.TechnicalException) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) ArrayList(java.util.ArrayList) SAML2IdentityProviderMetadataResolver(org.pac4j.saml.metadata.SAML2IdentityProviderMetadataResolver) SAML2ServiceProviderMetadataResolver(org.pac4j.saml.metadata.SAML2ServiceProviderMetadataResolver) SAML2MetadataResolver(org.pac4j.saml.metadata.SAML2MetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)

Example 3 with ResolverException

use of net.shibboleth.utilities.java.support.resolver.ResolverException in project pac4j by pac4j.

the class SAML2ContextProvider method addContext.

protected final void addContext(final SAML2MetadataResolver entityId, final BaseContext parentContext, final QName elementName) {
    final EntityDescriptor entityDescriptor;
    final RoleDescriptor roleDescriptor;
    try {
        final CriteriaSet set = new CriteriaSet();
        set.add(new EntityIdCriterion(entityId.getEntityId()));
        entityDescriptor = this.metadata.resolveSingle(set);
        if (entityDescriptor == null) {
            throw new SAMLException("Cannot find entity " + entityId + " in metadata provider");
        }
        final List<RoleDescriptor> list = entityDescriptor.getRoleDescriptors(elementName, SAMLConstants.SAML20P_NS);
        roleDescriptor = CommonHelper.isNotEmpty(list) ? list.get(0) : null;
        if (roleDescriptor == null) {
            throw new SAMLException("Cannot find entity " + entityId + " or role " + elementName + " in metadata provider");
        }
    } catch (final ResolverException e) {
        throw new SAMLException("An error occured while getting IDP descriptors", e);
    }
    final SAMLMetadataContext mdCtx = parentContext.getSubcontext(SAMLMetadataContext.class, true);
    mdCtx.setEntityDescriptor(entityDescriptor);
    mdCtx.setRoleDescriptor(roleDescriptor);
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) RoleDescriptor(org.opensaml.saml.saml2.metadata.RoleDescriptor) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SAMLMetadataContext(org.opensaml.saml.common.messaging.context.SAMLMetadataContext) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Example 4 with ResolverException

use of net.shibboleth.utilities.java.support.resolver.ResolverException in project pac4j by pac4j.

the class KeyStoreCredentialProvider method getCredential.

@Override
public final Credential getCredential() {
    try {
        final CriteriaSet cs = new CriteriaSet();
        final EntityIdCriterion criteria = new EntityIdCriterion(this.privateKey);
        cs.add(criteria);
        final X509Credential creds = (X509Credential) this.credentialResolver.resolveSingle(cs);
        return creds;
    } catch (final ResolverException e) {
        throw new SAMLException("Can't obtain SP private key", e);
    }
}
Also used : X509Credential(org.opensaml.security.x509.X509Credential) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Example 5 with ResolverException

use of net.shibboleth.utilities.java.support.resolver.ResolverException in project verify-hub by alphagov.

the class IdpSingleSignOnServiceHelperTest method shouldThrowExceptionWhenMetadataProviderThrowsOne.

@Test
public void shouldThrowExceptionWhenMetadataProviderThrowsOne() {
    Assertions.assertThrows(RuntimeException.class, () -> {
        MetadataResolver metadataResolver = mock(MetadataResolver.class);
        when(metadataResolver.resolveSingle(any(CriteriaSet.class))).thenThrow(new ResolverException());
        idpSingleSignOnServiceHelper = new IdpSingleSignOnServiceHelper(metadataResolver);
        idpSingleSignOnServiceHelper.getSingleSignOn(idpEntityId);
    });
}
Also used : ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) Test(org.junit.jupiter.api.Test)

Aggregations

ResolverException (net.shibboleth.utilities.java.support.resolver.ResolverException)8 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)6 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)4 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)4 MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)3 Test (org.junit.jupiter.api.Test)2 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)2 SingleSignOnService (org.opensaml.saml.saml2.metadata.SingleSignOnService)2 SAMLException (org.pac4j.saml.exceptions.SAMLException)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Timer (java.util.Timer)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1