Search in sources :

Example 1 with RequestedAttribute

use of org.opensaml.saml.saml2.metadata.RequestedAttribute in project cas by apereo.

the class AuthnRequestRequestedAttributesAttributeReleasePolicy method getAttributesForSamlRegisteredService.

@Override
protected Map<String, List<Object>> getAttributesForSamlRegisteredService(final Map<String, List<Object>> attributes, final ApplicationContext applicationContext, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredServiceServiceProviderMetadataFacade facade, final EntityDescriptor entityDescriptor, final RegisteredServiceAttributeReleasePolicyContext context) {
    val releaseAttributes = new HashMap<String, List<Object>>();
    getSamlAuthnRequest(applicationContext).ifPresent(authnRequest -> {
        if (authnRequest.getExtensions() != null) {
            authnRequest.getExtensions().getUnknownXMLObjects().stream().filter(object -> object instanceof RequestedAttribute).map(object -> (RequestedAttribute) object).filter(attr -> {
                val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName();
                LOGGER.debug("Checking for requested attribute [{}] in metadata for [{}]", name, context.getRegisteredService().getName());
                return attributes.containsKey(name);
            }).forEach(attr -> {
                val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName();
                LOGGER.debug("Found requested attribute [{}] in metadata for [{}]", name, context.getRegisteredService().getName());
                releaseAttributes.put(name, attributes.get(name));
            });
        }
    });
    return authorizeReleaseOfAllowedAttributes(context, releaseAttributes);
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) Getter(lombok.Getter) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) lombok.val(lombok.val) HashMap(java.util.HashMap) EqualsAndHashCode(lombok.EqualsAndHashCode) ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Map(java.util.Map) ToString(lombok.ToString) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) AllArgsConstructor(lombok.AllArgsConstructor) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) RequestedAttribute(org.opensaml.saml.saml2.metadata.RequestedAttribute) NoArgsConstructor(lombok.NoArgsConstructor) HashMap(java.util.HashMap) RequestedAttribute(org.opensaml.saml.saml2.metadata.RequestedAttribute)

Example 2 with RequestedAttribute

use of org.opensaml.saml.saml2.metadata.RequestedAttribute in project cas by apereo.

the class AuthnRequestRequestedAttributesAttributeReleasePolicy method determineRequestedAttributeDefinitions.

@Override
protected List<String> determineRequestedAttributeDefinitions(final RegisteredServiceAttributeReleasePolicyContext context) {
    val definitions = new ArrayList<String>();
    val applicationContext = ApplicationContextProvider.getApplicationContext();
    getSamlAuthnRequest(applicationContext).ifPresent(authnRequest -> {
        if (authnRequest.getExtensions() != null) {
            authnRequest.getExtensions().getUnknownXMLObjects().stream().filter(object -> object instanceof RequestedAttribute).map(object -> (RequestedAttribute) object).forEach(attr -> {
                val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName();
                LOGGER.debug("Found requested attribute [{}] in metadata for [{}]", name, context.getRegisteredService().getName());
                definitions.add(name);
            });
        }
    });
    return definitions;
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) Getter(lombok.Getter) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) lombok.val(lombok.val) HashMap(java.util.HashMap) EqualsAndHashCode(lombok.EqualsAndHashCode) ApplicationContext(org.springframework.context.ApplicationContext) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Map(java.util.Map) ToString(lombok.ToString) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) AllArgsConstructor(lombok.AllArgsConstructor) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) RequestedAttribute(org.opensaml.saml.saml2.metadata.RequestedAttribute) NoArgsConstructor(lombok.NoArgsConstructor) RequestedAttribute(org.opensaml.saml.saml2.metadata.RequestedAttribute) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AllArgsConstructor (lombok.AllArgsConstructor)2 EqualsAndHashCode (lombok.EqualsAndHashCode)2 Getter (lombok.Getter)2 NoArgsConstructor (lombok.NoArgsConstructor)2 Setter (lombok.Setter)2 ToString (lombok.ToString)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 RegisteredServiceAttributeReleasePolicyContext (org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext)2 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)2 SamlRegisteredServiceCachingMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver)2 ApplicationContextProvider (org.apereo.cas.util.spring.ApplicationContextProvider)2 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)2 RequestedAttribute (org.opensaml.saml.saml2.metadata.RequestedAttribute)2 ApplicationContext (org.springframework.context.ApplicationContext)2