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();
}
}
}
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;
}
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);
}
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);
}
}
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);
});
}
Aggregations