/** * Gets the default return value. * * @return the default return value. */ @Nullable public String getDefaultValue() { if (null == defaultValue) { return null; } return defaultValue.getValue(); }
/** * Returns an {@link EmptyAttributeValue} or {@link StringAttributeValue} as appropriate. This method should be * preferred over the constructor when the value may be null or empty. * * @param value to inspect * @return {@link EmptyAttributeValue} or {@link StringAttributeValue} */ @Nonnull public static IdPAttributeValue<?> valueOf(@Nullable final String value) { if (value == null) { return EmptyAttributeValue.NULL; } else if (value.length() == 0) { return EmptyAttributeValue.ZERO_LENGTH; } else { return new StringAttributeValue(value); } } }
/** * Add the provided value to the provided list, converting {@link String} to {@link StringAttributeValue}. * * @param values the list to add to. * @param value the value to add. Known to be a {@link String} or an {@link IdPAttributeValue} */ private void addAsIdPAttributeValue(final List<IdPAttributeValue<?>> values, final Object value) { if (null == value) { values.add(new EmptyAttributeValue(EmptyType.NULL_VALUE)); } else if (value instanceof String) { values.add(StringAttributeValue.valueOf((String) value)); } else { values.add((IdPAttributeValue) value); } }
/** {@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()); }
/** * Maps the value from a dependency in to the value(s) for this attribute. * * @param value the value from the dependency * * @return the set of attribute values that the given dependency value maps in to */ protected List<StringAttributeValue> mapValue(@Nullable final String value) { log.debug("Attribute Definition {}: mapping dependency attribute value {}", getId(), value); final List<StringAttributeValue> mappedValues = new ArrayList<>(); if (!Strings.isNullOrEmpty(value)) { boolean valueMapMatch = false; for (final ValueMap valueMap : valueMaps) { mappedValues.addAll(valueMap.apply(value)); if (!mappedValues.isEmpty()) { valueMapMatch = true; } } if (!valueMapMatch) { if (passThru) { mappedValues.add(new StringAttributeValue(value)); } else if (defaultValue != null) { mappedValues.add(defaultValue); } } } log.debug("Attribute Definition {}: mapped dependency attribute value {} to the values {}", new Object[] { getId(), value, mappedValues,}); return mappedValues; }
/** {@inheritDoc} */ @Nullable protected IdPAttributeValue<?> decodeValue(final XMLObject object) { Constraint.isNotNull(object, "Object supplied to must not be null"); final String value = getStringValue(object); if (null == value) { return null; } return StringAttributeValue.valueOf(value); }
/** {@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()); } }
/** * Sets the default return value. * * @param newDefaultValue the default return value */ public void setDefaultValue(@Nullable final String newDefaultValue) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); ComponentSupport.ifDestroyedThrowDestroyedComponentException(this); final String trimmedDefault = StringSupport.trimOrNull(newDefaultValue); if (null == trimmedDefault) { defaultValue = null; } else { defaultValue = new StringAttributeValue(trimmedDefault); } }
/** * Encode the provided string. * * @param value the value to encode or null if that failed * @return null or the attribute. */ @Nullable protected Map<String, IdPAttribute> encodeAsAttribute(@Nullable final String value) { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); if (null == value) { // The message will have been logged above return null; } final IdPAttribute attribute = new IdPAttribute(getGeneratedAttributeId()); attribute.setValues(Collections.singletonList(StringAttributeValue.valueOf(value))); return Collections.singletonMap(getGeneratedAttributeId(), attribute); }
/** {@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; }
/** {@inheritDoc} */ @Override @Nullable protected IdPAttribute doAttributeDefinitionResolve( @Nonnull final AttributeResolutionContext resolutionContext, @Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException { final String method = StringSupport.trimOrNull(resolutionContext.getPrincipalAuthenticationMethod()); if (null == method) { log.info("{} null or empty method was returned", getLogPrefix()); return null; } final IdPAttribute attribute = new IdPAttribute(getId()); attribute.setValues(Collections.singletonList(new StringAttributeValue(method))); return attribute; } }
/** * 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]); }
mappedValues.add(new StringAttributeValue(newValue));
log.debug("{} Computed the value '{}' by apply regexp '{}' to input value '{}'", getLogPrefix(), matcher.group(1), regexp.pattern(), inputValue); resultantValues.add(StringAttributeValue.valueOf(matcher.group(1))); } else { log.debug("{} Regexp '{}' did not match anything in input value '{}'", getLogPrefix(),
/** {@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; }
@Override @Nullable protected IdPAttribute doAttributeDefinitionResolve( @Nonnull final AttributeResolutionContext resolutionContext, @Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException { final String principalName = StringSupport.trimOrNull(resolutionContext.getPrincipal()); if (null == principalName) { throw new ResolutionException(getLogPrefix() + " provided principal name was empty"); } final IdPAttribute attribute = new IdPAttribute(getId()); attribute.setValues(Collections.singletonList(new StringAttributeValue(principalName))); return attribute; }
values.add(StringAttributeValue.valueOf(value));
/** {@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; }
/** * Prepare name id attribute id p attribute. * * @param casAssertion the assertion * @param nameFormat the name format * @param adaptor the adaptor * @return the idp attribute */ protected IdPAttribute prepareNameIdAttribute(final Object casAssertion, final String nameFormat, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) { val assertion = Assertion.class.cast(casAssertion); val attribute = new IdPAttribute(AttributePrincipal.class.getName()); val principalName = assertion.getPrincipal().getName(); LOGGER.debug("Preparing NameID attribute for principal [{}]", principalName); val nameIdValue = getNameIdValueFromNameFormat(nameFormat, adaptor, principalName); val value = new StringAttributeValue(nameIdValue); LOGGER.debug("NameID attribute value is set to [{}]", value); attribute.setValues(CollectionUtils.wrap(value)); return attribute; }