cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: Removing some Calendar instances
Date Wed, 15 Mar 2017 11:06:14 GMT
Repository: cxf
Updated Branches:
  refs/heads/master d6ceada3c -> c49f7a0be


Removing some Calendar instances


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c49f7a0b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c49f7a0b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c49f7a0b

Branch: refs/heads/master
Commit: c49f7a0be25d3f99a8fe81be6209139c3c0df562
Parents: d6ceada
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Mar 15 10:25:48 2017 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Mar 15 11:06:09 2017 +0000

----------------------------------------------------------------------
 .../cxf/rs/security/jose/jwt/JwtUtilsTest.java  | 33 ++++++-------
 .../cxf/transport/jms/BackChannelConduit.java   | 11 ++---
 .../cxf/xkms/x509/validator/DateValidator.java  |  7 +--
 .../security/jose/jwt/JWTPropertiesTest.java    | 52 ++++++++++----------
 .../security/oauth2/common/OAuth2TestUtils.java | 11 ++---
 .../grants/AuthorizationGrantNegativeTest.java  | 11 ++---
 .../security/oidc/IdTokenProviderImpl.java      | 11 ++---
 7 files changed, 62 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwt/JwtUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwt/JwtUtilsTest.java
b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwt/JwtUtilsTest.java
index deae65b..ca87e87 100644
--- a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwt/JwtUtilsTest.java
+++ b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwt/JwtUtilsTest.java
@@ -18,8 +18,8 @@
  */
 package org.apache.cxf.rs.security.jose.jwt;
 
-import java.util.Calendar;
-import java.util.Date;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 
 import org.junit.Assert;
 
@@ -36,9 +36,8 @@ public class JwtUtilsTest extends Assert {
         claims.setIssuer("DoubleItSTSIssuer");
 
         // Set the expiry date to be yesterday
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.DATE, -1);
-        claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC).minusDays(1L);
+        claims.setExpiryTime(dateTime.toEpochSecond());
 
         try {
             JwtUtils.validateJwtExpiry(claims, 0, true);
@@ -56,9 +55,8 @@ public class JwtUtilsTest extends Assert {
         claims.setIssuer("DoubleItSTSIssuer");
 
         // Set the issued date to be in the future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.DATE, 1);
-        claims.setIssuedAt(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC).plusDays(1L);
+        claims.setIssuedAt(dateTime.toEpochSecond());
 
         try {
             JwtUtils.validateJwtIssuedAt(claims, 300, 0, true);
@@ -76,9 +74,8 @@ public class JwtUtilsTest extends Assert {
         claims.setIssuer("DoubleItSTSIssuer");
 
         // Set the issued date to be in the near future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 30);
-        claims.setIssuedAt(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(30L);
+        claims.setIssuedAt(dateTime.toEpochSecond());
 
         try {
             JwtUtils.validateJwtIssuedAt(claims, 0, 0, true);
@@ -99,10 +96,9 @@ public class JwtUtilsTest extends Assert {
         claims.setIssuer("DoubleItSTSIssuer");
 
         // Set the issued date to be in the near future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 30);
-        claims.setIssuedAt(new Date().getTime() / 1000L);
-        claims.setNotBefore(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(dateTime.toEpochSecond());
+        claims.setNotBefore(dateTime.plusSeconds(30L).toEpochSecond());
 
         try {
             JwtUtils.validateJwtNotBefore(claims, 0, true);
@@ -123,15 +119,14 @@ public class JwtUtilsTest extends Assert {
         claims.setIssuer("DoubleItSTSIssuer");
 
         // Set the issued date to be now
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(dateTime.toEpochSecond());
 
         // Now test the TTL
         JwtUtils.validateJwtIssuedAt(claims, 60, 0, true);
 
         // Now create the token 70 seconds ago
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, -70);
-        claims.setIssuedAt(cal.getTimeInMillis() / 1000L);
+        claims.setIssuedAt(dateTime.minusSeconds(70L).toEpochSecond());
 
         try {
             JwtUtils.validateJwtIssuedAt(claims, 60, 0, true);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/BackChannelConduit.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/BackChannelConduit.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/BackChannelConduit.java
index be21327..a83984b 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/BackChannelConduit.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/BackChannelConduit.java
@@ -19,10 +19,8 @@
 package org.apache.cxf.transport.jms;
 
 import java.io.IOException;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.SimpleTimeZone;
-import java.util.TimeZone;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -185,9 +183,8 @@ class BackChannelConduit extends AbstractConduit implements JMSExchangeSender
{
 
     private boolean isTimedOut(final javax.jms.Message request) throws JMSException {
         if (request.getJMSExpiration() > 0) {
-            TimeZone tz = new SimpleTimeZone(0, "GMT");
-            Calendar cal = new GregorianCalendar(tz);
-            long timeToLive = request.getJMSExpiration() - cal.getTimeInMillis();
+            ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC);
+            long timeToLive = request.getJMSExpiration() - dateTime.toInstant().toEpochMilli();
             if (timeToLive < 0) {
                 getLogger()
                     .log(Level.INFO, "Message time to live is already expired skipping response.");

http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/validator/DateValidator.java
----------------------------------------------------------------------
diff --git a/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/validator/DateValidator.java
b/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/validator/DateValidator.java
index 1fd2ee1..c489dba 100644
--- a/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/validator/DateValidator.java
+++ b/services/xkms/xkms-x509-handlers/src/main/java/org/apache/cxf/xkms/x509/validator/DateValidator.java
@@ -22,7 +22,8 @@ package org.apache.cxf.xkms.x509.validator;
 import java.security.cert.CertificateExpiredException;
 import java.security.cert.CertificateNotYetValidException;
 import java.security.cert.X509Certificate;
-import java.util.Calendar;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.Date;
 import java.util.List;
 import java.util.logging.Logger;
@@ -45,10 +46,10 @@ public class DateValidator implements Validator {
      * @return the validity state of the certificate
      */
     public boolean isCertificateValid(X509Certificate certificate) {
-        Date date = Calendar.getInstance().getTime();
+        ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC);
 
         try {
-            certificate.checkValidity(date);
+            certificate.checkValidity(Date.from(dateTime.toInstant()));
         } catch (CertificateNotYetValidException e) {
             return false;
         } catch (CertificateExpiredException e) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java
b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java
index b5ff6b6..2c5cb5b 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jose/jwt/JWTPropertiesTest.java
@@ -21,10 +21,10 @@ package org.apache.cxf.systest.jaxrs.security.jose.jwt;
 
 import java.net.URL;
 import java.security.Security;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -85,13 +85,12 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         JwtClaims claims = new JwtClaims();
         claims.setSubject("alice");
         claims.setIssuer("DoubleItSTSIssuer");
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
         claims.setAudiences(toList(address));
 
         // Set the expiry date to be yesterday
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.DATE, -1);
-        claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
+        claims.setExpiryTime(now.minusDays(1L).toEpochSecond());
 
         JwtToken token = new JwtToken(claims);
 
@@ -125,9 +124,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         claims.setAudiences(toList(address));
 
         // Set the issued date to be in the future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.DATE, 1);
-        claims.setIssuedAt(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.plusDays(1L).toEpochSecond());
 
         JwtToken token = new JwtToken(claims);
 
@@ -161,9 +159,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         claims.setAudiences(toList(address));
 
         // Set the issued date to be in the near future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 30);
-        claims.setIssuedAt(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.plusSeconds(30L).toEpochSecond());
 
         JwtToken token = new JwtToken(claims);
 
@@ -197,9 +194,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         claims.setAudiences(toList(address));
 
         // Set the issued date to be in the near future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 30);
-        claims.setIssuedAt(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.plusSeconds(30L).toEpochSecond());
 
         JwtToken token = new JwtToken(claims);
 
@@ -233,10 +229,9 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         claims.setAudiences(toList(address));
 
         // Set the issued date to be in the near future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 30);
-        claims.setIssuedAt(new Date().getTime() / 1000L);
-        claims.setNotBefore(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
+        claims.setNotBefore(now.plusSeconds(30L).toEpochSecond());
 
         JwtToken token = new JwtToken(claims);
 
@@ -270,10 +265,9 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         claims.setAudiences(toList(address));
 
         // Set the issued date to be in the near future
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 30);
-        claims.setIssuedAt(new Date().getTime() / 1000L);
-        claims.setNotBefore(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
+        claims.setNotBefore(now.plusSeconds(30L).toEpochSecond());
 
         JwtToken token = new JwtToken(claims);
 
@@ -304,7 +298,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         JwtClaims claims = new JwtClaims();
         claims.setSubject("alice");
         claims.setIssuer("DoubleItSTSIssuer");
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
         claims.setAudiences(toList(address));
 
         Map<String, Object> properties = new HashMap<>();
@@ -334,7 +329,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         JwtClaims claims = new JwtClaims();
         claims.setSubject("alice");
         claims.setIssuer("DoubleItSTSIssuer");
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
         String badAddress = "https://localhost:" + PORT + "/badunsignedjwt/bookstore/books";
         claims.setAudiences(toList(badAddress));
 
@@ -365,7 +361,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         JwtClaims claims = new JwtClaims();
         claims.setSubject("alice");
         claims.setIssuer("DoubleItSTSIssuer");
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
 
         Map<String, Object> properties = new HashMap<>();
         properties.put("rs.security.signature.algorithm", "none");
@@ -394,7 +391,8 @@ public class JWTPropertiesTest extends AbstractBusClientServerTestBase
{
         JwtClaims claims = new JwtClaims();
         claims.setSubject("alice");
         claims.setIssuer("DoubleItSTSIssuer");
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
 
         String badAddress = "https://localhost:" + PORT + "/badunsignedjwt/bookstore/books";
         List<String> audiences = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuth2TestUtils.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuth2TestUtils.java
b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuth2TestUtils.java
index cca88d4..5405f47 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuth2TestUtils.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/common/OAuth2TestUtils.java
@@ -18,10 +18,10 @@
  */
 package org.apache.cxf.systest.jaxrs.security.oauth2.common;
 
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
 import java.util.Properties;
 
@@ -210,11 +210,10 @@ public final class OAuth2TestUtils {
         if (issuer != null) {
             claims.setIssuer(issuer);
         }
-        claims.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
         if (expiry) {
-            Calendar cal = Calendar.getInstance();
-            cal.add(Calendar.SECOND, 60);
-            claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
+            claims.setExpiryTime(now.plusSeconds(60L).toEpochSecond());
         }
         if (audience != null) {
             claims.setAudiences(Collections.singletonList(audience));

http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantNegativeTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantNegativeTest.java
b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantNegativeTest.java
index 3b5f689..fc4c398 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantNegativeTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantNegativeTest.java
@@ -20,9 +20,9 @@
 package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
 
 import java.net.URL;
-import java.util.Calendar;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.Collections;
-import java.util.Date;
 import java.util.Properties;
 
 import javax.ws.rs.client.ResponseProcessingException;
@@ -818,10 +818,9 @@ public class AuthorizationGrantNegativeTest extends AbstractBusClientServerTestB
         JwtClaims claims = new JwtClaims();
         claims.setSubject("consumer-id");
         claims.setIssuer("DoubleItSTSIssuer");
-        claims.setIssuedAt(new Date().getTime() / 1000L);
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 60);
-        claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        claims.setIssuedAt(now.toEpochSecond());
+        claims.setExpiryTime(now.plusSeconds(60L).toEpochSecond());
         String audience = "https://localhost:" + PORT + "/services/token";
         claims.setAudiences(Collections.singletonList(audience));
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c49f7a0b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/IdTokenProviderImpl.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/IdTokenProviderImpl.java
b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/IdTokenProviderImpl.java
index 5d5b01b..f9bd8e4 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/IdTokenProviderImpl.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/IdTokenProviderImpl.java
@@ -18,8 +18,8 @@
  */
 package org.apache.cxf.systest.jaxrs.security.oidc;
 
-import java.util.Calendar;
-import java.util.Date;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.List;
 
 import org.apache.cxf.rs.security.oauth2.common.UserSubject;
@@ -36,10 +36,9 @@ public class IdTokenProviderImpl implements IdTokenProvider {
     public IdToken getIdToken(String clientId, UserSubject authenticatedUser, List<String>
scopes) {
         IdToken token = new IdToken();
 
-        Calendar cal = Calendar.getInstance();
-        cal.add(Calendar.SECOND, 60);
-        token.setExpiryTime(cal.getTimeInMillis() / 1000L);
-        token.setIssuedAt(new Date().getTime() / 1000L);
+        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
+        token.setIssuedAt(now.toEpochSecond());
+        token.setExpiryTime(now.plusSeconds(60L).toEpochSecond());
         token.setAudience(clientId);
         token.setSubject(authenticatedUser.getLogin());
         token.setIssuer("OIDC IdP");


Mime
View raw message