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(); }
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(); }
/** * 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); }
created = timeSource.now(); DateTimeFormatter formatter = DateUtil.getDateTimeFormatter(milliseconds); elementCreated.appendChild(doc.createTextNode(created.atZone(ZoneOffset.UTC).format(formatter)));
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));