/** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof IdPAttribute)) { return false; } final IdPAttribute other = (IdPAttribute) obj; return java.util.Objects.equals(id, other.getId()); }
/** * Constructor. * * @param attribute the attribute we are encapsulating. * @param prefix the log path from the definition. */ public ScriptedIdPAttributeImpl(@Nonnull final IdPAttribute attribute, final String prefix) { encapsulatedAttribute = attribute; logPrefix = new StringBuilder(prefix).append(" scripted attribute '").append(attribute.getId()).append("':") .toString(); }
/** {@inheritDoc} */ @Override @Nonnull public String toString() { return MoreObjects.toStringHelper(this).add("id", getId()).add("displayNames", displayNames) .add("displayDescriptions", displayDescriptions).add("encoders", encoders).add("values", values) .toString(); }
/** {@inheritDoc} */ @Override @Nonnull @NotEmpty public String getName() { return attribute.getId(); }
/** * Get the encapsulated attributeId. * * @return the id */ @Override @Nonnull @NotEmpty public String getId() { return encapsulatedAttribute.getId(); }
/** * Adds the values of the given attribute to the target collection of attribute values. * * @param source the source attribute * @param target current set attribute values */ @Nonnull private static void addAttribute(@Nullable final IdPAttribute source, @Nullable final Map<String, List<IdPAttributeValue<?>>> target) { if (source == null) { return; } List<IdPAttributeValue<?>> attributeValues = target.get(source.getId()); if (attributeValues == null) { attributeValues = new ArrayList<>(); target.put(source.getId(), attributeValues); } mergeAttributeValues(source, attributeValues); }
/** {@inheritDoc} */ public boolean apply(@Nullable final IdPAttribute input) { if (input != null && requestedAttributesMap != null && !requestedAttributesMap.isEmpty()) { final Collection<IdPRequestedAttribute> requestedAttrs = requestedAttributesMap.get(input.getId()); if (requestedAttrs != null) { for (final IdPRequestedAttribute requestedAttr : requestedAttrs) { if (requestedAttr != null && requestedAttr.getIsRequired()) { log.debug("Attribute '{}' is required", input); return true; } } } } log.debug("Attribute '{}' is not required", input); return false; }
/** * Sets the attributes which are to be filtered. * * @param attributes attributes which are to be filtered */ public void setPrefilteredIdPAttributes(@Nullable @NullableElements final Collection<IdPAttribute> attributes) { final Collection<IdPAttribute> checkedAttributes = new ArrayList<>(); CollectionSupport.addIf(checkedAttributes, attributes, Predicates.notNull()); prefilteredAttributes = new HashMap<String, IdPAttribute>(checkedAttributes.size()); for (final IdPAttribute attribute : checkedAttributes) { prefilteredAttributes.put(attribute.getId(), attribute); } }
/** * Sets the attributes that have been filtered. * * @param attributes attributes that have been filtered */ public void setFilteredIdPAttributes(@Nullable @NullableElements final Collection<IdPAttribute> attributes) { final Collection<IdPAttribute> checkedAttributes = new ArrayList<>(); CollectionSupport.addIf(checkedAttributes, attributes, Predicates.notNull()); filteredAttributes = new HashMap<String, IdPAttribute>(checkedAttributes.size()); for (final IdPAttribute attribute : checkedAttributes) { filteredAttributes.put(attribute.getId(), attribute); } }
/** {@inheritDoc} */ @Override @Nullable public List<IdPAttributeValue<?>> apply(@Nullable final Principal principal) { if (null != principal && principal instanceof IdPAttributePrincipal) { final IdPAttributePrincipal attributePrincipal = (IdPAttributePrincipal) principal; final IdPAttribute attribute = attributePrincipal.getAttribute(); if (null != attribute && attributeName.equals(attribute.getId())) { return attribute.getValues(); } } return null; } }
/** * Set the set of resolved attributes. * * @param attributes set of resolved attributes * * @return this context */ @Nullable public AttributeResolutionContext setResolvedIdPAttributes( @Nullable @NullableElements final Collection<IdPAttribute> attributes) { resolvedAttributes = new HashMap<>(); if (attributes != null) { for (final IdPAttribute attribute : attributes) { if (attribute != null) { resolvedAttributes.put(attribute.getId(), attribute); } } } return this; }
/** {@inheritDoc} */ @Override @Nullable protected XMLObject encodeValue(@Nonnull final IdPAttribute attribute, @Nonnull final StringAttributeValue value) throws AttributeEncodingException { if (value instanceof LocalizedStringAttributeValue || value instanceof ScopedStringAttributeValue) { log.warn("Attribute '{}': Lossy encoding of attribute value of type {} to SAML2 String Attribute", attribute.getId(), value.getClass().getName()); } return SAMLEncoderSupport.encodeStringValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(), encodeType()); }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { final Collection<IdPAttribute> keepers = new ArrayList<>(query.getAttributeDesignators().size()); final Multimap<String,IdPAttribute> mapped = mapperService.mapAttributes(query.getAttributeDesignators()); log.debug("Query content mapped to attribute IDs: {}", mapped.keySet()); for (final IdPAttribute attribute : attributeContext.getIdPAttributes().values()) { if (mapped.containsKey(attribute.getId())) { log.debug("Retaining attribute '{}' requested by query", attribute.getId()); keepers.add(attribute); } else { log.debug("Removing attribute '{}' not requested by query", attribute.getId()); } } attributeContext.setIdPAttributes(keepers); }
/** {@inheritDoc} */ @Override @Nullable protected XMLObject encodeValue(@Nonnull final IdPAttribute attribute, @Nonnull final StringAttributeValue value) throws AttributeEncodingException { if (value instanceof LocalizedStringAttributeValue || value instanceof ScopedStringAttributeValue) { log.warn("Attribute '{}': Lossy encoding of attribute value of type {} to SAML1 String Attribute", attribute.getId(), value.getClass().getName()); } return SAMLEncoderSupport.encodeStringValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(), encodeType()); } }
/** {@inheritDoc} */ @Override @Nonnull @NotEmpty public String apply(@Nullable final IdPAttribute input) { if (input == null) { return "N/A"; } final Map<Locale, String> displayInfo = getDisplayInfo(input); if (null != displayInfo && !displayInfo.isEmpty()) { for (final Locale locale : locales) { String toBeDisplayed = displayInfo.get(locale); if (toBeDisplayed != null) { return toBeDisplayed; } toBeDisplayed = displayInfo.get(Locale.forLanguageTag(locale.getLanguage())); if (toBeDisplayed != null) { return toBeDisplayed; } } } return input.getId(); }
/** {@inheritDoc} */ @Override @Nonnull @NotEmpty public String apply(@Nonnull final IdPAttribute input) { if (input == null) { return "N/A"; } final Map<Locale, String> displayNames = getDisplayInfo(input); if (null != displayNames && !displayNames.isEmpty()) { for (final Locale locale : locales) { String displayName = displayNames.get(locale); if (displayName != null) { return displayName; } displayName = displayNames.get(Locale.forLanguageTag(locale.getLanguage())); if (displayName != null) { return displayName; } } } return input.getId(); }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { final Map<String, IdPAttribute> attributes = getAttributeContext().getIdPAttributes(); final Map<String, IdPAttribute> consentableAttributes = new TreeMap<>(attributeIdComparator); for (final IdPAttribute attribute : attributes.values()) { if (attributePredicate.apply(attribute)) { consentableAttributes.put(attribute.getId(), attribute); } } getAttributeReleaseContext().getConsentableAttributes().putAll(consentableAttributes); log.debug("{} Consentable attributes '{}'", getLogPrefix(), consentableAttributes); }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { final Map<String, IdPAttribute> attributes = getAttributeContext().getIdPAttributes(); final Map<String, IdPAttribute> consentableAttributes = new TreeMap<>(attributeIdComparator); for (final IdPAttribute attribute : attributes.values()) { if (attributePredicate.apply(attribute)) { consentableAttributes.put(attribute.getId(), attribute); } } getAttributeReleaseContext().getConsentableAttributes().putAll(consentableAttributes); log.debug("{} Consentable attributes '{}'", getLogPrefix(), consentableAttributes); }
/** * Compare the result's custom principal names to the string values of the attribute. * * @param result result to examine * * @return a match between the result's principal names and the attribute's string values, or null */ @Nullable private String getMatch(@Nonnull final AuthenticationResult result) { log.debug("{} Looking for match for active result of flow {} against values for attribute {}", getLogPrefix(), result.getAuthenticationFlowId(), attribute.getId()); for (final Principal p : result.getSupportedPrincipals(Principal.class)) { log.debug("{} Comparing principal {} against attribute values {}", getLogPrefix(), p.getName(), attribute.getValues()); for (final IdPAttributeValue val : attribute.getValues()) { if (val instanceof StringAttributeValue && Objects.equals(val.getValue(), p.getName())) { return p.getName(); } } } return null; }