Class OIDCStringAttributeTranscoder

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.attribute.transcoding.AbstractAttributeTranscoder<net.minidev.json.JSONObject>
net.shibboleth.oidc.attribute.transcoding.AbstractOIDCAttributeTranscoder
net.shibboleth.oidc.attribute.transcoding.impl.OIDCStringAttributeTranscoder
All Implemented Interfaces:
net.shibboleth.idp.attribute.transcoding.AttributeTranscoder<net.minidev.json.JSONObject>, OIDCAttributeTranscoder, Component, DestructableComponent, InitializableComponent

public class OIDCStringAttributeTranscoder extends AbstractOIDCAttributeTranscoder
Class encoding string attributes to string json object. Name of the attribute will be set as the key. The string contains attribute value. If there are several attribute values they are delimited with delimiter(space is default) or placed to array. If the value is set to be interpreted as int, only values that may be parsed to int are used. In case output is interpreted as int but not set to array, only the first parsable value is used. If the value is interpreted as boolean the value is true if string value equals to "true" ignoring the case. If boolean values are not set to array the first string value is considered to be the result. Finally, the result may be placed to json Object.

For decoding, attempt to convert the input JSON type into a StringAttributeValue in the following way for the following JSON types:

  • If a String, convert directly to a string attribute value.
  • If an Integer or Double (a number type) and PROP_NUMBER_AS_STRING is true, convert to string, else return an empty values list.
  • If a Boolean and PROP_BOOLEAN_AS_STRING is true, convert boolean to 'true' or 'false' string, else return an empty values list.
  • If a JSON Array and PROP_ARRAY_AS_STRING is true, convert to a string by serializing the array to a JSON string.
  • If a JSON Array and PROP_ARRAY_AS_STRING is false, attempt to recursively convert elements of the array to string attribute values using the same set of rules. If any element fails to convert it will be excluded from the result.
  • If a JSON Object and PROP_ASOBJECT is true, convert the object to a string by serializing into JSON. Else, return an empty values list.
  • For any other unknown type, return an empty values list.
  • Field Details

    • PROP_ASOBJECT

      @Nonnull @NotEmpty public static final String PROP_ASOBJECT
      Whether to parse the values into and out as a JSON object.
      See Also:
    • log

      @Nonnull private final org.slf4j.Logger log
      Class logger.
  • Constructor Details

    • OIDCStringAttributeTranscoder

      public OIDCStringAttributeTranscoder()
  • Method Details

    • encodeValues

      @Nullable protected Object encodeValues(@Nullable ProfileRequestContext profileRequestContext, @Nonnull net.shibboleth.idp.attribute.IdPAttribute attribute, @Nonnull net.shibboleth.idp.attribute.transcoding.TranscodingRule rule) throws net.shibboleth.idp.attribute.AttributeEncodingException
      Specified by:
      encodeValues in class AbstractOIDCAttributeTranscoder
      Throws:
      net.shibboleth.idp.attribute.AttributeEncodingException
    • decodeValues

      @Nonnull @NonnullElements protected List<net.shibboleth.idp.attribute.IdPAttributeValue> decodeValues(@Nullable ProfileRequestContext profileRequestContext, @Nonnull Object input, @Nonnull net.shibboleth.idp.attribute.transcoding.TranscodingRule rule) throws net.shibboleth.idp.attribute.AttributeDecodingException
      Specified by:
      decodeValues in class AbstractOIDCAttributeTranscoder
      Throws:
      net.shibboleth.idp.attribute.AttributeDecodingException
    • toJSONObject

      @Nonnull private Object toJSONObject(@Nonnull @NotEmpty String value) throws net.shibboleth.idp.attribute.AttributeEncodingException
      Parses string as JSONObject.
      Parameters:
      value - string to parse
      Returns:
      string parsed as JSONObject
      Throws:
      net.shibboleth.idp.attribute.AttributeEncodingException - if parsing fails
    • transformValues

      @Nonnull @NonnullElements @NotLive @Unmodifiable private List<?> transformValues(@Nonnull net.shibboleth.idp.attribute.transcoding.TranscodingRule rule, @Nonnull @NonnullElements Stream<String> attributeValues)
      Converts string values to List of Integer, String or Boolean depending on rule.
      Parameters:
      rule - transcoding rule
      attributeValues - IdPAttribute values
      Returns:
      list of String, Boolean or Integer objects