/** * 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; }
/** Constructor. */ public ConsentFlowDescriptor() { lifetime = DOMTypeSupport.durationToLong("P1Y"); expandedStorageThreshold = 1024 * 1024; }
/** Constructor. */ public ConsentFlowDescriptor() { lifetime = DOMTypeSupport.durationToLong("P1Y"); }
@Override public long toMillis(Duration duration) { if (isNull(duration)) { return -1; } else { return DOMTypeSupport.durationToLong(duration); } }
/** 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; } }
/** {@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} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { EntityDescriptor entityDescriptor = (EntityDescriptor) samlObject; if (attribute.getLocalName().equals(EntityDescriptor.ENTITY_ID_ATTRIB_NAME)) { entityDescriptor.setEntityID(attribute.getValue()); } else if (attribute.getLocalName().equals(EntityDescriptor.ID_ATTRIB_NAME)) { entityDescriptor.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { entityDescriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) { entityDescriptor.setCacheDuration(DOMTypeSupport.durationToLong(attribute.getValue())); } else { processUnknownAttribute(entityDescriptor, attribute); } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { AffiliationDescriptor descriptor = (AffiliationDescriptor) samlObject; if (attribute.getLocalName().equals(AffiliationDescriptor.OWNER_ID_ATTRIB_NAME)) { descriptor.setOwnerID(attribute.getValue()); } else if (attribute.getLocalName().equals(AffiliationDescriptor.ID_ATTRIB_NAME)) { descriptor.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { descriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) { descriptor.setCacheDuration(DOMTypeSupport.durationToLong(attribute.getValue())); } else { processUnknownAttribute(descriptor, attribute); } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { EntitiesDescriptor entitiesDescriptor = (EntitiesDescriptor) samlObject; if (attribute.getLocalName().equals(EntitiesDescriptor.ID_ATTRIB_NAME)) { entitiesDescriptor.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { entitiesDescriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) { entitiesDescriptor.setCacheDuration(new Long(DOMTypeSupport.durationToLong(attribute.getValue()))); } else if (attribute.getLocalName().equals(EntitiesDescriptor.NAME_ATTRIB_NAME)) { entitiesDescriptor.setName(attribute.getValue()); } else { super.processAttribute(samlObject, attribute); } } }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { RoleDescriptor roleDescriptor = (RoleDescriptor) samlObject; if (attribute.getLocalName().equals(RoleDescriptor.ID_ATTRIB_NAME)) { roleDescriptor.setID(attribute.getValue()); attribute.getOwnerElement().setIdAttributeNode(attribute, true); } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME) && !Strings.isNullOrEmpty(attribute.getValue())) { roleDescriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC())); } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) { roleDescriptor.setCacheDuration(DOMTypeSupport.durationToLong(attribute.getValue())); } else if (attribute.getLocalName().equals(RoleDescriptor.PROTOCOL_ENUMERATION_ATTRIB_NAME)) { StringTokenizer protocolTokenizer = new StringTokenizer(attribute.getValue(), " "); while (protocolTokenizer.hasMoreTokens()) { roleDescriptor.addSupportedProtocol(protocolTokenizer.nextToken()); } } else if (attribute.getLocalName().equals(RoleDescriptor.ERROR_URL_ATTRIB_NAME)) { roleDescriptor.setErrorURL(attribute.getValue()); } else { processUnknownAttribute(roleDescriptor, attribute); } } }
/** {@inheritDoc} */ @Override protected RequiredValidUntilFilter createInstance() throws Exception { final RequiredValidUntilFilter value = new RequiredValidUntilFilter(); if (null != maxValidityIntervalDuration) { if (maxValidityIntervalDuration.startsWith("P")) { value.setMaxValidityInterval(DOMTypeSupport.durationToLong(maxValidityIntervalDuration)); } else if (maxValidityIntervalDuration.startsWith("-P")) { throw new IllegalArgumentException("Negative durations are not supported"); } else { // Treat as a Long and seconds. value.setMaxValidityInterval(1000 * Long.valueOf(maxValidityIntervalDuration)); DeprecationSupport.warn(ObjectType.ATTRIBUTE, "maxValidityIntervalDuration (when numeric)", "RequiredValidUntil MetadataFilter", "duration notation"); } } return value; }
/** {@inheritDoc} */ @Override @Nonnull @NotEmpty public String serialize(@Nonnull final Principal principal) throws IOException { if (sealer == null) { throw new IOException("No DataSealer was provided, unable to support PasswordPrincipal serialization"); } final StringWriter sink = new StringWriter(32); final JsonGenerator gen = getJsonGenerator(sink); try { gen.writeStartObject() .write(PASSWORD_FIELD, sealer.wrap(principal.getName(), System.currentTimeMillis() + DOMTypeSupport.durationToLong("P1Y"))) .writeEnd(); } catch (final DataSealerException e) { throw new IOException(e); } gen.close(); return sink.toString(); }