/** {@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; } }
/** * Ensure that all the values in the attribute are of the correct type. * * @param attribute the attribute to look at */ private void checkValues(final IdPAttribute attribute) { if (null == attribute.getValues()) { log.info("{} Attribute '{}' has no values provided.", getLogPrefix(), attribute.getId()); attribute.setValues(Collections.<IdPAttributeValue<?>> emptyList()); return; } log.debug("{} Attribute '{}' has {} value(s).", getLogPrefix(), attribute.getId(), attribute.getValues().size()); final List<IdPAttributeValue<?>> inputValues = attribute.getValues(); final List<IdPAttributeValue<?>> outputValues = new ArrayList<>(inputValues.size()); for (final Object o : inputValues) { if (o instanceof IdPAttributeValue<?>) { outputValues.add((IdPAttributeValue<?>) o); } else { log.error("{} Attribute '{} has attribute value of type {}. This will be ignored", getLogPrefix(), attribute.getId(), o.getClass().getName()); } } attribute.setValues(outputValues); } }
@Override @Nullable protected IdPAttribute doAttributeDefinitionResolve( @Nonnull final AttributeResolutionContext resolutionContext, @Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException { final ProfileRequestContext prc = prcLookupStrategy.apply(resolutionContext); @Nullable final List<IdPAttributeValue<?>> results = attributeValuesFunction.apply(prc); if (null == results) { log.debug("{} Generated no values.", getLogPrefix()); return null; } log.debug("{} Generated {} values.", getLogPrefix(), results.size()); log.trace("{} Values:", getLogPrefix(), results); final IdPAttribute attribute = new IdPAttribute(getId()); attribute.setValues(results); return attribute; }
/** * Clones an attribute. The clone will contains defensive copies of this objects display descriptions and names, * encoders, and values. The elements of each collection, however, are not themselves cloned. * * {@inheritDoc} */ @Override @Nonnull public IdPAttribute clone() throws CloneNotSupportedException { final IdPAttribute clone = (IdPAttribute) super.clone(); clone.setDisplayDescriptions(getDisplayDescriptions()); clone.setDisplayNames(getDisplayNames()); clone.setEncoders(getEncoders()); clone.setValues(getValues()); return clone; }
/** * Whether the IdP attribute is empty. * * @param input the IdP Attribute * @return true if the IdP attribute has no values or empty values, false otherwise */ private boolean isEmpty(@Nonnull final IdPAttribute input) { for (final IdPAttributeValue value : input.getValues()) { if (!(value instanceof EmptyAttributeValue)) { return false; } } return true; } }
if (idpAttribute.getValues().isEmpty()) { continue; for (final AttributeEncoder encoder : idpAttribute.getEncoders()) { if (encoderType.isInstance(encoder) && ((NameIdentifierAttributeEncoder) encoder).apply(format) && encoder.getActivationCondition().apply(profileRequestContext)) { log.debug("Encoded attribute {} into name identifier with format {}", idpAttribute.getId(), format); return nameId;
attribute = new IdPAttribute(effectiveId); attributes.put(effectiveId, attribute); if (attribute.getValues().isEmpty()) { attribute.setValues( Collections.singletonList(StringAttributeValue.valueOf(results.getString(i)))); } else { final List<IdPAttributeValue<?>> values = new ArrayList<>(attribute.getValues()); values.add(StringAttributeValue.valueOf(results.getString(i))); attribute.setValues(values);
throws AttributeEncodingException { log.debug("{} Attempting to encode attribute {} as a SAML 1 Attribute", getLogPrefix(), attribute.getId()); final Set<AttributeEncoder<?>> encoders = attribute.getEncoders(); if (encoders.isEmpty()) { log.debug("{} Attribute {} does not have any encoders, nothing to do", getLogPrefix(), attribute.getId()); return; && encoder instanceof SAML1AttributeEncoder && encoder.getActivationCondition().apply(profileRequestContext)) { log.debug("{} Encoding attribute {} as a SAML 1 Attribute", getLogPrefix(), attribute.getId()); try { added = true; if (isIgnoringUnencodableAttributes()) { log.debug("{} Unable to encode attribute {} as SAML 1 attribute", getLogPrefix(), attribute.getId(), e); } else { throw e; log.debug( "{} Attribute {} did not have a usable SAML 1 Attribute encoder associated with it, nothing to do", getLogPrefix(), attribute.getId());
final Collection<IdPAttributeValue<?>> keepers = new ArrayList<>(attribute.getValues().size()); for (final IdPAttributeValue<?> value : attribute.getValues()) { if (!requested.getValues().isEmpty()) { requestedValues = true; if (requested.getValues().contains(value)) { keepers.add(value); break; attribute.setValues(keepers); return keepers.size();
if (resolvedAttribute.getValues().isEmpty()) { log.debug("{} produced an attribute with no values", getLogPrefix()); } else { log.debug("{} produced an attribute with the following values {}", getLogPrefix(), resolvedAttribute.getValues()); resolvedAttribute.setDisplayDescriptions(getDisplayDescriptions()); resolvedAttribute.setDisplayNames(getDisplayNames()); resolvedAttribute.setEncoders(getAttributeEncoders());
/** {@inheritDoc} */ @Override @Nonnull protected IdPAttribute newAttribute(@Nonnull final Attribute input, @Nonnull @NotEmpty final String id) { return new IdPAttribute(id); }
/** * Function to reconstruct the attribute after the scripting. If {@link #getValues()} has been called then this is * taken as the content and the attribute updated, otherwise the Attribute is returned. * * @return a suitable modified attribute. * @throws ResolutionException if we find the wrong type. */ @Nonnull protected IdPAttribute getResultingAttribute() throws ResolutionException { if (null == attributeValues) { log.debug("{} return initial attribute unchanged", getLogPrefix()); return encapsulatedAttribute; } // Otherwise re-marshall the {@link #attributeValues} final List<IdPAttributeValue<?>> valueList = new ArrayList<>(attributeValues.size()); log.debug("{} recreating attribute contents from {}", getLogPrefix(), attributeValues); for (final Object object : attributeValues) { policeValueType(object); addAsIdPAttributeValue(valueList, object); } encapsulatedAttribute.setValues(valueList); log.debug("{} recreated attribute contents are {}", getLogPrefix(), valueList); return encapsulatedAttribute; }
/** {@inheritDoc} */ @Override @Nonnull protected Map<Locale, String> getDisplayInfo(@Nonnull final IdPAttribute attribute) { return attribute.getDisplayNames(); } }
/** {@inheritDoc} */ @Override @Nonnull protected Map<Locale, String> getDisplayInfo(@Nonnull IdPAttribute attribute) { return attribute.getDisplayDescriptions(); } }
/** {@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()); }
/** {@inheritDoc} */ @Override public Set<IdPAttributeValue<?>> getMatchingValues(@Nonnull final IdPAttribute attribute, @Nonnull final AttributeFilterContext filterContext) { return ImmutableSet.copyOf(attribute.getValues()); }
attribute = new IdPAttribute(effectiveId); attributes.put(effectiveId, attribute); attr.getStringValues().size() + attribute.getValues().size()); values.addAll(attribute.getValues()); attribute.setValues(values);
throws AttributeEncodingException { log.debug("{} Attempting to encode attribute {} as a SAML 2 Attribute", getLogPrefix(), attribute.getId()); final Set<AttributeEncoder<?>> encoders = attribute.getEncoders(); if (encoders.isEmpty()) { log.debug("{} Attribute {} does not have any encoders, nothing to do", getLogPrefix(), attribute.getId()); return; && encoder instanceof SAML2AttributeEncoder && encoder.getActivationCondition().apply(profileRequestContext)) { log.debug("{} Encoding attribute {} as a SAML 2 Attribute", getLogPrefix(), attribute.getId()); try { results.add((Attribute) encoder.encode(attribute)); if (isIgnoringUnencodableAttributes()) { log.debug("{} Unable to encode attribute {} as SAML 2 attribute", getLogPrefix(), attribute.getId(), e); } else { throw e; log.debug( "{} Attribute {} did not have a usable SAML 2 Attribute encoder associated with it, nothing to do", getLogPrefix(), attribute.getId());
/** {@inheritDoc} */ @Override @Nonnull protected IdPAttribute newAttribute(@Nonnull final AttributeDesignator input, @Nonnull @NotEmpty final String id) { return new IdPAttribute(id); }