Search in sources :

Example 36 with EntityIdCriterion

use of org.opensaml.core.criterion.EntityIdCriterion in project cas by apereo.

the class SamlIdPMetadataResolverTests method verifyOperation.

@RepeatedTest(2)
public void verifyOperation() throws Exception {
    val criteria = new CriteriaSet(new EntityIdCriterion(casProperties.getAuthn().getSamlIdp().getCore().getEntityId()));
    val result1 = casSamlIdPMetadataResolver.resolve(criteria);
    assertFalse(Iterables.isEmpty(result1));
    val result2 = casSamlIdPMetadataResolver.resolve(criteria);
    assertFalse(Iterables.isEmpty(result2));
    assertEquals(Iterables.size(result1), Iterables.size(result2));
}
Also used : lombok.val(lombok.val) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 37 with EntityIdCriterion

use of org.opensaml.core.criterion.EntityIdCriterion in project cas by apereo.

the class SamlIdPMetadataResolverTests method verifyOperationEmpty.

@RepeatedTest(2)
public void verifyOperationEmpty() throws Exception {
    val criteria = new CriteriaSet(new EntityIdCriterion("https://example.com"));
    val result = casSamlIdPMetadataResolver.resolve(criteria);
    assertTrue(Iterables.isEmpty(result));
}
Also used : lombok.val(lombok.val) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 38 with EntityIdCriterion

use of org.opensaml.core.criterion.EntityIdCriterion in project cas by apereo.

the class SamlIdPUtilsTests method verifyMetadataForAllServices.

@Test
public void verifyMetadataForAllServices() throws Exception {
    val service = getSamlRegisteredServiceForTestShib();
    servicesManager.save(service);
    val md = SamlIdPUtils.getMetadataResolverForAllSamlServices(servicesManager, service.getServiceId(), samlRegisteredServiceCachingMetadataResolver);
    assertNotNull(md);
    val criteriaSet = new CriteriaSet();
    criteriaSet.add(new EntityIdCriterion(service.getServiceId()));
    criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
    criteriaSet.add(new BindingCriterion(CollectionUtils.wrap(SAMLConstants.SAML2_POST_BINDING_URI)));
    val it = md.resolve(criteriaSet).iterator();
    assertTrue(it.hasNext());
    assertEquals(service.getServiceId(), it.next().getEntityID());
}
Also used : lombok.val(lombok.val) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) BindingCriterion(org.opensaml.saml.criterion.BindingCriterion) Test(org.junit.jupiter.api.Test)

Example 39 with EntityIdCriterion

use of org.opensaml.core.criterion.EntityIdCriterion in project cas by apereo.

the class SamlRegisteredServiceMetadataExpirationPolicy method getCacheDurationForServiceProvider.

/**
 * Gets cache duration for service provider.
 *
 * @param service                  the service
 * @param chainingMetadataResolver the chaining metadata resolver
 * @return the cache duration for service provider
 */
protected long getCacheDurationForServiceProvider(final SamlRegisteredService service, final MetadataResolver chainingMetadataResolver) {
    try {
        if (StringUtils.isBlank(service.getServiceId())) {
            LOGGER.warn("Unable to determine duration for SAML service [{}] with no entity id", service.getName());
            return -1;
        }
        val set = new CriteriaSet();
        set.add(new EntityIdCriterion(service.getServiceId()));
        set.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
        val entitySp = chainingMetadataResolver.resolveSingle(set);
        if (entitySp != null && entitySp.getCacheDuration() != null) {
            LOGGER.debug("Located cache duration [{}] specified in SP metadata for [{}]", entitySp.getCacheDuration(), entitySp.getEntityID());
            return TimeUnit.MILLISECONDS.toNanos(entitySp.getCacheDuration().toMillis());
        }
        set.clear();
        set.add(new EntityIdCriterion(service.getServiceId()));
        val entity = chainingMetadataResolver.resolveSingle(set);
        if (entity != null && entity.getCacheDuration() != null) {
            LOGGER.debug("Located cache duration [{}] specified in entity metadata for [{}]", entity.getCacheDuration(), entity.getEntityID());
            return TimeUnit.MILLISECONDS.toNanos(entity.getCacheDuration().toMillis());
        }
    } catch (final Exception e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return -1;
}
Also used : lombok.val(lombok.val) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion)

Example 40 with EntityIdCriterion

use of org.opensaml.core.criterion.EntityIdCriterion 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);
}
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)

Aggregations

EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)44 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)39 EntityRoleCriterion (org.opensaml.saml.criterion.EntityRoleCriterion)30 lombok.val (lombok.val)25 Test (org.junit.jupiter.api.Test)9 UsageCriterion (org.opensaml.security.criteria.UsageCriterion)9 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)7 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)7 ArrayList (java.util.ArrayList)5 File (java.io.File)4 SamlException (org.apereo.cas.support.saml.SamlException)4 ProtocolCriterion (org.opensaml.saml.criterion.ProtocolCriterion)4 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)4 SAMLSignatureProfileValidator (org.opensaml.saml.security.impl.SAMLSignatureProfileValidator)4 ResolverException (net.shibboleth.utilities.java.support.resolver.ResolverException)3 SamlIdPMetadataCredentialResolver (org.apereo.cas.support.saml.idp.metadata.locator.SamlIdPMetadataCredentialResolver)3 SamlIdPSamlRegisteredServiceCriterion (org.apereo.cas.support.saml.idp.metadata.locator.SamlIdPSamlRegisteredServiceCriterion)3 BasicProviderKeyInfoCredentialResolver (org.opensaml.xmlsec.keyinfo.impl.BasicProviderKeyInfoCredentialResolver)3 DEREncodedKeyValueProvider (org.opensaml.xmlsec.keyinfo.impl.provider.DEREncodedKeyValueProvider)3 DSAKeyValueProvider (org.opensaml.xmlsec.keyinfo.impl.provider.DSAKeyValueProvider)3