/** * Gets the default return value. * * @return the default return value. */ @Nullable public String getDefaultValue() { if (null == defaultValue) { return null; } return defaultValue.getValue(); }
/** {@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 @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 @Nullable public String apply(@Nullable final ProfileRequestContext input) { final AttributeContext attributeContext = attributeContextLookupStrategy.apply(input); if (attributeContext == null) { log.debug("No attribute context within profile request context"); return null; } final IdPAttribute attribute = attributeContext.getIdPAttributes().get(attributeId); if (attribute == null || attribute.getValues().isEmpty()) { log.debug("Attribute '{}' does not exist or has no values", attributeId); return null; } if (attribute.getValues().size() != 1) { log.debug("Returning first string value of attribute '{}'", attributeId); } for (final IdPAttributeValue value : attribute.getValues()) { if (value instanceof StringAttributeValue) { log.debug("Returning value '{}' of attribute '{}'", ((StringAttributeValue) value).getValue(), attributeId); return ((StringAttributeValue) value).getValue(); } } return null; }
/** * Builds a {@link ScopedStringAttributeValue} from a {@link StringAttributeValue} whose value contains a delimited * value. * * @param value the original attribute value * * @return the scoped attribute value * * @throws ResolutionException thrown if the given attribute value does not contain a delimited value */ @Nonnull private IdPAttributeValue<?> buildScopedStringAttributeValue( @Nonnull final StringAttributeValue value) throws ResolutionException { Constraint.isNotNull(value, getLogPrefix() + " Attribute value can not be null"); final String[] stringValues = value.getValue().split(scopeDelimiter); if (stringValues.length < 2) { log.error("{} Input attribute value {} does not contain delimiter {} and can not be split", new Object[] { getLogPrefix(), value.getValue(), scopeDelimiter,}); throw new ResolutionException("Input attribute value can not be split."); } log.debug("{} Value '{}' was split into {} at scope delimiter '{}'", new Object[] {getLogPrefix(), value.getValue(), stringValues, scopeDelimiter,}); return ScopedStringAttributeValue.valueOf(stringValues[0], stringValues[1]); }
/** {@inheritDoc} */ @Override @Nullable public String apply(@Nullable final ProfileRequestContext input) { final AttributeContext attributeContext = attributeContextLookupStrategy.apply(input); if (attributeContext == null) { log.debug("No attribute context within profile request context"); return null; } final Map<String,IdPAttribute> attributes = useUnfilteredAttributes ? attributeContext.getUnfilteredIdPAttributes() : attributeContext.getIdPAttributes(); final IdPAttribute attribute = attributes.get(attributeId); if (attribute == null || attribute.getValues().isEmpty()) { log.debug("Attribute '{}' does not exist or has no values", attributeId); return null; } if (attribute.getValues().size() != 1) { log.debug("Returning first string value of attribute '{}'", attributeId); } for (final IdPAttributeValue value : attribute.getValues()) { if (value instanceof StringAttributeValue) { log.debug("Returning value '{}' of attribute '{}'", ((StringAttributeValue) value).getValue(), attributeId); return ((StringAttributeValue) value).getValue(); } } return null; }
/** * We use an internal list of attribute values to allow the legacy use of getValues().add(). */ private void setupAttributeValues() { if (null != attributeValues) { return; } log.debug("{} values being prepared", getLogPrefix()); // NOTE. This has to be a List - the examples use get(0) final ArrayList<Object> newValues = new ArrayList<>(encapsulatedAttribute.getValues().size()); for (final IdPAttributeValue value : encapsulatedAttribute.getValues()) { if ((value instanceof StringAttributeValue) && !(value instanceof ScopedStringAttributeValue)) { newValues.add(((StringAttributeValue) value).getValue()); } else if (value instanceof EmptyAttributeValue) { // Shib2 made both empty strings and nulls null newValues.add(null); } else { newValues.add(value); } } attributeValues = newValues; log.debug("{} values are : {}", getLogPrefix(), newValues); }
/** {@inheritDoc} */ @Override protected boolean hasMatch(@Nonnull @NonnullElements final Map<String, IdPAttribute> attributeMap) { final IdPAttribute attribute = attributeMap.get(attributeName); if (attribute == null) { log.debug("Attribute {} not found in context, returning {}", attributeName, resultIfMissing); return resultIfMissing; } else if (attribute.getValues().isEmpty()) { log.debug("Attribute {} has no values, returning {}", attributeName, resultIfMissing); return resultIfMissing; } String dateString; for (final IdPAttributeValue<?> value : attribute.getValues()) { if (value instanceof StringAttributeValue) { dateString = ((StringAttributeValue) value).getValue(); try { if (dateTimeFormatter.parseDateTime(dateString).plus(systemTimeOffset).isAfterNow()) { return true; } } catch (final RuntimeException e) { log.info("{} is not a valid date for the configured date parser", dateString); } } } return false; }
/** * Worker function for doAttributeDefintionResolve. This returns an AttributeValue if the input value is appropriate * for encoding as a NameID. * * @param theValue an arbitrary value. * @param resolutionContext the context to get the rest of the values from * @return null or an attributeValue; * @throws ResolutionException if the IdP Name is empty. */ @Nullable private XMLObjectAttributeValue encodeOneValue(@Nonnull final IdPAttributeValue<?> theValue, @Nonnull final AttributeResolutionContext resolutionContext) throws ResolutionException { if (theValue instanceof StringAttributeValue) { final String value = StringSupport.trimOrNull(((StringAttributeValue) theValue).getValue()); if (value == null) { log.warn("{} Value was all whitespace", getLogPrefix()); return null; } final NameIdentifier nid = buildNameId(value, resolutionContext); final XMLObjectAttributeValue val = new XMLObjectAttributeValue(nid); return val; } log.warn("{} Unsupported value type: {}", getLogPrefix(), theValue.getClass().getName()); return null; }
/** * Worker function for doAttributeDefintionResolve. This returns an AttributeValue if the input value is appropriate * for encoding as a NameID. * * @param theValue an arbitrary value. * @param resolutionContext the context to get the rest of the values from * @return null or an attributeValue. * @throws ResolutionException if the IdP Name is empty. */ @Nullable private XMLObjectAttributeValue encodeOneValue(@Nonnull final IdPAttributeValue theValue, @Nonnull final AttributeResolutionContext resolutionContext) throws ResolutionException { if (theValue instanceof StringAttributeValue) { final String value = StringSupport.trimOrNull(((StringAttributeValue) theValue).getValue()); if (value == null) { log.warn("{} Value was all whitespace", getLogPrefix()); return null; } final NameID nid = buildNameId(value, resolutionContext); final XMLObjectAttributeValue val = new XMLObjectAttributeValue(nid); return val; } log.warn("{} Unsupported value type: {}", getLogPrefix(), theValue.getClass().getName()); return null; }
return builder.build(); } else if (value instanceof StringAttributeValue) { builder.add(STRING_VALUE_FIELD, ((StringAttributeValue) value).getValue()); return builder.build();
if (val.getValue() == null || ((StringAttributeValue) val).getValue().isEmpty()) { log.debug("{} Ignoring null/empty string value", getLogPrefix()); continue; val.getValue()); c14nContext.setPrincipalName(applyTransforms(((StringAttributeValue) val).getValue())); return; } else if (val instanceof ScopedStringAttributeValue) {
valueList.addAll(mapValue(null)); } else if (unmappedValue instanceof StringAttributeValue) { valueList.addAll(mapValue(((StringAttributeValue) unmappedValue).getValue())); } else { throw new ResolutionException(new UnsupportedAttributeTypeException("Attribute definition '"