summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2006-07-31 03:39:01 +0000
committerMark Wielaard <mark@klomp.org>2006-07-31 03:39:01 +0000
commitf3f5fa595b90b16495d1199963e4f9a8a1018029 (patch)
tree8105ee393e1c473200071ffa1af65c3723ec500f
parentf8281aa7c87e365bdf1adcced842e4ae8be87985 (diff)
downloadclasspath-f3f5fa595b90b16495d1199963e4f9a8a1018029.tar.gz
2006-07-31 Raif S. Naffah <raif@swiftdsl.com.au>
* java/security/Provider.java: Updated copyright year. Updated documentation. Formatting. (put): Updated documentation. Added security manager check. Canonicalize the key before adding its mapping. (get): Override superclass implementation to use canonicalized keys. (remove): Updated documentation. Added security manager check. Canonicalize the key before removing its mapping. (clear): Updated documentation. Added security manager check. (toCanonicalKey): New method.
-rw-r--r--ChangeLog16
-rw-r--r--java/security/Provider.java105
2 files changed, 83 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index af00e869a..8afb66aed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2006-07-31 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * java/security/Provider.java: Updated copyright year.
+ Updated documentation.
+ Formatting.
+ (put): Updated documentation.
+ Added security manager check.
+ Canonicalize the key before adding its mapping.
+ (get): Override superclass implementation to use canonicalized keys.
+ (remove): Updated documentation.
+ Added security manager check.
+ Canonicalize the key before removing its mapping.
+ (clear): Updated documentation.
+ Added security manager check.
+ (toCanonicalKey): New method.
+
2006-07-30 Matt Wringe <mwringe@redhat.com>
* gnu/java/security/Engine.java
diff --git a/java/security/Provider.java b/java/security/Provider.java
index 57affe1dc..ea1dd9d3f 100644
--- a/java/security/Provider.java
+++ b/java/security/Provider.java
@@ -1,5 +1,5 @@
/* Provider.java -- Security provider information
- Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,20 +41,19 @@ import java.io.Serializable;
import java.util.Properties;
/**
- * This class represents a Java security architecture service provider.
- * The services provided by a such a provider can range from security
- * algorithms to key generation.
+ * This class represents a Java security architecture service provider. The
+ * services provided by a such a provider can range from security algorithms to
+ * key generation.
* <p>
- * Providers are installed by name and version number. There is one
- * standard provider supplied with the class library. This is the
- * "GNU" provider, which can also be accessed by the alias "SUN" for
- * compatibility with the JDK.
- *
- * @version 0.0
- *
+ * Providers are installed by name and version number. See the static
+ * initializer of the {@link java.security.Security} class for the default
+ * security providers installed by this class library.
+ *
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
-public abstract class Provider extends Properties implements Serializable
+public abstract class Provider
+ extends Properties
+ implements Serializable
{
private static final long serialVersionUID = -4298000515446427739L;
@@ -119,57 +118,81 @@ public abstract class Provider extends Properties implements Serializable
}
/**
- * Sets the key property to have the specified value.
+ * Maps a key property to a designated value.
* <p>
- * <bold>NOT IMPLEMENTED YET</bold>[
- * First, if there is a security manager, its <code>checkSecurityAccess</code>
- * method is called with the string "putProviderProperty."+name, where name is
- * the provider name, to see if it's ok to set this provider's property
- * values.
- * If the default implementation of <code>checkSecurityAccess</code> is used
- * (that is, that method is not overriden), then this results in a call to the
- * security manager's <code>checkPermission</code> method with a
- * <code>SecurityPermission("putProviderProperty."+name)</code>
- * permission.<br>]
- *
+ * If there is an installed {@link SecurityManager} object in the underlying
+ * VM, its {@link SecurityManager#checkSecurityAccess(String)} method is
+ * called with the string <code>"putProviderProperty." + name</code>, where
+ * <code>name</code> is this provider's name. For the default implementation
+ * this translates into a {@link SecurityManager#checkPermission(Permission)}
+ * for a <code>SecurityPermission("putProviderProperty." + name)</code>.
+ *
* @param key The property key.
* @param value The property value.
- *
* @return The previous value of the specified property (<code>key</code>),
* or <code>null</code> if it did not have one.
- * @throws SecurityException If a security manager exists and its
- * {@link java.lang.SecurityManager.checkSecurityAccess(java.lang.String)}
- * method denies access to set property values.
+ * @throws SecurityException If a security manager is installed and its
+ * {@link SecurityManager#checkSecurityAccess(String)} method
+ * disallows adding properties at run-time.
* @since Classpath 0.4+cvs, JDK 1.2
- * @see java.lang.Object.equals(Object)
- * @see java.util.Hashtable.get(Object)
+ * @see java.lang.Object#equals(Object)
+ * @see java.util.Hashtable#get(Object)
*/
public Object put(Object key, Object value)
{
- return super.put(key, value);
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("putProviderProperty." + this.name);
+ return super.put(toCanonicalKey(key), value);
}
-
+
+ // overrides same in java.util.Hashtable
+ public Object get(Object key)
+ {
+ return super.get(toCanonicalKey(key));
+ }
+
/**
* This method removes the specified key entry (and its associated value)
- * from the property mapping list.
+ * from the property mapping collection.
+ * <p>
+ * If there is an installed {@link SecurityManager} object in the underlying
+ * VM, its {@link SecurityManager#checkSecurityAccess(String)} method is
+ * called with the string <code>"removeProviderProperty." + name</code>, where
+ * <code>name</code> is this provider's name. For the default implementation
+ * this translates into a {@link SecurityManager#checkPermission(Permission)}
+ * for a <code>SecurityPermission("removeProviderProperty." + name)</code>.
*
* @param key The key to remove
- *
* @return The previous value for this key, or <code>null</code> if no
* previous value.
*/
public Object remove(Object key)
{
- return super.remove(key);
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("removeProviderProperty." + this.name);
+ return super.remove(toCanonicalKey(key));
}
/**
- * This method clears the entire property list such that it no longer
+ * This method clears the entire property collection such that it no longer
* contains the properties used to look up the services provided by
- * the <code>Provider</code>.
+ * this <code>Provider</code>.
+ * <p>
+ * If there is an installed {@link SecurityManager} object in the underlying
+ * VM, its {@link SecurityManager#checkSecurityAccess(String)} method is
+ * called with the string <code>"clearProviderProperties." + name</code>,
+ * where <code>name</code> is this provider's name. For the default
+ * implementation this translates into a
+ * {@link SecurityManager#checkPermission(Permission)} for a
+ * <code>SecurityPermission("clearProviderProperties." + name)</code>.
*/
public void clear()
{
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("clearProviderProperties." + this.name);
super.clear();
}
@@ -185,5 +208,11 @@ public abstract class Provider extends Properties implements Serializable
return (getClass().getName() + ": name=" + getName() + " version=" +
version);
}
-
+
+ private Object toCanonicalKey(Object key)
+ {
+ if (key.getClass().isAssignableFrom(String.class)) // is it ours?
+ return ((String) key).toUpperCase(); // use default locale
+ return key;
+ }
}