/** * 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); } } }
/** * 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; }
/** * 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); } }
/** {@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; } }
mappedValues.add(new StringAttributeValue(newValue));
@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; }
/** * 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; }
/** {@inheritDoc} */ @Override @Nonnull protected IdPAttribute doAttributeDefinitionResolve( @Nonnull final AttributeResolutionContext resolutionContext, @Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ComponentSupport.ifDestroyedThrowDestroyedComponentException(this); final String attributeRecipientID = getAttributeRecipientID(resolutionContext); final String principalName = getPrincipal(resolutionContext); try { final String transientId = idGenerator.generate(attributeRecipientID, principalName); log.debug("{} creating new transient ID '{}'", new Object[] {getLogPrefix(), transientId,}); final IdPAttribute result = new IdPAttribute(getId()); result.setValues(Collections.singletonList(new StringAttributeValue(transientId))); return result; } catch (final SAMLException e) { throw new ResolutionException(e); } }
val principalName = request.getTicketGrantingTicket().getAuthentication().getPrincipal().getId(); LOGGER.trace("Preparing NameID attribute for principal [{}]", principalName); attribute.setValues(CollectionUtils.wrap(new StringAttributeValue(principalName))); val nameId = encoder.encode(attribute);
final JsonValue value = object.get(STRING_VALUE_FIELD); if (value instanceof JsonString) { return new StringAttributeValue(((JsonString) value).getString());