use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceCacheKeyTests method verifyCacheKeyByMetadataLocation.
@Test
public void verifyCacheKeyByMetadataLocation() {
val entityId = "https://carmenwiki.osu.edu/shibboleth";
val criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIdCriterion(entityId));
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
val service = new SamlRegisteredService();
service.setName("Example");
service.setId(1000);
service.setServiceId(".+");
service.setMetadataLocation("classpath:sample-sp.xml");
val results = new SamlRegisteredServiceCacheKey(service, criteriaSet);
assertNotNull(results.getId());
assertNotNull(results.getRegisteredService());
assertNotNull(results.getCriteriaSet());
assertEquals(results.getCacheKey(), service.getMetadataLocation());
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceMetadataResolverCacheLoaderTests method verifyEmptyResolvers.
@Test
public void verifyEmptyResolvers() {
val plan = new DefaultSamlRegisteredServiceMetadataResolutionPlan();
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());
assertThrows(SamlException.class, () -> loader.load(key));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class FileSystemResourceMetadataResolverTests method verifyResolverWithDirectory.
@Test
public void verifyResolverWithDirectory() throws Exception {
val resolver = new FileSystemResourceMetadataResolver(PROPERTIES, openSamlConfigBean);
val service = new SamlRegisteredService();
val file = new FileSystemResource("src/test/resources/md-dir").getFile().getCanonicalPath();
service.setMetadataLocation(file);
val resolvers = resolver.resolve(service);
assertFalse(resolvers.isEmpty());
val directoryResolver = resolvers.iterator().next();
val criteriaSet = new CriteriaSet();
criteriaSet.add(new EntityIdCriterion("https://idp.example.net/idp/shibboleth"));
criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
assertNotNull(directoryResolver.resolve(criteriaSet));
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class JsonResourceMetadataResolverTests method verifyResolverResolves.
@Test
public void verifyResolverResolves() throws Exception {
val props = new SamlIdPProperties();
val dir = new FileSystemResource(FileUtils.getTempDirectory());
props.getMetadata().getFileSystem().setLocation(dir.getFile().getCanonicalPath());
FileUtils.copyFile(new ClassPathResource("saml-sp-metadata.json").getFile(), new File(FileUtils.getTempDirectory(), "saml-sp-metadata.json"));
val service = new SamlRegisteredService();
val resolver = new JsonResourceMetadataResolver(props, openSamlConfigBean);
service.setName("Example");
service.setId(1000);
service.setServiceId("https://example.org/saml");
service.setMetadataLocation("json://");
assertTrue(resolver.isAvailable(service));
assertTrue(resolver.supports(service));
val results = resolver.resolve(service);
assertFalse(results.isEmpty());
val metadataResolver = results.iterator().next();
val resolved = metadataResolver.resolveSingle(new CriteriaSet(new EntityIdCriterion("https://example.org/saml")));
assertNotNull(resolved);
resolver.destroy();
}
use of net.shibboleth.utilities.java.support.resolver.CriteriaSet in project cas by apereo.
the class SamlRegisteredServiceMetadataExpirationPolicyTests method verifyPolicyBySpEntityCache.
@Test
public void verifyPolicyBySpEntityCache() 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 spCacheDuration = Duration.ofSeconds(30);
when(entity.getCacheDuration()).thenReturn(spCacheDuration);
when(resolver.resolveSingle(argThat(argument -> argument != null && argument.size() == 1))).thenReturn(entity);
when(resolver.resolveSingle(argThat(argument -> argument != null && argument.size() > 1))).thenReturn(null);
assertEquals(spCacheDuration.toNanos(), policy.expireAfterCreate(cacheKey, resolver, System.currentTimeMillis()));
}
Aggregations