use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceMetadataExpirationPolicyTests method verifyPolicyByEntityCache.
@Test
public void verifyPolicyByEntityCache() throws Exception {
val policy = new SamlRegisteredServiceMetadataExpirationPolicy(Beans.newDuration("PT5M"));
val props = new SamlIdPProperties();
props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
val service = new SamlRegisteredService();
service.setMetadataExpirationDuration(StringUtils.EMPTY);
service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
service.setMetadataLocation("classpath:GroovyMetadataResolver.groovy");
val cacheKey = new SamlRegisteredServiceCacheKey(service, new CriteriaSet());
val resolver = mock(MetadataResolver.class);
val entity = mock(EntityDescriptor.class);
val entityCacheDuration = Duration.ofSeconds(10);
when(entity.getCacheDuration()).thenReturn(entityCacheDuration);
when(resolver.resolveSingle(any())).thenReturn(entity);
assertEquals(entityCacheDuration.toNanos(), policy.expireAfterCreate(cacheKey, resolver, System.currentTimeMillis()));
when(resolver.resolveSingle(any())).thenThrow(new IllegalArgumentException());
assertEquals(policy.getDefaultExpiration(), policy.expireAfterCreate(cacheKey, resolver, System.currentTimeMillis()));
assertEquals(policy.getDefaultExpiration(), policy.expireAfterUpdate(cacheKey, resolver, 1000, policy.getDefaultExpiration()));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class MetadataQueryProtocolMetadataResolver method fetchMetadata.
@Override
protected HttpResponse fetchMetadata(final SamlRegisteredService service, final String metadataLocation, final CriteriaSet criteriaSet, final File backupFile) {
val metadata = samlIdPProperties.getMetadata().getMdq();
val headers = new LinkedHashMap<String, Object>();
headers.put("Content-Type", metadata.getSupportedContentTypes());
headers.put("Accept", "*/*");
val path = backupFile.toPath();
if (Files.exists(path)) {
Unchecked.consumer(store -> {
val etag = new String((byte[]) Files.getAttribute(path, "user:ETag"), StandardCharsets.UTF_8).trim();
headers.put("If-None-Match", etag);
}).accept(path);
}
LOGGER.trace("Fetching metadata via MDQ for [{}]", metadataLocation);
val exec = HttpUtils.HttpExecutionRequest.builder().basicAuthPassword(metadata.getBasicAuthnPassword()).basicAuthUsername(metadata.getBasicAuthnUsername()).method(HttpMethod.GET).url(metadataLocation).headers(headers).proxyUrl(service.getMetadataProxyLocation()).build();
val response = HttpUtils.execute(exec);
if (response == null) {
LOGGER.error("Unable to fetch metadata from [{}]", metadataLocation);
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE);
}
return response;
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class InMemoryResourceMetadataResolverTests method verifyInvalidExpiredMetadataResourceIsOkay.
@Test
public void verifyInvalidExpiredMetadataResourceIsOkay() throws Exception {
val resolver = new InMemoryResourceMetadataResolver(new ClassPathResource("metadata/metadata-expired.xml"), configBean);
resolver.setRequireValidMetadata(false);
resolver.setId(UUID.randomUUID().toString());
resolver.initialize();
val criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIdCriterion("urn:app.e2ma.net"));
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
val resolved = resolver.resolve(criteriaSet);
assertFalse(Iterables.isEmpty(resolved));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class InMemoryResourceMetadataResolverTests method verifyExpiredValidUntilMetadataResource.
@Test
public void verifyExpiredValidUntilMetadataResource() throws Exception {
val resolver = new InMemoryResourceMetadataResolver(new ClassPathResource("metadata/metadata-expired.xml"), configBean);
resolver.setId(UUID.randomUUID().toString());
resolver.initialize();
val criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIdCriterion("urn:app.e2ma.net"));
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
val resolved = resolver.resolve(criteriaSet);
assertTrue(Iterables.isEmpty(resolved));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project verify-hub by alphagov.
the class IdpSingleSignOnServiceHelperTest method setUp.
@BeforeEach
public void setUp() throws ResolverException, MarshallingException, SignatureException {
CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(idpEntityId));
EntityDescriptor idpEntityDescriptor = anEntityDescriptor().withIdpSsoDescriptor(anIdpSsoDescriptor().withSingleSignOnService(anEndpoint().withLocation(idpSSOUri.toASCIIString()).buildSingleSignOnService()).build()).build();
when(metadataProvider.resolveSingle(eq(criteria))).thenReturn(idpEntityDescriptor);
when(metadataProvider.resolveSingle(not(eq(criteria)))).thenReturn(null);
idpSingleSignOnServiceHelper = new IdpSingleSignOnServiceHelper(metadataProvider);
}
Aggregations