You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2017/03/13 11:45:20 UTC

svn commit: r1786661 - in /webservices/wss4j/trunk: bindings/src/main/java/org/apache/wss4j/binding/wsu10/ ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/ ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/ ws-s...

Author: coheigea
Date: Mon Mar 13 11:45:20 2017
New Revision: 1786661

URL: http://svn.apache.org/viewvc?rev=1786661&view=rev
Log:
WSS-599 - Removing all GregorianCalendar instances

Modified:
    webservices/wss4j/trunk/bindings/src/main/java/org/apache/wss4j/binding/wsu10/AbstractAttributedDateTime.java
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/Timestamp.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/TimestampInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/TimestampOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/UsernameTokenOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/securityEvent/TimestampSecurityEvent.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java

Modified: webservices/wss4j/trunk/bindings/src/main/java/org/apache/wss4j/binding/wsu10/AbstractAttributedDateTime.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/bindings/src/main/java/org/apache/wss4j/binding/wsu10/AbstractAttributedDateTime.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/bindings/src/main/java/org/apache/wss4j/binding/wsu10/AbstractAttributedDateTime.java (original)
+++ webservices/wss4j/trunk/bindings/src/main/java/org/apache/wss4j/binding/wsu10/AbstractAttributedDateTime.java Mon Mar 13 11:45:20 2017
@@ -18,33 +18,23 @@
  */
 package org.apache.wss4j.binding.wsu10;
 
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeParseException;
+
 import javax.xml.bind.annotation.XmlTransient;
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-import javax.xml.datatype.XMLGregorianCalendar;
 
 @XmlTransient
 public abstract class AbstractAttributedDateTime {
 
-    private static final DatatypeFactory datatypeFactory;
-
-    static {
-        try {
-            datatypeFactory = DatatypeFactory.newInstance();
-        } catch (DatatypeConfigurationException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     @XmlTransient
-    private XMLGregorianCalendar xmlGregorianCalendar;
+    private ZonedDateTime zonedDateTime;
 
     public abstract String getValue();
 
-    public XMLGregorianCalendar getAsXMLGregorianCalendar() throws IllegalArgumentException {
-        if (xmlGregorianCalendar == null && getValue() != null) {
-            xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(getValue());
+    public ZonedDateTime getAsZonedDateTime() throws DateTimeParseException {
+        if (zonedDateTime == null && getValue() != null) {
+            zonedDateTime = ZonedDateTime.parse(getValue());
         }
-        return xmlGregorianCalendar;
+        return zonedDateTime;
     }
 }

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/Timestamp.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/Timestamp.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/Timestamp.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/Timestamp.java Mon Mar 13 11:45:20 2017
@@ -23,9 +23,7 @@ import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
-
-import javax.xml.datatype.DatatypeConstants;
-import javax.xml.datatype.XMLGregorianCalendar;
+import java.time.temporal.ChronoField;
 
 import org.apache.wss4j.common.bsp.BSPEnforcer;
 import org.apache.wss4j.common.bsp.BSPRule;
@@ -36,7 +34,6 @@ import org.apache.wss4j.common.util.WSCu
 import org.apache.wss4j.common.util.WSTimeSource;
 import org.apache.wss4j.common.util.XMLUtils;
 import org.apache.wss4j.dom.WSConstants;
-import org.apache.wss4j.dom.engine.WSSConfig;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -116,54 +113,40 @@ public class Timestamp {
 
         // Parse the dates
         if (createdString != null) {
-            XMLGregorianCalendar createdCalendar = null;
             try {
-                createdCalendar =
-                    WSSConfig.DATATYPE_FACTORY.newXMLGregorianCalendar(createdString);
-            } catch (IllegalArgumentException e) {
+                createdDate = ZonedDateTime.parse(createdString);
+            } catch (DateTimeParseException e) {
                 throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
             }
-
-            if (createdCalendar.getFractionalSecond() != null
-                && createdCalendar.getFractionalSecond().scale() > 3) {
-                bspEnforcer.handleBSPRule(BSPRule.R3220);
-            }
-            if (createdCalendar.getSecond() > 59) {
-                bspEnforcer.handleBSPRule(BSPRule.R3213);
-            }
-            if (createdCalendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
+            
+            if (!ZoneOffset.UTC.equals(createdDate.getZone())) {
                 bspEnforcer.handleBSPRule(BSPRule.R3217);
             }
-            try {
-                createdDate = ZonedDateTime.parse(createdString);
-            } catch (DateTimeParseException e) {
-                throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
+            
+            if (createdDate.getNano() > 0) {
+                int milliseconds = createdDate.get(ChronoField.MILLI_OF_SECOND);
+                if (milliseconds * 1000000 != createdDate.getNano()) {
+                    bspEnforcer.handleBSPRule(BSPRule.R3220);
+                }
             }
         }
 
         if (strExpires != null) {
-            XMLGregorianCalendar expiresCalendar = null;
             try {
-                expiresCalendar =
-                    WSSConfig.DATATYPE_FACTORY.newXMLGregorianCalendar(strExpires);
-            } catch (IllegalArgumentException e) {
+                expiresDate = ZonedDateTime.parse(strExpires);
+            } catch (DateTimeParseException e) {
                 throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
             }
-
-            if (expiresCalendar.getFractionalSecond() != null
-                && expiresCalendar.getFractionalSecond().scale() > 3) {
-                bspEnforcer.handleBSPRule(BSPRule.R3229);
-            }
-            if (expiresCalendar.getSecond() > 59) {
-                bspEnforcer.handleBSPRule(BSPRule.R3215);
-            }
-            if (expiresCalendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
+            
+            if (!ZoneOffset.UTC.equals(expiresDate.getZone())) {
                 bspEnforcer.handleBSPRule(BSPRule.R3223);
             }
-            try {
-                expiresDate = ZonedDateTime.parse(strExpires);
-            } catch (DateTimeParseException e) {
-                throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
+            
+            if (expiresDate.getNano() > 0) {
+                int milliseconds = expiresDate.get(ChronoField.MILLI_OF_SECOND);
+                if (milliseconds * 1000000 != expiresDate.getNano()) {
+                    bspEnforcer.handleBSPRule(BSPRule.R3229);
+                }
             }
         }
     }
@@ -205,7 +188,7 @@ public class Timestamp {
 
         element.appendChild(elementCreated);
         if (ttl != 0) {
-            expiresDate = timeSource.now().atZone(ZoneOffset.UTC).plusSeconds((long)ttl);
+            expiresDate = createdDate.plusSeconds((long)ttl);
 
             Element elementExpires =
                 doc.createElementNS(

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/TimestampInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/TimestampInputHandler.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/TimestampInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/TimestampInputHandler.java Mon Mar 13 11:45:20 2017
@@ -37,11 +37,13 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.impl.util.IDGenerator;
 
 import javax.xml.bind.JAXBElement;
-import javax.xml.datatype.DatatypeConstants;
-import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamConstants;
 
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeParseException;
+import java.time.temporal.ChronoField;
 import java.util.Deque;
 import java.util.List;
 
@@ -87,7 +89,7 @@ public class TimestampInputHandler exten
         if (timestampType.getCreated() != null) {
             try {
                 timestampSecurityEvent.setCreated(
-                        timestampType.getCreated().getAsXMLGregorianCalendar().toGregorianCalendar());
+                        timestampType.getCreated().getAsZonedDateTime());
             } catch (IllegalArgumentException e) { //NOPMD
                 //ignore
             }
@@ -95,7 +97,7 @@ public class TimestampInputHandler exten
         if (timestampType.getExpires() != null) {
             try {
                 timestampSecurityEvent.setExpires(
-                        timestampType.getExpires().getAsXMLGregorianCalendar().toGregorianCalendar());
+                        timestampType.getExpires().getAsZonedDateTime());
             } catch (IllegalArgumentException e) { //NOPMD
                 //ignore
             }
@@ -144,53 +146,57 @@ public class TimestampInputHandler exten
         }
 
         if (timestampType.getCreated() != null) {
-            XMLGregorianCalendar createdCalendar;
+            ZonedDateTime createdDate;
             try {
-                createdCalendar = timestampType.getCreated().getAsXMLGregorianCalendar();
-            } catch (IllegalArgumentException e) {
+                createdDate = timestampType.getCreated().getAsZonedDateTime();
+            } catch (DateTimeParseException e) {
                 throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
             }
-            if (createdCalendar.getFractionalSecond() != null
-                && createdCalendar.getFractionalSecond().scale() > 3) {
-                securityContext.handleBSPRule(BSPRule.R3220);
+            
+            if (!ZoneOffset.UTC.equals(createdDate.getZone())) {
+                securityContext.handleBSPRule(BSPRule.R3217);
             }
-            if (createdCalendar.getSecond() > 59) {
-                securityContext.handleBSPRule(BSPRule.R3213);
+            
+            if (createdDate.getNano() > 0) {
+                int milliseconds = createdDate.get(ChronoField.MILLI_OF_SECOND);
+                if (milliseconds * 1000000 != createdDate.getNano()) {
+                    securityContext.handleBSPRule(BSPRule.R3220);
+                }
             }
+            
             String valueType = XMLSecurityUtils.getQNameAttribute(timestampType.getCreated().getOtherAttributes(),
                                                                   WSSConstants.ATT_NULL_VALUE_TYPE);
             if (valueType != null) {
                 securityContext.handleBSPRule(BSPRule.R3225);
             }
-            if (createdCalendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
-                securityContext.handleBSPRule(BSPRule.R3217);
-            }
         } else {
             securityContext.handleBSPRule(BSPRule.R3203);
         }
 
         if (timestampType.getExpires() != null) {
-            XMLGregorianCalendar expiresCalendar;
+            ZonedDateTime expiresDate;
             try {
-                expiresCalendar = timestampType.getExpires().getAsXMLGregorianCalendar();
-            } catch (IllegalArgumentException e) {
+                expiresDate = timestampType.getExpires().getAsZonedDateTime();
+            } catch (DateTimeParseException e) {
                 throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, e);
             }
-            if (expiresCalendar.getFractionalSecond() != null
-                && expiresCalendar.getFractionalSecond().scale() > 3) {
-                securityContext.handleBSPRule(BSPRule.R3229);
+            
+            if (!ZoneOffset.UTC.equals(expiresDate.getZone())) {
+                securityContext.handleBSPRule(BSPRule.R3223);
             }
-            if (expiresCalendar.getSecond() > 59) {
-                securityContext.handleBSPRule(BSPRule.R3215);
+            
+            if (expiresDate.getNano() > 0) {
+                int milliseconds = expiresDate.get(ChronoField.MILLI_OF_SECOND);
+                if (milliseconds * 1000000 != expiresDate.getNano()) {
+                    securityContext.handleBSPRule(BSPRule.R3229);
+                }
             }
+            
             String valueType = XMLSecurityUtils.getQNameAttribute(timestampType.getExpires().getOtherAttributes(),
                                                                   WSSConstants.ATT_NULL_VALUE_TYPE);
             if (valueType != null) {
                 securityContext.handleBSPRule(BSPRule.R3226);
             }
-            if (expiresCalendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
-                securityContext.handleBSPRule(BSPRule.R3223);
-            }
         }
     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java Mon Mar 13 11:45:20 2017
@@ -22,9 +22,11 @@ import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.time.Duration;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.temporal.ChronoField;
 import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -313,19 +315,17 @@ public class WSSSignatureReferenceVerify
             ((WSSSecurityProperties)getSecurityProperties()).getTimestampReplayCache();
         if (timestampSecurityEvent != null && replayCache != null) {
             final String cacheKey =
-                    timestampSecurityEvent.getCreated().getTimeInMillis()
+                    timestampSecurityEvent.getCreated().get(ChronoField.MILLI_OF_SECOND)
                     + "" + Arrays.hashCode(getSignatureType().getSignatureValue().getValue());
             if (replayCache.contains(cacheKey)) {
                 throw new WSSecurityException(WSSecurityException.ErrorCode.MESSAGE_EXPIRED);
             }
 
             // Store the Timestamp/SignatureValue combination in the cache
-            Calendar expiresCal = timestampSecurityEvent.getExpires();
-            if (expiresCal != null) {
-                Date rightNow = new Date();
-                long currentTime = rightNow.getTime();
-                long expiresTime = expiresCal.getTimeInMillis();
-                replayCache.add(cacheKey, 1L + (expiresTime - currentTime) / 1000L);
+            ZonedDateTime expires = timestampSecurityEvent.getExpires();
+            if (expires != null) {
+                ZonedDateTime currentTime = ZonedDateTime.now(ZoneOffset.UTC);
+                replayCache.add(cacheKey, 1L + Duration.between(currentTime, expires).getSeconds());
             } else {
                 replayCache.add(cacheKey);
             }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/TimestampOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/TimestampOutputProcessor.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/TimestampOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/TimestampOutputProcessor.java Mon Mar 13 11:45:20 2017
@@ -18,14 +18,13 @@
  */
 package org.apache.wss4j.stax.impl.processor.output;
 
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 
-import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
+import org.apache.wss4j.common.util.DateUtil;
 import org.apache.wss4j.stax.ext.WSSConstants;
 import org.apache.wss4j.stax.ext.WSSSecurityProperties;
 import org.apache.wss4j.stax.utils.WSSUtils;
@@ -66,21 +65,19 @@ public class TimestampOutputProcessor ex
             final QName headerElementName = WSSConstants.TAG_WSU_TIMESTAMP;
             OutputProcessorUtils.updateSecurityHeaderOrder(outputProcessorChain, headerElementName, getAction(), false);
 
-            XMLGregorianCalendar created =
-                WSSConstants.datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar(TimeZone.getTimeZone("UTC")));
+            ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC);
 
-            GregorianCalendar expiresCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
-            expiresCalendar.add(Calendar.SECOND, ((WSSSecurityProperties) getSecurityProperties()).getTimestampTTL());
-            XMLGregorianCalendar expires = WSSConstants.datatypeFactory.newXMLGregorianCalendar(expiresCalendar);
+            int ttl = ((WSSSecurityProperties) getSecurityProperties()).getTimestampTTL();
+            ZonedDateTime expires = created.plusSeconds(ttl);
 
             OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this);
             //wsu:id is optional and will be added when signing...
             createStartElementAndOutputAsEvent(subOutputProcessorChain, headerElementName, true, null);
             createStartElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_CREATED, false, null);
-            createCharactersAndOutputAsEvent(subOutputProcessorChain, created.toXMLFormat());
+            createCharactersAndOutputAsEvent(subOutputProcessorChain, DateUtil.getDateTimeFormatter(true).format(created));
             createEndElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_CREATED);
             createStartElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_EXPIRES, false, null);
-            createCharactersAndOutputAsEvent(subOutputProcessorChain, expires.toXMLFormat());
+            createCharactersAndOutputAsEvent(subOutputProcessorChain, DateUtil.getDateTimeFormatter(true).format(expires));
             createEndElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_EXPIRES);
             createEndElementAndOutputAsEvent(subOutputProcessorChain, headerElementName);
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/UsernameTokenOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/UsernameTokenOutputProcessor.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/UsernameTokenOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/processor/output/UsernameTokenOutputProcessor.java Mon Mar 13 11:45:20 2017
@@ -21,6 +21,7 @@ package org.apache.wss4j.stax.impl.proce
 import org.apache.commons.codec.binary.Base64;
 import org.apache.wss4j.common.ext.WSPasswordCallback;
 import org.apache.wss4j.common.ext.WSSecurityException;
+import org.apache.wss4j.common.util.DateUtil;
 import org.apache.wss4j.common.util.UsernameTokenUtil;
 import org.apache.wss4j.stax.ext.WSSConstants;
 import org.apache.wss4j.stax.ext.WSSSecurityProperties;
@@ -35,14 +36,13 @@ import org.apache.xml.security.stax.secu
 import org.apache.xml.security.stax.securityToken.SecurityTokenProvider;
 
 import javax.security.auth.callback.CallbackHandler;
-import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.ArrayList;
-import java.util.GregorianCalendar;
 import java.util.List;
-import java.util.TimeZone;
 
 public class UsernameTokenOutputProcessor extends AbstractOutputProcessor {
 
@@ -97,12 +97,11 @@ public class UsernameTokenOutputProcesso
                 nonceValue = WSSConstants.generateBytes(16);
             }
 
-            XMLGregorianCalendar created = null;
             String createdStr = "";
             if (usernameTokenPasswordType == WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST
                 || ((WSSSecurityProperties) getSecurityProperties()).isAddUsernameTokenCreated()) {
-                created = WSSConstants.datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar(TimeZone.getTimeZone("UTC")));
-                createdStr = created.toXMLFormat();
+                ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC);
+                createdStr = DateUtil.getDateTimeFormatter(true).format(created);
             }
 
             final OutputProcessor outputProcessor = this;
@@ -136,7 +135,7 @@ public class UsernameTokenOutputProcesso
                 outputProcessorChain.getSecurityContext().put(WSSConstants.PROP_USE_THIS_TOKEN_ID_FOR_SIGNATURE, wsuId);
             }
             final FinalUsernameTokenOutputProcessor finalUsernameTokenOutputProcessor =
-                new FinalUsernameTokenOutputProcessor(wsuId, nonceValue, password, created, salt, derivedIterations, getAction());
+                new FinalUsernameTokenOutputProcessor(wsuId, nonceValue, password, createdStr, salt, derivedIterations, getAction());
             finalUsernameTokenOutputProcessor.setXMLSecurityProperties(getSecurityProperties());
             finalUsernameTokenOutputProcessor.setAction(getAction());
             finalUsernameTokenOutputProcessor.init(outputProcessorChain);
@@ -152,13 +151,13 @@ public class UsernameTokenOutputProcesso
         private String wsuId;
         private byte[] nonceValue;
         private String password;
-        private XMLGregorianCalendar created;
+        private String created;
         private byte[] salt;
         private int iterations;
         private XMLSecurityConstants.Action action;
 
         FinalUsernameTokenOutputProcessor(String wsuId, byte[] nonceValue, String password,
-                                          XMLGregorianCalendar created, byte[] salt,
+                                          String created, byte[] salt,
                                           int iterations, XMLSecurityConstants.Action action)
                 throws XMLSecurityException {
             super();
@@ -205,7 +204,7 @@ public class UsernameTokenOutputProcesso
                     createCharactersAndOutputAsEvent(subOutputProcessorChain,
                             ((WSSSecurityProperties) getSecurityProperties()).getUsernameTokenPasswordType()
                                 == WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST
-                                    ? WSSUtils.doPasswordDigest(this.nonceValue, this.created.toXMLFormat(), this.password)
+                                    ? WSSUtils.doPasswordDigest(this.nonceValue, created, this.password)
                                     : this.password);
                     createEndElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSSE_PASSWORD);
                 }
@@ -231,9 +230,9 @@ public class UsernameTokenOutputProcesso
                     createEndElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSSE_NONCE);
                 }
 
-                if (created != null && !WSSConstants.USERNAMETOKEN_SIGNED.equals(action)) {
+                if (!"".equals(created)) {
                     createStartElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_CREATED, false, null);
-                    createCharactersAndOutputAsEvent(subOutputProcessorChain, this.created.toXMLFormat());
+                    createCharactersAndOutputAsEvent(subOutputProcessorChain, created);
                     createEndElementAndOutputAsEvent(subOutputProcessorChain, WSSConstants.TAG_WSU_CREATED);
                 }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/securityEvent/TimestampSecurityEvent.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/securityEvent/TimestampSecurityEvent.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/securityEvent/TimestampSecurityEvent.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/securityEvent/TimestampSecurityEvent.java Mon Mar 13 11:45:20 2017
@@ -18,32 +18,32 @@
  */
 package org.apache.wss4j.stax.securityEvent;
 
-import java.util.Calendar;
+import java.time.ZonedDateTime;
 
 import org.apache.xml.security.stax.securityEvent.SecurityEvent;
 
 public class TimestampSecurityEvent extends SecurityEvent {
 
-    private Calendar created;
-    private Calendar expires;
+    private ZonedDateTime created;
+    private ZonedDateTime expires;
 
     public TimestampSecurityEvent() {
         super(WSSecurityEventConstants.TIMESTAMP);
     }
 
-    public Calendar getCreated() {
+    public ZonedDateTime getCreated() {
         return created;
     }
 
-    public void setCreated(Calendar created) {
+    public void setCreated(ZonedDateTime created) {
         this.created = created;
     }
 
-    public Calendar getExpires() {
+    public ZonedDateTime getExpires() {
         return expires;
     }
 
-    public void setExpires(Calendar expires) {
+    public void setExpires(ZonedDateTime expires) {
         this.expires = expires;
     }
 }

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java Mon Mar 13 11:45:20 2017
@@ -22,16 +22,14 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
-import javax.xml.datatype.DatatypeFactory;
-import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
@@ -41,6 +39,7 @@ import javax.xml.transform.stream.Stream
 import org.apache.wss4j.common.ConfigurationConstants;
 import org.apache.wss4j.common.bsp.BSPRule;
 import org.apache.wss4j.common.ext.WSSecurityException;
+import org.apache.wss4j.common.util.DateUtil;
 import org.apache.wss4j.dom.handler.WSHandlerConstants;
 import org.apache.wss4j.stax.ext.WSSConstants;
 import org.apache.wss4j.stax.ext.WSSSecurityProperties;
@@ -84,17 +83,14 @@ public class TimestampTest extends Abstr
             Element created = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_CREATED.getNamespaceURI(), WSSConstants.TAG_WSU_CREATED.getLocalPart()).item(0);
             Element expires = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_EXPIRES.getNamespaceURI(), WSSConstants.TAG_WSU_EXPIRES.getLocalPart()).item(0);
 
-            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
-            GregorianCalendar gregorianCalendarCreated = datatypeFactory.newXMLGregorianCalendar(created.getTextContent()).toGregorianCalendar();
-            GregorianCalendar gregorianCalendarExpires = datatypeFactory.newXMLGregorianCalendar(expires.getTextContent()).toGregorianCalendar();
-
-            Assert.assertTrue(gregorianCalendarCreated.before(gregorianCalendarExpires));
-            GregorianCalendar now = new GregorianCalendar();
-            Assert.assertFalse(now.before(gregorianCalendarCreated));
-            Assert.assertTrue(now.before(gregorianCalendarExpires));
+            ZonedDateTime createdDateTime = ZonedDateTime.parse(created.getTextContent());
+            ZonedDateTime expiresDateTime = ZonedDateTime.parse(expires.getTextContent());
 
-            gregorianCalendarCreated.add(Calendar.SECOND, 301);
-            Assert.assertTrue(gregorianCalendarCreated.after(gregorianCalendarExpires));
+            ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+            Assert.assertFalse(now.isBefore(createdDateTime));
+            Assert.assertTrue(now.isBefore(expiresDateTime));
+
+            Assert.assertTrue(createdDateTime.plusSeconds(301L).isAfter(expiresDateTime));
         }
 
         //done timestamp; now test timestamp verification:
@@ -161,17 +157,16 @@ public class TimestampTest extends Abstr
             Element created = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_CREATED.getNamespaceURI(), WSSConstants.TAG_WSU_CREATED.getLocalPart()).item(0);
             Element expires = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_EXPIRES.getNamespaceURI(), WSSConstants.TAG_WSU_EXPIRES.getLocalPart()).item(0);
 
-            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
-            GregorianCalendar gregorianCalendarCreated = datatypeFactory.newXMLGregorianCalendar(created.getTextContent()).toGregorianCalendar();
-            GregorianCalendar gregorianCalendarExpires = datatypeFactory.newXMLGregorianCalendar(expires.getTextContent()).toGregorianCalendar();
-
-            Assert.assertTrue(gregorianCalendarCreated.before(gregorianCalendarExpires));
-            GregorianCalendar now = new GregorianCalendar();
-            Assert.assertFalse(now.before(gregorianCalendarCreated));
-            Assert.assertTrue(now.before(gregorianCalendarExpires));
+            ZonedDateTime createdDateTime = ZonedDateTime.parse(created.getTextContent());
+            ZonedDateTime expiresDateTime = ZonedDateTime.parse(expires.getTextContent());
+            
+            Assert.assertTrue(createdDateTime.isBefore(expiresDateTime));
+            
+            ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+            Assert.assertFalse(now.isBefore(createdDateTime));
+            Assert.assertTrue(now.isBefore(expiresDateTime));
 
-            gregorianCalendarCreated.add(Calendar.SECOND, 3601);
-            Assert.assertTrue(gregorianCalendarCreated.after(gregorianCalendarExpires));
+            Assert.assertTrue(createdDateTime.plusSeconds(3601L).isAfter(expiresDateTime));
         }
 
         //done timestamp; now test timestamp verification:
@@ -278,17 +273,11 @@ public class TimestampTest extends Abstr
             Element created = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_CREATED.getNamespaceURI(), WSSConstants.TAG_WSU_CREATED.getLocalPart()).item(0);
             Element expires = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_EXPIRES.getNamespaceURI(), WSSConstants.TAG_WSU_EXPIRES.getLocalPart()).item(0);
 
-            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
-            GregorianCalendar gregorianCalendarCreated = new GregorianCalendar();
-            gregorianCalendarCreated.add(Calendar.SECOND, 40);
-            XMLGregorianCalendar xmlGregorianCalendarCreated = datatypeFactory.newXMLGregorianCalendar(gregorianCalendarCreated);
-            created.setTextContent(xmlGregorianCalendarCreated.toXMLFormat());
-
-            GregorianCalendar gregorianCalendarExpires = new GregorianCalendar();
-            gregorianCalendarExpires.add(Calendar.SECOND, 300);
-            XMLGregorianCalendar xmlGregorianCalendarExpires = datatypeFactory.newXMLGregorianCalendar(gregorianCalendarExpires);
+            ZonedDateTime createdDateTime = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(40L);
+            created.setTextContent(DateUtil.getDateTimeFormatter(true).format(createdDateTime));
 
-            expires.setTextContent(xmlGregorianCalendarExpires.toXMLFormat());
+            ZonedDateTime expiresDateTime = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(300L);
+            expires.setTextContent(DateUtil.getDateTimeFormatter(true).format(expiresDateTime));
 
             javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
             transformer.transform(new DOMSource(securedDocument), new StreamResult(baos));
@@ -322,19 +311,12 @@ public class TimestampTest extends Abstr
             Element created = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_CREATED.getNamespaceURI(), WSSConstants.TAG_WSU_CREATED.getLocalPart()).item(0);
             Element expires = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_EXPIRES.getNamespaceURI(), WSSConstants.TAG_WSU_EXPIRES.getLocalPart()).item(0);
 
-            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
-            GregorianCalendar gregorianCalendarCreated = new GregorianCalendar();
-            gregorianCalendarCreated.add(Calendar.HOUR, 2);
-            XMLGregorianCalendar xmlGregorianCalendarCreated = datatypeFactory.newXMLGregorianCalendar(gregorianCalendarCreated);
-            created.setTextContent(xmlGregorianCalendarCreated.toXMLFormat());
-
-            GregorianCalendar gregorianCalendarExpires = new GregorianCalendar();
-            gregorianCalendarExpires.add(Calendar.HOUR, 2);
-            gregorianCalendarExpires.add(Calendar.SECOND, 300);
-            XMLGregorianCalendar xmlGregorianCalendarExpires = datatypeFactory.newXMLGregorianCalendar(gregorianCalendarExpires);
-
-            expires.setTextContent(xmlGregorianCalendarExpires.toXMLFormat());
+            ZonedDateTime createdDateTime = ZonedDateTime.now(ZoneOffset.UTC).plusHours(2L);
+            created.setTextContent(DateUtil.getDateTimeFormatter(true).format(createdDateTime));
 
+            ZonedDateTime expiresDateTime = ZonedDateTime.now(ZoneOffset.UTC).plusHours(2L).plusSeconds(300L);
+            expires.setTextContent(DateUtil.getDateTimeFormatter(true).format(expiresDateTime));
+            
             javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
             transformer.transform(new DOMSource(securedDocument), new StreamResult(baos));
         }
@@ -685,17 +667,16 @@ public class TimestampTest extends Abstr
             Element created = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_CREATED.getNamespaceURI(), WSSConstants.TAG_WSU_CREATED.getLocalPart()).item(0);
             Element expires = (Element) ((Element) nodeList.item(0)).getElementsByTagNameNS(WSSConstants.TAG_WSU_EXPIRES.getNamespaceURI(), WSSConstants.TAG_WSU_EXPIRES.getLocalPart()).item(0);
 
-            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
-            GregorianCalendar gregorianCalendarCreated = datatypeFactory.newXMLGregorianCalendar(created.getTextContent()).toGregorianCalendar();
-            GregorianCalendar gregorianCalendarExpires = datatypeFactory.newXMLGregorianCalendar(expires.getTextContent()).toGregorianCalendar();
-
-            Assert.assertTrue(gregorianCalendarCreated.before(gregorianCalendarExpires));
-            GregorianCalendar now = new GregorianCalendar();
-            Assert.assertFalse(now.before(gregorianCalendarCreated));
-            Assert.assertTrue(now.before(gregorianCalendarExpires));
+            ZonedDateTime createdDateTime = ZonedDateTime.parse(created.getTextContent());
+            ZonedDateTime expiresDateTime = ZonedDateTime.parse(expires.getTextContent());
+            
+            Assert.assertTrue(createdDateTime.isBefore(expiresDateTime));
+            
+            ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+            Assert.assertFalse(now.isBefore(createdDateTime));
+            Assert.assertTrue(now.isBefore(expiresDateTime));
 
-            gregorianCalendarCreated.add(Calendar.SECOND, 301);
-            Assert.assertTrue(gregorianCalendarCreated.after(gregorianCalendarExpires));
+            Assert.assertTrue(createdDateTime.plusSeconds(301L).isAfter(expiresDateTime));
         }
 
         //done timestamp; now test timestamp verification:

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java?rev=1786661&r1=1786660&r2=1786661&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java Mon Mar 13 11:45:20 2017
@@ -22,16 +22,15 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Base64;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
-import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
@@ -42,6 +41,7 @@ import org.apache.wss4j.common.Configura
 import org.apache.wss4j.common.cache.ReplayCache;
 import org.apache.wss4j.common.cache.ReplayCacheFactory;
 import org.apache.wss4j.common.ext.WSSecurityException;
+import org.apache.wss4j.common.util.DateUtil;
 import org.apache.wss4j.dom.WSConstants;
 import org.apache.wss4j.dom.handler.WSHandlerConstants;
 import org.apache.wss4j.stax.ext.WSSConstants;
@@ -242,9 +242,8 @@ public class UsernameTokenTest extends A
     @Test
     public void testReusedNonce() throws Exception {
 
-        XMLGregorianCalendar created =
-            WSSConstants.datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar());
-        String createdString = created.toXMLFormat();
+        ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC);
+        String createdString = DateUtil.getDateTimeFormatter(true).format(created);
         String digest =
             org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
                 "Ex2YESUvsa1qne1m6TM8XA==", createdString, "default"
@@ -292,11 +291,8 @@ public class UsernameTokenTest extends A
     @Test
     public void testOldUsernameToken() throws Exception {
 
-        GregorianCalendar createdCalendar = new GregorianCalendar();
-        createdCalendar.add(Calendar.SECOND, -301);
-        XMLGregorianCalendar created =
-            WSSConstants.datatypeFactory.newXMLGregorianCalendar(createdCalendar);
-        String createdString = created.toXMLFormat();
+        ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(301L);
+        String createdString = DateUtil.getDateTimeFormatter(true).format(created);
 
         String digest =
             org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
@@ -339,11 +335,8 @@ public class UsernameTokenTest extends A
      */
     @Test
     public void testNearFutureCreated() throws Exception {
-        GregorianCalendar createdCalendar = new GregorianCalendar();
-        createdCalendar.add(Calendar.SECOND, 30);
-        XMLGregorianCalendar created =
-            WSSConstants.datatypeFactory.newXMLGregorianCalendar(createdCalendar);
-        String createdString = created.toXMLFormat();
+        ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(30L);
+        String createdString = DateUtil.getDateTimeFormatter(true).format(created);
 
         String digest =
             org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
@@ -379,11 +372,8 @@ public class UsernameTokenTest extends A
      */
     @Test
     public void testFutureCreated() throws Exception {
-        GregorianCalendar createdCalendar = new GregorianCalendar();
-        createdCalendar.add(Calendar.SECOND, 120);
-        XMLGregorianCalendar created =
-            WSSConstants.datatypeFactory.newXMLGregorianCalendar(createdCalendar);
-        String createdString = created.toXMLFormat();
+        ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(120L);
+        String createdString = DateUtil.getDateTimeFormatter(true).format(created);
 
         String digest =
             org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(