use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceCachedMetadataEndpoint method invalidate.
/**
* Invalidate.
*
* @param serviceId the service id
*/
@DeleteOperation
@Operation(summary = "Invalidate SAML2 metadata cache using an entity id.", parameters = { @Parameter(name = "serviceId") })
public void invalidate(@Nullable final String serviceId) {
if (StringUtils.isBlank(serviceId)) {
cachingMetadataResolver.invalidate();
} else {
val registeredService = findRegisteredService(serviceId);
val criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIdCriterion(serviceId));
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
cachingMetadataResolver.invalidate(registeredService, criteriaSet);
}
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceCacheKeyTests method verifyCacheKeyDynamicMetadata.
@Test
public void verifyCacheKeyDynamicMetadata() {
val criteriaSet = new CriteriaSet();
val entityIdCriterion = new EntityIdCriterion("https://carmenwiki.osu.edu/shibboleth");
criteriaSet.add(entityIdCriterion);
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
val service = new SamlRegisteredService();
service.setName("Example");
service.setId(1000);
service.setServiceId(".+");
service.setMetadataLocation("https://mdq.something.net/entities/{0}");
val result1 = new SamlRegisteredServiceCacheKey(service, criteriaSet);
assertNotNull(result1.getId());
assertNotNull(result1.toString());
assertEquals(entityIdCriterion.getEntityId(), result1.getCacheKey());
val result2 = new SamlRegisteredServiceCacheKey(service, criteriaSet);
assertEquals(result1, result2);
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceMetadataResolverCacheLoaderTests method verifyFileByExpression.
@Test
public void verifyFileByExpression() throws Exception {
val mdFile = File.createTempFile("spsamlmetadata", ".xml");
val content = IOUtils.toString(new ClassPathResource("sample-sp.xml").getInputStream(), StandardCharsets.UTF_8);
FileUtils.writeStringToFile(mdFile, content, StandardCharsets.UTF_8);
System.setProperty("SP_REF", mdFile.getCanonicalPath());
val props = new SamlIdPProperties();
props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
val plan = new DefaultSamlRegisteredServiceMetadataResolutionPlan();
plan.registerMetadataResolver(new FileSystemResourceMetadataResolver(props, openSamlConfigBean));
val loader = new SamlRegisteredServiceMetadataResolverCacheLoader(openSamlConfigBean, httpClient, plan);
val service = new SamlRegisteredService();
service.setName("Example");
service.setId(1000);
service.setServiceId("https://example.org/saml");
service.setMetadataLocation("${#systemProperties['SP_REF']}");
val key = new SamlRegisteredServiceCacheKey(service, new CriteriaSet());
assertNotNull(loader.load(key));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceMetadataResolverCacheLoaderTests method verifyClasspathByExpression.
@Test
public void verifyClasspathByExpression() throws Exception {
System.setProperty("SP_REF", "classpath:sample-sp.xml");
val props = new SamlIdPProperties();
props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
val plan = new DefaultSamlRegisteredServiceMetadataResolutionPlan();
plan.registerMetadataResolver(new ClasspathResourceMetadataResolver(props, openSamlConfigBean));
val loader = new SamlRegisteredServiceMetadataResolverCacheLoader(openSamlConfigBean, httpClient, plan);
val service = new SamlRegisteredService();
service.setName("Example");
service.setId(1000);
service.setServiceId("https://example.org/saml");
service.setMetadataLocation("${#systemProperties['SP_REF']}");
val key = new SamlRegisteredServiceCacheKey(service, new CriteriaSet());
assertNotNull(loader.load(key));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceMetadataExpirationPolicyTests method verifyPolicyByServiceExpirationPolicy.
@Test
@SuppressWarnings("JavaTimeDefaultTimeZone")
public void verifyPolicyByServiceExpirationPolicy() 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.setExpirationPolicy(new DefaultRegisteredServiceExpirationPolicy().setExpirationDate(LocalDate.now(Clock.systemDefaultZone()).plusDays(1).toString()));
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);
when(entity.getCacheDuration()).thenReturn(null);
when(resolver.resolveSingle(argThat(argument -> argument != null && argument.size() == 1))).thenReturn(entity);
when(resolver.resolveSingle(argThat(argument -> argument != null && argument.size() > 1))).thenReturn(null);
assertNotEquals(policy.getDefaultExpiration(), policy.expireAfterCreate(cacheKey, resolver, System.currentTimeMillis()));
}
Aggregations