/** {@inheritDoc} */ protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject) throws UnmarshallingException { AttributeConsumingService service = (AttributeConsumingService) parentSAMLObject; if (childSAMLObject instanceof ServiceName) { service.getNames().add((ServiceName) childSAMLObject); } else if (childSAMLObject instanceof ServiceDescription) { service.getDescriptions().add((ServiceDescription) childSAMLObject); } else if (childSAMLObject instanceof RequestedAttribute) { service.getRequestAttributes().add((RequestedAttribute) childSAMLObject); } else { super.processChildElement(parentSAMLObject, childSAMLObject); } }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { AttributeConsumingService service = (AttributeConsumingService) samlObject; domElement.setAttributeNS(null, AttributeConsumingService.INDEX_ATTRIB_NAME, Integer.toString(service .getIndex())); if (service.isDefaultXSBoolean() != null) { domElement.setAttributeNS(null, AttributeConsumingService.IS_DEFAULT_ATTRIB_NAME, service .isDefaultXSBoolean().toString()); } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { AttributeConsumingService service = (AttributeConsumingService) samlObject; if (attribute.getLocalName().equals(AttributeConsumingService.INDEX_ATTRIB_NAME)) { service.setIndex(Integer.valueOf(attribute.getValue())); } else if (attribute.getLocalName().equals(AttributeConsumingService.IS_DEFAULT_ATTRIB_NAME)) { service.setIsDefault(XSBooleanValue.valueOf(attribute.getValue())); } else { super.processAttribute(samlObject, attribute); } } }
protected AttributeConsumingService getAttributeConsumingService(List<Attribute> attributes) { AttributeConsumingService service = buildSAMLObject(AttributeConsumingService.class); service.setIsDefault(true); service.setIndex(0); List<RequestedAttribute> attrs = new LinkedList<>(); for (Attribute a : attributes) { RequestedAttribute ra = buildSAMLObject(RequestedAttribute.class); ra.setIsRequired(a.isRequired()); ra.setFriendlyName(a.getFriendlyName()); ra.setName(a.getName()); ra.setNameFormat(a.getNameFormat().toString()); attrs.add(ra); } service.getRequestAttributes().addAll(attrs); return service; }
protected List<Attribute> getRequestAttributes(SPSSODescriptor desc) { List<Attribute> result = new LinkedList<>(); if (desc.getDefaultAttributeConsumingService() != null) { result.addAll(getRequestedAttributes(desc.getDefaultAttributeConsumingService() .getRequestAttributes())); } else { for (AttributeConsumingService s : ofNullable(desc.getAttributeConsumingServices()).orElse(emptyList())) { if (s != null) { //take the first one result.addAll(getRequestedAttributes(s.getRequestAttributes())); break; } } } return result; }
/** {@inheritDoc}*/ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { if (acsContext == null) { log.trace("{} AttributeConsumingServiceContext not found", getLogPrefix()); return; } final AttributeConsumingService acs = acsContext.getAttributeConsumingService(); if (acs == null) { log.trace("{} no AttributeConsumingService to map", getLogPrefix()); return; } if (acs.getRequestAttributes().isEmpty() || acs.getObjectMetadata().containsKey(AttributesMapContainer.class) || acs.getParent() != null) { log.trace("{} skipping mapping for AttributeConsumingService", getLogPrefix()); // Nothing to map, already mapped, or attached to metadata (and hence already scanned) return; } try { final AttributeMappingNodeProcessor processor = new AttributeMappingNodeProcessor(attributeResolverService); log.debug("{} mapping requested Attributes for generated AttributeConsumingService", getLogPrefix()); processor.process(acs); } catch (final FilterException e) { log.error("{} Error mapping Attributesresponding to request", getLogPrefix(), e); ActionSupport.buildEvent(profileRequestContext, EventIds.RUNTIME_EXCEPTION); } }
/** * Look inside the {@link AttributeConsumingService} for any {@link RequestedAttribute}s and map them. * * @param acs the {@link AttributeConsumingService} to look at */ //CheckStyle: ReturnCount OFF private void handleAttributeConsumingService(final AttributeConsumingService acs) { final List<RequestedAttribute> requestedAttributes = acs.getRequestAttributes(); final RequestedAttributesMapper mapper = getRequestedAttributesMapper(); if (null == requestedAttributes || requestedAttributes.isEmpty() || null == mapper) { return; } final Multimap<String, IdPRequestedAttribute> maps = mapper.mapAttributes(requestedAttributes); if (null == maps || maps.isEmpty()) { return; } acs.getObjectMetadata().put(new AttributesMapContainer<>(maps)); } //CheckStyle: ReturnCount ON
/** * Select the default service. * * @param candidates the list of candiate services * @return the selected candidate or null */ private AttributeConsumingService selectDefault(List<AttributeConsumingService> candidates) { log.debug("Selecting default AttributeConsumingService"); AttributeConsumingService firstNoDefault = null; for (AttributeConsumingService attribCS : candidates) { if (attribCS.isDefault()) { log.debug("Selected AttributeConsumingService with explicit isDefault of true"); return attribCS; } // This records the first element whose isDefault is not explicitly false if (firstNoDefault == null && attribCS.isDefaultXSBoolean() == null) { firstNoDefault = attribCS; } } if (firstNoDefault != null) { log.debug("Selected first AttributeConsumingService with no explicit isDefault"); return firstNoDefault; } else { log.debug("Selected first AttributeConsumingService with explicit isDefault of false"); return candidates.get(0); } } }
/** * Select the service based on the index value. * * @param candidates the list of candiate services * @return the selected candidate or null */ private AttributeConsumingService selectByIndex(List<AttributeConsumingService> candidates) { log.debug("Selecting AttributeConsumingService by index"); for (AttributeConsumingService attribCS : candidates) { // Check for null b/c don't ever want to fail with an NPE due to autoboxing. // Note: metadata index property is an int, not an Integer. if (index != null) { if (index == attribCS.getIndex()) { log.debug("Selected AttributeConsumingService with index: {}", index); return attribCS; } } } log.debug("A service index of '{}' was specified, but was not found in metadata", index); return null; }
/** * Get the map of requested attributes from the profile request context. * * @param prc the profile request context * @return the map of requested attributes or <code>null</code> */ @Nullable protected Multimap<String, IdPRequestedAttribute> getRequestedAttributes(@Nullable final ProfileRequestContext prc) { if (prc != null) { final SAMLMetadataContext metadataContext = metadataContextLookupStrategy.apply(prc); if (metadataContext != null) { final AttributeConsumingService acs = acsLookupStrategy.apply(metadataContext); if (acs != null) { final List<AttributesMapContainer> maps = acs.getObjectMetadata().get(AttributesMapContainer.class); if (maps != null && !maps.isEmpty()) { if (maps.size() > 1) { log.warn("More than one set of mapped attributes found, using the first."); } return maps.get(0).get(); } } } } return null; }
/** * Look for an <AttributeConsumeService> and if its there look for an appropriate name. * * @param lang - which language to look up * @return null or an appropriate name */ @Nullable protected String getNameFromAttributeConsumingService(final String lang) { if (null == getRPAttributeConsumingService()) { return null; } for (final ServiceName name : getRPAttributeConsumingService().getNames()) { log.trace("Found name in AttributeConsumingService, language '{}'", name.getXMLLang()); if (name.getXMLLang() != null && name.getXMLLang().equals(lang)) { log.debug("Returning name from AttributeConsumingService '{}'", name.getValue()); return name.getValue(); } } log.trace("No name found in AttributeConsumingService for '{}'", lang); return null; }
/** * look for an <AttributeConsumeService> and if its there look for an appropriate description. * * @param lang - which language to look up * @return null or an appropriate description */ @Nullable protected String getDescriptionFromAttributeConsumingService(final String lang) { if (getRPAttributeConsumingService() == null) { log.trace("No ACS found"); return null; } for (final ServiceDescription desc : getRPAttributeConsumingService().getDescriptions()) { log.trace("Found name in AttributeConsumingService, language=" + desc.getXMLLang()); if (desc.getXMLLang() != null && desc.getXMLLang().equals(lang)) { log.debug("Returning name from AttributeConsumingService " + desc.getValue()); return desc.getValue(); } } log.trace("No description in AttributeConsumingService"); return null; }
for (final RequestedAttribute requestedAttribute : attributeConsumingService.getRequestAttributes()) { if (Objects.equals(LibertyConstants.SERVICE_TYPE_SSOS, StringSupport.trimOrNull(requestedAttribute.getName()))) {
log.debug("{} Request specified AttributeConsumingService index {}", getLogPrefix(), index); for (final AttributeConsumingService acsEntry : ssoDescriptor.getAttributeConsumingServices()) { if (index.intValue() == acsEntry.getIndex()) { acs = acsEntry; break; log.debug("{} Selected AttributeConsumingService with index {}", getLogPrefix(), acs.getIndex()); metadataContext.getSubcontext( AttributeConsumingServiceContext.class, true).setAttributeConsumingService(acs);
@Override protected Map<String, Object> getAttributesForSamlRegisteredService(final Map<String, Object> attributes, final SamlRegisteredService service, final ApplicationContext applicationContext, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredServiceServiceProviderMetadataFacade facade, final EntityDescriptor entityDescriptor) { val releaseAttributes = new HashMap<String, Object>(); val sso = facade.getSsoDescriptor(); if (sso != null) { sso.getAttributeConsumingServices().forEach(svc -> svc.getRequestAttributes().stream().filter(attr -> { val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName(); LOGGER.debug("Checking for requested attribute [{}] in metadata for [{}]", name, service.getName()); return attributes.containsKey(name); }).forEach(attr -> { val name = this.useFriendlyName ? attr.getFriendlyName() : attr.getName(); LOGGER.debug("Found requested attribute [{}] in metadata for [{}]", name, service.getName()); releaseAttributes.put(name, attributes.get(name)); })); } return releaseAttributes; } }
requestAttribute.setNameFormat(attr.getNameFormat()); attributeService.getRequestAttributes().add(requestAttribute);