Search in sources :

Example 6 with OpenSamlConfigBean

use of org.apereo.cas.support.saml.OpenSamlConfigBean in project cas by apereo.

the class SamlMetadataUIConfiguration method configureAdapter.

private static MetadataResolverAdapter configureAdapter(final AbstractMetadataResolverAdapter adapter, final ConfigurableApplicationContext applicationContext, final CasConfigurationProperties casProperties, final OpenSamlConfigBean openSamlConfigBean) {
    val resources = new HashMap<Resource, MetadataFilterChain>();
    val chain = new MetadataFilterChain();
    casProperties.getSamlMetadataUi().getResources().forEach(Unchecked.consumer(r -> configureResource(applicationContext, resources, chain, r, casProperties)));
    adapter.setRequireValidMetadata(casProperties.getSamlMetadataUi().isRequireValidMetadata());
    adapter.setMetadataResources(resources);
    adapter.setConfigBean(openSamlConfigBean);
    return adapter;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Arrays(java.util.Arrays) StaticMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.StaticMetadataResolverAdapter) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) RequiredValidUntilFilter(org.opensaml.saml.metadata.resolver.filter.impl.RequiredValidUntilFilter) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ArrayList(java.util.ArrayList) SamlUtils(org.apereo.cas.support.saml.SamlUtils) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Duration(java.time.Duration) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Splitter(com.google.common.base.Splitter) MetadataFilter(org.opensaml.saml.metadata.resolver.filter.MetadataFilter) Resource(org.springframework.core.io.Resource) MetadataFilterChain(org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain) AbstractMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.AbstractMetadataResolverAdapter) MetadataResolverAdapter(org.apereo.cas.support.saml.mdui.MetadataResolverAdapter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ResourceUtils(org.apereo.cas.util.ResourceUtils) Unchecked(org.jooq.lambda.Unchecked) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) ChainingMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.ChainingMetadataResolverAdapter) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) DynamicMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.DynamicMetadataResolverAdapter) Bean(org.springframework.context.annotation.Bean) HashMap(java.util.HashMap) MetadataFilterChain(org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain)

Example 7 with OpenSamlConfigBean

use of org.apereo.cas.support.saml.OpenSamlConfigBean in project cas by apereo.

the class SamlRegisteredServiceCachedMetadataEndpoint method getCachedMetadataObject.

/**
 * Gets cached metadata object.
 *
 * @param serviceId the service id
 * @param entityId  the entity id
 * @return the cached metadata object
 */
@ReadOperation
@Operation(summary = "Get SAML2 cached metadata", parameters = { @Parameter(name = "serviceId", required = true), @Parameter(name = "entityId") })
public Map<String, Object> getCachedMetadataObject(final String serviceId, @Nullable final String entityId) {
    try {
        val registeredService = findRegisteredService(serviceId);
        val issuer = StringUtils.defaultIfBlank(entityId, registeredService.getServiceId());
        val criteriaSet = new CriteriaSet();
        criteriaSet.add(new EntityIdCriterion(issuer));
        criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
        val metadataResolver = cachingMetadataResolver.resolve(registeredService, criteriaSet);
        val iteration = metadataResolver.resolve(criteriaSet).spliterator();
        return StreamSupport.stream(iteration, false).map(entity -> Pair.of(entity.getEntityID(), SamlUtils.transformSamlObject(openSamlConfigBean, entity).toString())).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
        return CollectionUtils.wrap("error", e.getMessage());
    }
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) StringUtils(org.apache.commons.lang3.StringUtils) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) SamlUtils(org.apereo.cas.support.saml.SamlUtils) LoggingUtils(org.apereo.cas.util.LoggingUtils) Operation(io.swagger.v3.oas.annotations.Operation) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Nullable(org.springframework.lang.Nullable) StreamSupport(java.util.stream.StreamSupport) ServicesManager(org.apereo.cas.services.ServicesManager) AuditableContext(org.apereo.cas.audit.AuditableContext) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) Collection(java.util.Collection) lombok.val(lombok.val) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Parameter(io.swagger.v3.oas.annotations.Parameter) Slf4j(lombok.extern.slf4j.Slf4j) AuditableExecution(org.apereo.cas.audit.AuditableExecution) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) NumberUtils(org.apache.commons.lang3.math.NumberUtils) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

OpenSamlConfigBean (org.apereo.cas.support.saml.OpenSamlConfigBean)7 Map (java.util.Map)5 lombok.val (lombok.val)5 StringUtils (org.apache.commons.lang3.StringUtils)5 CollectionUtils (org.apereo.cas.util.CollectionUtils)5 Slf4j (lombok.extern.slf4j.Slf4j)4 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)4 SamlUtils (org.apereo.cas.support.saml.SamlUtils)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)4 Bean (org.springframework.context.annotation.Bean)4 HashMap (java.util.HashMap)3 ChainingMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.ChainingMetadataResolverAdapter)3 DynamicMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.DynamicMetadataResolverAdapter)3 StaticMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.StaticMetadataResolverAdapter)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Splitter (com.google.common.base.Splitter)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2