protected void addLifetime(XMLStreamWriter writer) throws XMLStreamException { Instant created = Instant.now(); Instant expires = created.plusSeconds(ttl); writer.writeStartElement("wst", "Lifetime", namespace); writer.writeNamespace("wsu", WSS4JConstants.WSU_NS); writer.writeStartElement("wsu", "Created", WSS4JConstants.WSU_NS); writer.writeCharacters(created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeStartElement("wsu", "Expires", WSS4JConstants.WSU_NS); writer.writeCharacters(expires.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeEndElement(); }
/** * Return true if the "Created" value is before the current time minus the timeToLive * argument, and if the Created value is not "in the future". * * @param timeToLive the value in seconds for the validity of the Created time * @param futureTimeToLive the value in seconds for the future validity of the Created time * @return true if the UsernameToken is before (now-timeToLive), false otherwise */ public boolean verifyCreated( int timeToLive, int futureTimeToLive ) { return DateUtil.verifyCreated(created, timeToLive, futureTimeToLive); }
protected void addLifetime(XMLStreamWriter writer) throws XMLStreamException { Instant created = Instant.now(); Instant expires = created.plusSeconds(ttl); writer.writeStartElement("wst", "Lifetime", namespace); writer.writeNamespace("wsu", WSS4JConstants.WSU_NS); writer.writeStartElement("wsu", "Created", WSS4JConstants.WSU_NS); writer.writeCharacters(created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeStartElement("wsu", "Expires", WSS4JConstants.WSU_NS); writer.writeCharacters(expires.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeEndElement(); }
/** * Return true if the "Created" value is before the current time minus the timeToLive * argument, and if the Created value is not "in the future". * * @param timeToLive the value in seconds for the validity of the Created time * @param futureTimeToLive the value in seconds for the future validity of the Created time * @return true if the timestamp is before (now-timeToLive), false otherwise */ public boolean verifyCreated( int timeToLive, int futureTimeToLive ) { return DateUtil.verifyCreated(created, timeToLive, futureTimeToLive); }
/** * Creates and adds a Created element to this UsernameToken */ public void addCreated(boolean milliseconds, WSTimeSource timeSource, Document doc) { if (elementCreated != null) { return; } elementCreated = doc.createElementNS( WSConstants.WSU_NS, WSConstants.WSU_PREFIX + ":" + WSConstants.CREATED_LN ); Instant currentTime = timeSource.now(); DateTimeFormatter formatter = DateUtil.getDateTimeFormatter(milliseconds); elementCreated.appendChild(doc.createTextNode(currentTime.atZone(ZoneOffset.UTC).format(formatter))); element.appendChild(elementCreated); }
private Instant verifyCreated( WSSSecurityProperties wssSecurityProperties, UsernameTokenType usernameTokenType ) throws WSSecurityException { // Verify Created int ttl = wssSecurityProperties.getUtTTL(); int futureTTL = wssSecurityProperties.getUtFutureTTL(); final AttributedDateTime attributedDateTimeCreated = XMLSecurityUtils.getQNameType(usernameTokenType.getAny(), WSSConstants.TAG_WSU_CREATED); if (attributedDateTimeCreated != null) { // Parse the Date ZonedDateTime created; try { created = ZonedDateTime.parse(attributedDateTimeCreated.getValue()); } catch (DateTimeParseException e) { throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e); } // Validate whether the security semantics have expired if (!DateUtil.verifyCreated(created.toInstant(), ttl, futureTTL)) { throw new WSSecurityException(WSSecurityException.ErrorCode.MESSAGE_EXPIRED); } return created.toInstant(); } return null; } }
created = timeSource.now(); DateTimeFormatter formatter = DateUtil.getDateTimeFormatter(milliseconds); elementCreated.appendChild(doc.createTextNode(created.atZone(ZoneOffset.UTC).format(formatter)));
if (createdDate != null && !DateUtil.verifyCreated(createdDate.toInstant(), ttl, futureTTL)) { LOG.debug("Time now: {}", rightNow.toString()); throw new WSSecurityException(WSSecurityException.ErrorCode.MESSAGE_EXPIRED, "invalidTimestamp",
void writeLifetime( W3CDOMStreamWriter writer, Instant created, Instant expires, String prefix, String namespace ) throws Exception { writer.writeStartElement(prefix, "Lifetime", namespace); writer.writeNamespace("wsu", WSS4JConstants.WSU_NS); writer.writeStartElement("wsu", "Created", WSS4JConstants.WSU_NS); writer.writeCharacters(created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeStartElement("wsu", "Expires", WSS4JConstants.WSU_NS); writer.writeCharacters(expires.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeEndElement(); }
void writeLifetime( W3CDOMStreamWriter writer, Instant created, Instant expires, String prefix, String namespace ) throws Exception { writer.writeStartElement(prefix, "Lifetime", namespace); writer.writeNamespace("wsu", WSS4JConstants.WSU_NS); writer.writeStartElement("wsu", "Created", WSS4JConstants.WSU_NS); writer.writeCharacters(created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeStartElement("wsu", "Expires", WSS4JConstants.WSU_NS); writer.writeCharacters(expires.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); writer.writeEndElement(); writer.writeEndElement(); }
/** * Create a LifetimeType object given a created + expires Dates */ protected static LifetimeType createLifetime( Instant tokenCreated, Instant tokenExpires ) { AttributedDateTime created = QNameConstants.UTIL_FACTORY.createAttributedDateTime(); AttributedDateTime expires = QNameConstants.UTIL_FACTORY.createAttributedDateTime(); Instant now = Instant.now(); Instant creationTime = tokenCreated; if (tokenCreated == null) { creationTime = now; } Instant expirationTime = tokenExpires; if (tokenExpires == null) { long lifeTimeOfToken = 300L; expirationTime = now.plusSeconds(lifeTimeOfToken); } created.setValue(creationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); expires.setValue(expirationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Token lifetime creation: " + created.getValue()); LOG.fine("Token lifetime expiration: " + expires.getValue()); } LifetimeType lifetimeType = QNameConstants.WS_TRUST_FACTORY.createLifetimeType(); lifetimeType.setCreated(created); lifetimeType.setExpires(expires); return lifetimeType; }
/** * Create a LifetimeType object given a created + expires Dates */ protected static LifetimeType createLifetime( Instant tokenCreated, Instant tokenExpires ) { AttributedDateTime created = QNameConstants.UTIL_FACTORY.createAttributedDateTime(); AttributedDateTime expires = QNameConstants.UTIL_FACTORY.createAttributedDateTime(); Instant now = Instant.now(); Instant creationTime = tokenCreated; if (tokenCreated == null) { creationTime = now; } Instant expirationTime = tokenExpires; if (tokenExpires == null) { long lifeTimeOfToken = 300L; expirationTime = now.plusSeconds(lifeTimeOfToken); } created.setValue(creationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); expires.setValue(expirationTime.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true))); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Token lifetime creation: " + created.getValue()); LOG.fine("Token lifetime expiration: " + expires.getValue()); } LifetimeType lifetimeType = QNameConstants.WS_TRUST_FACTORY.createLifetimeType(); lifetimeType.setCreated(created); lifetimeType.setExpires(expires); return lifetimeType; }
@Override public void modifySecurityHeader(Element securityHeader) { if (securityHeader != null) { // Find the Timestamp + change it. Element timestampElement = XMLUtils.findElement(securityHeader, "Timestamp", WSS4JConstants.WSU_NS); Element createdValue = XMLUtils.findElement(timestampElement, "Created", WSS4JConstants.WSU_NS); ZonedDateTime created = ZonedDateTime.parse(createdValue.getTextContent()); // Add 5 seconds createdValue.setTextContent(DateUtil.getDateTimeFormatter(true).format(created.plusSeconds(5L))); } }
DateTimeFormatter formatter = DateUtil.getDateTimeFormatter(true); createCharactersAndOutputAsEvent(subOutputProcessorChain, created.atZone(ZoneOffset.UTC).format(formatter)); createEndElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_CREATED);
|| ((WSSSecurityProperties) getSecurityProperties()).isAddUsernameTokenCreated()) { Instant created = Instant.now(); createdStr = created.atZone(ZoneOffset.UTC).format(DateUtil.getDateTimeFormatter(true));