/** * Converts the supplied duration to milliseconds and divides it by the divisor. Useful for modifying durations * while resolving property replacement. * * @param duration string format * @param divisor to modify the duration with * * @return result of the division */ public static long buildDuration(final String duration, final long divisor) { return DOMTypeSupport.durationToLong(duration) / divisor; }
/** {@inheritDoc} */ @Nonnull public XMLObjectType buildObject(@Nonnull final Element element) { XMLObjectType xmlObject; String localName = element.getLocalName(); String nsURI = element.getNamespaceURI(); String nsPrefix = element.getPrefix(); QName schemaType = DOMTypeSupport.getXSIType(element); xmlObject = buildObject(nsURI, localName, nsPrefix, schemaType); return xmlObject; } }
@Override public Duration toDuration(long millis) { if (millis < 0) { return null; } else { return DOMTypeSupport.getDataTypeFactory().newDuration(millis); } }
/** {@inheritDoc} */ @Override public Long convert(final String source) { if (source.startsWith("P")) { return DOMTypeSupport.durationToLong(source.trim()); } else if (source.startsWith("-P")) { throw new IllegalArgumentException("Negative durations are not supported"); } else { // Treat as a milliseconds. But note this final long duration = Long.valueOf(source); log.info("Deprecated duration of {} was specified. Use XML duration of {}", source, DOMTypeSupport.longToDuration(duration)); return duration; } }
/** {@inheritDoc} */ @Override public BeanDefinition parseCustomElement(final Element element, final BeanDefinition containingBd) { String namespaceUri = element.getNamespaceURI(); if (DOMTypeSupport.hasXSIType(element)) { namespaceUri = DOMTypeSupport.getXSIType(element).getNamespaceURI(); } final NamespaceHandler handler = getReaderContext().getNamespaceHandlerResolver().resolve(namespaceUri); if (handler == null) { error("Unable to locate NamespaceHandler for namespace [" + namespaceUri + "]", element); return null; } return handler.parse(element, new ParserContext(getReaderContext(), this, containingBd)); } }
/** {@inheritDoc} */ @Override @Nullable public XMLObject filter(@Nullable final XMLObject metadata) throws FilterException { if (metadata == null) { return null; } final DateTime validUntil = getValidUntil(metadata); if (validUntil == null) { throw new FilterException("Metadata did not include a validUntil attribute"); } final DateTime now = new DateTime(ISOChronology.getInstanceUTC()); if (maxValidityInterval > 0 && validUntil.isAfter(now)) { final long validityInterval = validUntil.getMillis() - now.getMillis(); if (validityInterval > maxValidityInterval) { throw new FilterException(String.format("Metadata's validity interval %s is larger than is allowed %s", DOMTypeSupport.longToDuration(validityInterval), DOMTypeSupport.longToDuration(maxValidityInterval))); } } return metadata; }
String cacheDuration = DOMTypeSupport.longToDuration(roleDescriptor.getCacheDuration()); domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
/** {@inheritDoc} */ @Nonnull public XMLObjectType buildObject(@Nonnull final Element element) { XMLObjectType xmlObject; String localName = element.getLocalName(); String nsURI = element.getNamespaceURI(); String nsPrefix = element.getPrefix(); QName schemaType = DOMTypeSupport.getXSIType(element); xmlObject = buildObject(nsURI, localName, nsPrefix, schemaType); return xmlObject; } }
/** Constructor. */ public ConsentFlowDescriptor() { lifetime = DOMTypeSupport.durationToLong("P1Y"); expandedStorageThreshold = 1024 * 1024; }
String cacheDuration = DOMTypeSupport.longToDuration(entitiesDescriptor.getCacheDuration()); domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
/** {@inheritDoc} */ @Override public void setAsText(final String text) { if (text.startsWith("P")) { setValue(DOMTypeSupport.getDataTypeFactory().newDuration(text.trim())); } else if (text.startsWith("-P")) { throw new IllegalArgumentException("Negative durations are not supported"); } else { setValue(DOMTypeSupport.getDataTypeFactory().newDuration(Long.valueOf(text))); } } }
/** {@inheritDoc} */ @Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { if (TYPE_NAME_FILESYSTEM.equals(DOMTypeSupport.getXSIType(element))) { log.warn("Credential type '{}' has been deprecated; use the compatible Credential type '{}'", TYPE_NAME_FILESYSTEM.getLocalPart(), TYPE_NAME_RESOURCE.getLocalPart()); } super.doParse(element, builder); } }
/** Constructor. */ public ConsentFlowDescriptor() { lifetime = DOMTypeSupport.durationToLong("P1Y"); }
String cacheDuration = DOMTypeSupport.longToDuration(entityDescriptor.getCacheDuration()); domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
/** {@inheritDoc} */ @Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { if (TYPE_NAME_FILESYSTEM.equals(DOMTypeSupport.getXSIType(element))) { log.warn("Credential type '{}' has been deprecated; use the compatible Credential type '{}'", TYPE_NAME_FILESYSTEM.getLocalPart(), TYPE_NAME_RESOURCE.getLocalPart()); } super.doParse(element, builder); } }
@Override public long toMillis(Duration duration) { if (isNull(duration)) { return -1; } else { return DOMTypeSupport.durationToLong(duration); } }
String cacheDuration = DOMTypeSupport.longToDuration(descriptor.getCacheDuration()); domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
/** {@inheritDoc} */ @Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { if (TYPE_NAME_FILESYSTEM.equals(DOMTypeSupport.getXSIType(element))) { log.warn("Credential type '{}' has been deprecated; use the compatible Credential type '{}'", TYPE_NAME_FILESYSTEM.getLocalPart(), TYPE_NAME_RESOURCE.getLocalPart()); } super.doParse(element, builder); }
/** Helper function to return the TTL with a suitable default. * @param timeToLive duration string * @return the input as a long, or DEFAULT_TTL_MS */ private static long getTimeToLiveMs(@Nullable final String timeToLive) { if (timeToLive != null) { return DOMTypeSupport.durationToLong(timeToLive); } else { return DEFAULT_TTL_MS; } }
/** * Handle attributes which are inappropriate for specific implementations. The chaining metadata provider cannot * have "requireValidMetadata" or "failFastInitialization" set, even though they are present in the schema. <br/> * This method detects whether these elements are present and if the element is not a chaining provider returns * true, otherwise it returns false and emits a warning. * * @param element the element * @param attribute the attribute * @return true iff this is not a chaining resolver and the attribute is present */ private boolean isPresentNotChaining(@Nonnull final Element element, @Nonnull final String attribute) { if (!element.hasAttributeNS(null, attribute)) { return false; } if (CHAINING_PROVIDER_ELEMENT_NAME.equals(DOMTypeSupport.getXSIType(element))) { log.warn("{} is not valid for {}", attribute, CHAINING_PROVIDER_ELEMENT_NAME.getLocalPart()); return false; } return true; }