From 57a4df4e505591d9537a7c742ccbe63bcca63363 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Collet Date: Mon, 2 Feb 2009 16:50:54 +0100 Subject: [PATCH 1/6] 6791927: Wrong Locale in HttpCookie::expiryDate2DeltaSeconds Force Locale.US when parsing the cookie expiration date. Reviewed-by: chegar --- .../share/classes/java/net/HttpCookie.java | 3 +- jdk/test/java/net/CookieHandler/B6791927.java | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 jdk/test/java/net/CookieHandler/B6791927.java diff --git a/jdk/src/share/classes/java/net/HttpCookie.java b/jdk/src/share/classes/java/net/HttpCookie.java index 85705543411..bd16d4f2723 100644 --- a/jdk/src/share/classes/java/net/HttpCookie.java +++ b/jdk/src/share/classes/java/net/HttpCookie.java @@ -33,6 +33,7 @@ import java.util.TimeZone; import java.util.Date; import java.lang.NullPointerException; // for javadoc +import java.util.Locale; /** * An HttpCookie object represents an http cookie, which carries state @@ -1096,7 +1097,7 @@ public final class HttpCookie implements Cloneable { static { cDateFormats = new SimpleDateFormat[COOKIE_DATE_FORMATS.length]; for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) { - cDateFormats[i] = new SimpleDateFormat(COOKIE_DATE_FORMATS[i]); + cDateFormats[i] = new SimpleDateFormat(COOKIE_DATE_FORMATS[i], Locale.US); cDateFormats[i].setTimeZone(TimeZone.getTimeZone("GMT")); } } diff --git a/jdk/test/java/net/CookieHandler/B6791927.java b/jdk/test/java/net/CookieHandler/B6791927.java new file mode 100644 index 00000000000..f1e1f7f3991 --- /dev/null +++ b/jdk/test/java/net/CookieHandler/B6791927.java @@ -0,0 +1,48 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6791927 + * @summary Wrong Locale in HttpCookie::expiryDate2DeltaSeconds + */ + +import java.net.*; +import java.util.List; +import java.util.Locale; + +public class B6791927 { + public static final void main( String[] aaParamters ) throws Exception{ + // Forces a non US locale + Locale.setDefault(Locale.FRANCE); + List cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT"); + if (cookies == null || cookies.isEmpty()) { + throw new RuntimeException("No cookie found"); + } + for (HttpCookie c : cookies) { + if (c.getMaxAge() == 0) { + throw new RuntimeException("Expiration date shouldn't be 0"); + } + } + } +} From e7c217c72dea7beb23a2f40b83ba3f6417e1de58 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Tue, 3 Feb 2009 09:38:13 +0800 Subject: [PATCH 2/6] 6552334: Enable DNS in Kerberos by default Reviewed-by: valeriep --- .../share/classes/sun/security/krb5/Config.java | 16 ++++++++-------- .../sun/security/krb5/KrbServiceLocator.java | 4 ++-- jdk/test/sun/security/krb5/DnsFallback.java | 10 ++++++++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/jdk/src/share/classes/sun/security/krb5/Config.java b/jdk/src/share/classes/sun/security/krb5/Config.java index ec3eb81767d..401f50206f9 100644 --- a/jdk/src/share/classes/sun/security/krb5/Config.java +++ b/jdk/src/share/classes/sun/security/krb5/Config.java @@ -39,7 +39,6 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Enumeration; -import java.util.List; import java.util.StringTokenizer; import java.net.InetAddress; import java.net.UnknownHostException; @@ -156,11 +155,7 @@ public class Config { configFile = loadConfigFile(); stanzaTable = parseStanzaTable(configFile); } catch (IOException ioe) { - KrbException ke = new KrbException("Could not load " + - "configuration file " + - ioe.getMessage()); - ke.initCause(ioe); - throw(ke); + // No krb5.conf, no problem. We'll use DNS etc. } } } @@ -1057,7 +1052,12 @@ public class Config { public boolean useDNS(String name) { String value = getDefault(name, "libdefaults"); if (value == null) { - return getDefaultBooleanValue("dns_fallback", "libdefaults"); + value = getDefault("dns_fallback", "libdefaults"); + if ("false".equalsIgnoreCase(value)) { + return false; + } else { + return true; + } } else { return value.equalsIgnoreCase("true"); } @@ -1117,7 +1117,7 @@ public class Config { String realm = null; String hostName = null; try { - hostName = InetAddress.getLocalHost().getHostName(); + hostName = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC, "Unable to locate Kerberos realm: " + e.getMessage()); diff --git a/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java b/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java index 0efe37d1aa4..fefcdbde054 100644 --- a/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java +++ b/jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2006-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -133,7 +133,7 @@ class KrbServiceLocator { */ static String[] getKerberosService(String realmName, String protocol) { - String dnsUrl = "dns:///_kerberos." + protocol + realmName; + String dnsUrl = "dns:///_kerberos." + protocol + "." + realmName; String[] hostports = null; try { diff --git a/jdk/test/sun/security/krb5/DnsFallback.java b/jdk/test/sun/security/krb5/DnsFallback.java index 95fbf3b165b..54aa8301eff 100644 --- a/jdk/test/sun/security/krb5/DnsFallback.java +++ b/jdk/test/sun/security/krb5/DnsFallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,8 @@ /* * @test * @bug 6673164 - * @summary dns_fallback parse error + * @bug 6552334 + * @summary fix dns_fallback parse error, and use dns by default */ import sun.security.krb5.*; @@ -31,6 +32,8 @@ import java.io.*; public class DnsFallback { public static void main(String[] args) throws Exception { + + // for 6673164 check("true", "true", true); check("false", "true", false); check("true", "false", true); @@ -39,6 +42,9 @@ public class DnsFallback { check("false", null, false); check(null, "true", true); check(null, "false", false); + + // for 6552334 + check(null, null, true); } static void check(String realm, String fallback, boolean output) throws Exception { From 17e0db945f1bad4afa55f5393cf4c94573b2a846 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Tue, 3 Feb 2009 09:38:31 +0800 Subject: [PATCH 3/6] 6785456: Read Kerberos setting from Windows environment variables Reviewed-by: valeriep --- .../classes/sun/security/krb5/Config.java | 66 +++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/jdk/src/share/classes/sun/security/krb5/Config.java b/jdk/src/share/classes/sun/security/krb5/Config.java index 401f50206f9..07c78e2959a 100644 --- a/jdk/src/share/classes/sun/security/krb5/Config.java +++ b/jdk/src/share/classes/sun/security/krb5/Config.java @@ -1079,12 +1079,39 @@ public class Config { /** * Gets default realm. + * @throws KrbException where no realm can be located + * @return the default realm, always non null */ public String getDefaultRealm() throws KrbException { + Exception cause = null; String realm = getDefault("default_realm", "libdefaults"); if ((realm == null) && useDNS_Realm()) { // use DNS to locate Kerberos realm - realm = getRealmFromDNS(); + try { + realm = getRealmFromDNS(); + } catch (KrbException ke) { + cause = ke; + } + } + if (realm == null) { + realm = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + @Override + public String run() { + String osname = System.getProperty("os.name"); + if (osname.startsWith("Windows")) { + return System.getenv("USERDNSDOMAIN"); + } + return null; + } + }); + } + if (realm == null) { + KrbException ke = new KrbException("Cannot locate default realm"); + if (cause != null) { + ke.initCause(cause); + } + throw ke; } return realm; } @@ -1092,17 +1119,48 @@ public class Config { /** * Returns a list of KDC's with each KDC separated by a space * - * @param realm the realm for which the master KDC is desired - * @return the list of KDCs + * @param realm the realm for which the KDC list is desired + * @throws KrbException if there's no way to find KDC for the realm + * @return the list of KDCs separated by a space, always non null */ public String getKDCList(String realm) throws KrbException { if (realm == null) { realm = getDefaultRealm(); } + Exception cause = null; String kdcs = getDefault("kdc", realm); if ((kdcs == null) && useDNS_KDC()) { // use DNS to locate KDC - kdcs = getKDCFromDNS(realm); + try { + kdcs = getKDCFromDNS(realm); + } catch (KrbException ke) { + cause = ke; + } + } + if (kdcs == null) { + kdcs = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + @Override + public String run() { + String osname = System.getProperty("os.name"); + if (osname.startsWith("Windows")) { + String logonServer = System.getenv("LOGONSERVER"); + if (logonServer != null + && logonServer.startsWith("\\\\")) { + logonServer = logonServer.substring(2); + } + return logonServer; + } + return null; + } + }); + } + if (kdcs == null) { + KrbException ke = new KrbException("Cannot locate KDC"); + if (cause != null) { + ke.initCause(cause); + } + throw ke; } return kdcs; } From 6a6fc9ad3fdcaae1a7c8a6795b6ccd2e03943d3b Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 3 Feb 2009 16:29:32 -0800 Subject: [PATCH 4/6] 6548433: (enum spec) java.lang.Enum docs should explain about values() and valueOf(String) Reviewed-by: martin --- jdk/src/share/classes/java/lang/Enum.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/java/lang/Enum.java b/jdk/src/share/classes/java/lang/Enum.java index e5f50f58793..5df8146c1d4 100644 --- a/jdk/src/share/classes/java/lang/Enum.java +++ b/jdk/src/share/classes/java/lang/Enum.java @@ -34,11 +34,13 @@ import java.io.ObjectStreamException; /** * This is the common base class of all Java language enumeration types. * - * More information about enums, including implicit methods synthesised - * by the compiler, can be found in The Java™ Language - * Specification, Third Edition, The Java™ Language Specification, Third + * Edition, §8.9. * + * @param The enum type subclass * @author Josh Bloch * @author Neal Gafter * @see Class#getEnumConstants() @@ -197,6 +199,15 @@ public abstract class Enum> * to declare an enum constant in this type. (Extraneous whitespace * characters are not permitted.) * + *

Note that for a particular enum type {@code T}, the + * implicitly declared {@code public static T valueOf(String)} + * method on that enum may be used instead of this method to map + * from a name to the corresponding enum constant. All the + * constants of an enum type can be obtained by calling the + * implicit {@code public static T[] values()} method of that + * type. + * + * @param The enum type whose constant is to be returned * @param enumType the {@code Class} object of the enum type from which * to return a constant * @param name the name of the constant to return From df345d27f43e7dd3b41f5b8471448db4efbeb849 Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Wed, 4 Feb 2009 19:10:09 +0800 Subject: [PATCH 5/6] 6782783: regtest HttpsURLConnection/B6216082.java throws ClosedByInterruptException Make the test robust Reviewed-by: weijun --- .../sun/net/www/protocol/https/HttpsURLConnection/B6216082.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java index e5f28779cca..1a7ac9a4f5c 100644 --- a/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java +++ b/jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java @@ -136,6 +136,7 @@ public class B6216082 { server.getLocalPort(), "/"); HttpURLConnection uc = (HttpURLConnection)url.openConnection(); System.out.println(uc.getResponseCode()); + uc.disconnect(); } catch (IOException e) { e.printStackTrace(); } finally { From b17d12c83de060f79701004c256012f51da5c646 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Collet Date: Wed, 4 Feb 2009 14:15:13 +0100 Subject: [PATCH 6/6] 6585546: Please update API doc for java.net.CookieManager Trivial doc updates Reviewed-by: chegar --- jdk/src/share/classes/java/net/CookieManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/java/net/CookieManager.java b/jdk/src/share/classes/java/net/CookieManager.java index e262dd8c2c0..6b7b1165329 100644 --- a/jdk/src/share/classes/java/net/CookieManager.java +++ b/jdk/src/share/classes/java/net/CookieManager.java @@ -107,8 +107,9 @@ import java.io.IOException; * * * - *

The implementation conforms to RFC 2965, section 3.3. + *

The implementation conforms to RFC 2965, section 3.3. * + * @see CookiePolicy * @author Edward Wang * @since 1.6 */