>From f7aee2062cb8e862865493c2d9a994d43c988772 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Fri, 2 Dec 2011 14:15:50 -0500 Subject: [PATCH] Remove Deprecated Date Functions Fixed error in parsing for stringToDate https://fedorahosted.org/pki/ticket/3 --- .../netscape/cms/jobs/RenewalNotificationJob.java | 18 ++++++++----- .../src/com/netscape/cms/servlet/cert/Monitor.java | 24 ++++++++++++------- .../cms/servlet/cert/RemoteAuthConfig.java | 25 ++++++++++--------- .../netscape/cms/servlet/cert/RenewalServlet.java | 8 ++++- .../netscape/cmscore/security/CertificateInfo.java | 10 +++++-- 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java b/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java index 59116bd911407905fb14e9eb417a35ef9d4c227f..929dd57867e8027f938c967ab9baa7fc34608c38 100644 --- a/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java +++ b/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java @@ -20,6 +20,7 @@ package com.netscape.cms.jobs; import java.io.IOException; import java.text.DateFormat; +import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.Locale; @@ -487,15 +488,18 @@ public class RenewalNotificationJob } } - private String makeLDAPDateString(Date d) { + private String makeLDAPDateString(Date date) { - String ldfYear = "" + Integer.toString(d.getYear()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + String ldfYear = "" + Integer.toString(calendar.get(Calendar.YEAR) - 1900); - String ldfMonth = getPadded(d.getMonth()); - String ldfDate = getPadded(d.getDate()); - String ldfHours = getPadded(d.getHours()); - String ldfMinutes = getPadded(d.getMinutes()); - String ldfSeconds = getPadded(d.getSeconds()); + String ldfMonth = getPadded(calendar.get(Calendar.MONTH)); + String ldfDate = getPadded(calendar.get(Calendar.DAY_OF_MONTH)); + String ldfHours = getPadded(calendar.get(Calendar.HOUR)); + String ldfMinutes = getPadded(calendar.get(Calendar.MINUTE)); + String ldfSeconds = getPadded(calendar.get(Calendar.SECOND)); return ldfYear + ldfMonth + ldfDate + ldfHours + ldfMinutes + ldfSeconds + "Z"; } diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/Monitor.java b/pki/base/common/src/com/netscape/cms/servlet/cert/Monitor.java index 649d701695d0d0947d10e688fbbf22981332a9bb..db77d039cfa00c374ff56a3ca28bb51d2230c35e 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/Monitor.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/Monitor.java @@ -19,6 +19,7 @@ package com.netscape.cms.servlet.cert; import java.io.IOException; +import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.Locale; @@ -341,14 +342,15 @@ public class Monitor extends CMSServlet { z.length() == 15 && (z.charAt(14) == 'Z' || z.charAt(14) == 'z'))) { // 20020516132030Z or 20020516132030 try { - int year = Integer.parseInt(z.substring(0, 4)) - 1900; + int year = Integer.parseInt(z.substring(0, 4)); int month = Integer.parseInt(z.substring(4, 6)) - 1; int date = Integer.parseInt(z.substring(6, 8)); int hour = Integer.parseInt(z.substring(8, 10)); int minute = Integer.parseInt(z.substring(10, 12)); int second = Integer.parseInt(z.substring(12, 14)); - - d = new Date(year, month, date, hour, minute, second); + Calendar calendar= Calendar.getInstance(); + calendar.set(year, month, date, hour, minute, second); + d = calendar.getTime(); } catch (NumberFormatException nfe) { } } else if (z != null && z.length() > 1 && z.charAt(0) == '-') { // -5 @@ -365,21 +367,25 @@ public class Monitor extends CMSServlet { } String DateToZString(Date d) { - String time = "" + (d.getYear() + 1900); - int i = d.getMonth() + 1; + Calendar calendar = Calendar.getInstance(); + calendar.setTime(d); + + + String time = "" + (calendar.get(Calendar.YEAR)); + int i = calendar.get(Calendar.MONTH) + 1; if (i < 10) time += "0"; time += i; - i = d.getDate(); + i = calendar.get(Calendar.DAY_OF_MONTH); if (i < 10) time += "0"; time += i; - i = d.getHours(); + i = calendar.get(Calendar.HOUR_OF_DAY); if (i < 10) time += "0"; time += i; - i = d.getMinutes(); + i = calendar.get(Calendar.MINUTE); if (i < 10) time += "0"; time += i; - i = d.getSeconds(); + i = calendar.get(Calendar.SECOND); if (i < 10) time += "0"; time += i + "Z"; return time; diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/RemoteAuthConfig.java b/pki/base/common/src/com/netscape/cms/servlet/cert/RemoteAuthConfig.java index 86fa0dc571e7f2b8b1c08c6cfa8ad507bdcd652f..9c414b9cbf3f17d3ed2ec5118e2883d8a26304d8 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/RemoteAuthConfig.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/RemoteAuthConfig.java @@ -19,6 +19,7 @@ package com.netscape.cms.servlet.cert; import java.io.IOException; +import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.Locale; @@ -597,20 +598,20 @@ public class RemoteAuthConfig extends CMSServlet { } private String makeInstanceName() { - Date now = new Date(); - int y = 1900 + now.getYear(); + Calendar now = Calendar.getInstance(); + int y = now.get(Calendar.YEAR); String name = "R" + y; - if (now.getMonth() < 10) name += "0"; - name += now.getMonth(); - if (now.getDate() < 10) name += "0"; - name += now.getDate(); - if (now.getHours() < 10) name += "0"; - name += now.getHours(); - if (now.getMinutes() < 10) name += "0"; - name += now.getMinutes(); - if (now.getSeconds() < 10) name += "0"; - name += now.getSeconds(); + if (now.get(Calendar.MONTH) < 10) name += "0"; + name += now.get(Calendar.MONTH); + if (now.get(Calendar.DAY_OF_MONTH) < 10) name += "0"; + name += now.get(Calendar.DAY_OF_MONTH); + if (now.get(Calendar.HOUR_OF_DAY) < 10) name += "0"; + name += now.get(Calendar.HOUR_OF_DAY); + if (now.get(Calendar.MINUTE) < 10) name += "0"; + name += now.get(Calendar.MINUTE); + if (now.get(Calendar.SECOND) < 10) name += "0"; + name += now.get(Calendar.SECOND); return name; } } diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/RenewalServlet.java b/pki/base/common/src/com/netscape/cms/servlet/cert/RenewalServlet.java index 811c5f10797ffd95a81c455c7c11dc93a95d9eaf..050dd36dca916a9528c538ba5bdc01bafc9a37f2 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/cert/RenewalServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/cert/RenewalServlet.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.math.BigInteger; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.Vector; @@ -190,8 +191,11 @@ public class RenewalServlet extends CMSServlet { if (beginYear != -1 && beginMonth != -1 && beginDate != -1 && endYear != -1 && endMonth != -1 && endDate != -1) { - notBefore = new Date(beginYear, beginMonth, beginDate); - notAfter = new Date(endYear, endMonth, endDate); + Calendar calendar = Calendar.getInstance(); + calendar.set(beginYear, beginMonth, beginDate); + notBefore = calendar.getTime(); + calendar.set(endYear, endMonth, endDate); + notAfter = calendar.getTime(); } } // coming from client else { diff --git a/pki/base/common/src/com/netscape/cmscore/security/CertificateInfo.java b/pki/base/common/src/com/netscape/cmscore/security/CertificateInfo.java index c492feac0a2c788b546f1e869fcfe65f7db06dfd..dc240dac2aeeaf2e922c62910527d7fab2d05a69 100644 --- a/pki/base/common/src/com/netscape/cmscore/security/CertificateInfo.java +++ b/pki/base/common/src/com/netscape/cmscore/security/CertificateInfo.java @@ -27,6 +27,7 @@ import java.security.PublicKey; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.CertificateParsingException; +import java.util.Calendar; import java.util.Date; import netscape.security.util.DerInputStream; @@ -142,10 +143,13 @@ public abstract class CertificateInfo { int afterSec = Integer.parseInt(mProperties.getAfterSec()); - notBeforeDate = new Date(beginYear, beginMonth, beginDate, + Calendar calendar = Calendar.getInstance(); + calendar.set(beginYear, beginMonth, beginDate, beginHour, beginMin, beginSec); - notAfterDate = new Date(afterYear, afterMonth, afterDate, - afterHour, afterMin, afterSec); + notBeforeDate = calendar.getTime(); + calendar.set(afterYear, afterMonth, afterDate, + afterHour, afterMin, afterSec); + notAfterDate = calendar.getTime(); } return new CertificateValidity(notBeforeDate, notAfterDate); } -- 1.7.7.3