ALF-9127 - WebDAV - fix unsafe use of SimpleDateFormat

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28420 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2011-06-16 09:46:50 +00:00
parent 4cc14b3106
commit faf34d29fb

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2011 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -20,7 +20,6 @@ package org.alfresco.repo.webdav;
import java.io.Serializable; import java.io.Serializable;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale; import java.util.Locale;
@@ -249,12 +248,6 @@ public class WebDAV
private static String CREATION_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; private static String CREATION_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
// HTTP header date/time formatter
// NOTE: According to RFC2616 dates should always be in English and in
// the GMT timezone see http://rfc.net/rfc2616.html#p20 for details
private static SimpleDateFormat _httpDateFormatter = new SimpleDateFormat(HEADER_IF_DATE_FORMAT, Locale.ENGLISH);
/** /**
* Formats the given date so that it conforms with the Last-Modified HTTP header * Formats the given date so that it conforms with the Last-Modified HTTP header
* *
@@ -263,7 +256,7 @@ public class WebDAV
*/ */
public static String formatModifiedDate(Date date) public static String formatModifiedDate(Date date)
{ {
return _httpDateFormatter.format(date); return formatHeaderDate(date);
} }
/** /**
@@ -274,7 +267,7 @@ public class WebDAV
*/ */
public static String formatModifiedDate(long ldate) public static String formatModifiedDate(long ldate)
{ {
return _httpDateFormatter.format(new Date(ldate)); return formatHeaderDate(ldate);
} }
/** /**
@@ -307,7 +300,10 @@ public class WebDAV
*/ */
public static String formatHeaderDate(Date date) public static String formatHeaderDate(Date date)
{ {
return _httpDateFormatter.format( date); // HTTP header date/time format
// NOTE: According to RFC2616 dates should always be in English and in
// the GMT timezone see http://rfc.net/rfc2616.html#p20 for details
return DateFormatUtils.format(date, HEADER_IF_DATE_FORMAT, TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
} }
/** /**
@@ -316,9 +312,12 @@ public class WebDAV
* @param date long * @param date long
* @return String * @return String
*/ */
public static String formatHeaderDate(long date) public static String formatHeaderDate(long ldate)
{ {
return _httpDateFormatter.format( new Date(date)); // HTTP header date/time format
// NOTE: According to RFC2616 dates should always be in English and in
// the GMT timezone see http://rfc.net/rfc2616.html#p20 for details
return DateFormatUtils.format(ldate, HEADER_IF_DATE_FORMAT, TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
} }
/** /**
@@ -640,9 +639,6 @@ public class WebDAV
*/ */
static static
{ {
// ensure http dates are in GMT time zone (see note above)
_httpDateFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
// Create the WebDAV to Alfresco property mapping table // Create the WebDAV to Alfresco property mapping table
_propertyNameMap = new Hashtable<String, QName>(); _propertyNameMap = new Hashtable<String, QName>();