This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Security provider fallback
- From: Mark Wielaard <mark at klomp dot org>
- To: java-patches at gcc dot gnu dot org
- Date: 02 Mar 2003 19:26:07 +0100
- Subject: Security provider fallback
- Organization:
Hi,
The following prints a warning when non of the security provider files
could be read or non of them contain any valid entries and falls back to
the standard Gnu provider. If the security provider files do exist, but
just don't contain any provider the user gets what was asked for.
This helps in situations where the security file is missing or not
correctly installed (which seems to happen often with VMs). It also
fixes a couple of Mauve failures that would happen if you did a make
check without a make install first (and no old installation was
available) like most autobuilders do.
Could someone check the warning message (not being a native English
speaker):
WARNING: could not properly read security provider files:
file:///usr/local/gcc34/lib/security/libgcj.security
file:///usr/local/gcc34/lib/security/classpath.security
Falling back to standard GNU security provider
2003-03-02 Mark Wielaard <mark at klomp dot org>
* java/security/Security.java (secprops): Initialize.
(loadProviders): Return boolean.
(static): Check result of loadProvider calls. If necessary
display WARNING and fallback to Gnu provider.
OK for mainline and branch?
Cheers,
Mark
Index: java/security/Security.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/security/Security.java,v
retrieving revision 1.11
diff -u -r1.11 Security.java
--- java/security/Security.java 31 Dec 2002 22:50:10 -0000 1.11
+++ java/security/Security.java 2 Mar 2003 18:11:22 -0000
@@ -1,5 +1,5 @@
/* Security.java --- Java base security class implmentation
- Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -56,13 +56,30 @@
public final class Security extends Object
{
private static Vector providers = new Vector();
- private static Properties secprops;
+ private static Properties secprops = new Properties();
static
{
String base = System.getProperty("gnu.classpath.home.url");
- loadProviders(base, System.getProperty("gnu.classpath.vm.shortname"));
- loadProviders(base, "classpath");
+ String vendor = System.getProperty("gnu.classpath.vm.shortname");
+
+ // Try VM specific security file
+ boolean loaded = loadProviders(base, vendor);
+
+ // Append classpath standard provider if possible
+ if (!loadProviders(base, "classpath") && !loaded && providers.size() == 0)
+ {
+ // No providers found and both security files failed to load properly.
+ System.err.println
+ ("WARNING: could not properly read security provider files:");
+ System.err.println
+ (" " + base + "/security/" + vendor + ".security");
+ System.err.println
+ (" " + base + "/security/" + "classpath" + ".security");
+ System.err.println
+ (" Falling back to standard GNU security provider");
+ providers.addElement(new gnu.java.security.provider.Gnu());
+ }
}
// This class can't be instantiated.
@@ -70,17 +87,21 @@
{
}
- private static void loadProviders(String baseUrl, String vendor)
+ /**
+ * Tries to load the vender specific security providers from the given
+ * base URL. Returns true if the resource could be read and completely
+ * parsed successfully, false otherwise.
+ */
+ private static boolean loadProviders(String baseUrl, String vendor)
{
if (baseUrl == null || vendor == null)
- return;
+ return false;
+ boolean result = true;
String secfilestr = baseUrl + "/security/" + vendor + ".security";
-
try
{
InputStream fin = new URL(secfilestr).openStream();
- secprops = new Properties();
secprops.load(fin);
int i = 1;
@@ -108,19 +129,20 @@
exception = x;
}
if (exception != null)
- System.err.println ("Error loading security provider " + name
- + ": " + exception);
+ {
+ System.err.println ("WARNING: Error loading security provider "
+ + name + ": " + exception);
+ result = false;
+ }
i++;
}
}
- catch (FileNotFoundException ignored)
- {
- // Actually we probibly shouldn't ignore these, once the security
- // properties file is actually installed somewhere.
- }
catch (IOException ignored)
{
+ result = false;
}
+
+ return result;
}
/**