Search in sources :

Example 21 with CriteriaSet

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());
}
Also used : lombok.val(lombok.val) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) Test(org.junit.jupiter.api.Test)

Example 22 with CriteriaSet

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));
}
Also used : lombok.val(lombok.val) DefaultSamlRegisteredServiceMetadataResolutionPlan(org.apereo.cas.support.saml.services.idp.metadata.plan.DefaultSamlRegisteredServiceMetadataResolutionPlan) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) Test(org.junit.jupiter.api.Test)

Example 23 with CriteriaSet

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));
}
Also used : lombok.val(lombok.val) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.jupiter.api.Test)

Example 24 with 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();
}
Also used : lombok.val(lombok.val) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 25 with CriteriaSet

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()));
}
Also used : lombok.val(lombok.val) DefaultRegisteredServiceExpirationPolicy(org.apereo.cas.services.DefaultRegisteredServiceExpirationPolicy) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) BaseSamlIdPServicesTests(org.apereo.cas.support.saml.services.BaseSamlIdPServicesTests) lombok.val(lombok.val) FileSystemResource(org.springframework.core.io.FileSystemResource) FileUtils(org.apache.commons.io.FileUtils) Beans(org.apereo.cas.configuration.support.Beans) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) SamlRegisteredServiceCacheKey(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCacheKey) StringUtils(org.apache.commons.lang3.StringUtils) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) Duration(java.time.Duration) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) Clock(java.time.Clock) SamlRegisteredServiceMetadataExpirationPolicy(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceMetadataExpirationPolicy) Tag(org.junit.jupiter.api.Tag) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) SamlRegisteredServiceCacheKey(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCacheKey) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) SamlRegisteredServiceMetadataExpirationPolicy(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceMetadataExpirationPolicy) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.jupiter.api.Test)

Aggregations

CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)68 lombok.val (lombok.val)44 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)40 EntityRoleCriterion (org.opensaml.saml.criterion.EntityRoleCriterion)28 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)18 Test (org.junit.jupiter.api.Test)16 UsageCriterion (org.opensaml.security.criteria.UsageCriterion)11 SamlIdPProperties (org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties)10 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)10 ArrayList (java.util.ArrayList)9 SignatureSigningConfigurationCriterion (org.opensaml.xmlsec.criterion.SignatureSigningConfigurationCriterion)9 MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)8 SAMLMetadataSignatureSigningParametersResolver (org.opensaml.saml.security.impl.SAMLMetadataSignatureSigningParametersResolver)8 SneakyThrows (lombok.SneakyThrows)7 StringUtils (org.apache.commons.lang3.StringUtils)7 SignatureSigningParameters (org.opensaml.xmlsec.SignatureSigningParameters)7 FileSystemResource (org.springframework.core.io.FileSystemResource)7 SamlException (org.apereo.cas.support.saml.SamlException)6 EvaluableEntityRoleEntityDescriptorCriterion (org.opensaml.saml.metadata.criteria.entity.impl.EvaluableEntityRoleEntityDescriptorCriterion)6 Credential (org.opensaml.security.credential.Credential)6