harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [133/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionCollection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionCollection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionCollection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionCollection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,123 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.Serializable;
+import java.util.Enumeration;
+
+import com.ibm.oti.util.PriviAction;
+
+/**
+ * Abstract superclass of classes which are collections of Permission objects.
+ * 
+ */
+public abstract class PermissionCollection implements Serializable {
+
+	/**
+	 * Set to true if the collection is read only.
+	 */
+	private boolean readOnly = false;
+
+	/**
+	 * Constructs a new instance of this class.
+	 * 
+	 */
+	public PermissionCollection() {
+		// Intentionally empty
+	}
+
+	/**
+	 * Adds the argument to the collection.
+	 * 
+	 * 
+	 * @param permission
+	 *            java.security.Permission the permission to add to the
+	 *            collection.
+	 * @exception IllegalStateException
+	 *                if the collection is read only.
+	 */
+	public abstract void add(Permission permission);
+
+	/**
+	 * Answers an enumeration of the permissions in the receiver.
+	 * 
+	 * 
+	 * @return Enumeration the permissions in the receiver.
+	 */
+	public abstract Enumeration elements();
+
+	/**
+	 * Indicates whether the argument permission is implied by the permissions
+	 * contained in the receiver.
+	 * 
+	 * 
+	 * @return boolean <code>true</code> if the argument permission is implied
+	 *         by the permissions in the receiver, and <code>false</code> if
+	 *         it is not.
+	 * @param permission
+	 *            java.security.Permission the permission to check
+	 */
+	public abstract boolean implies(Permission permission);
+
+	/**
+	 * Indicates whether new permissions can be added to the receiver.
+	 * 
+	 * 
+	 * @return boolean <code>true</code> if the receiver is read only
+	 *         <code>false</code> if new elements can still be added to the
+	 *         receiver.
+	 */
+	public boolean isReadOnly() {
+		return readOnly;
+	}
+
+	/**
+	 * Marks the receiver as read only, so that no new permissions can be added
+	 * to it.
+	 * 
+	 */
+	public void setReadOnly() {
+		readOnly = true;
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * 
+	 * @return a printable representation for the receiver.
+	 */
+	public String toString() {
+		String newline = (String) AccessController
+				.doPrivileged(new PriviAction("line.separator", "\n"));
+		StringBuffer answer = new StringBuffer();
+		answer.append(super.toString());
+		answer.append(" (");
+		Enumeration perms = elements();
+		if (perms.hasMoreElements()) {
+			answer.append(newline);
+		}
+		while (perms.hasMoreElements()) {
+			Permission p = (Permission) perms.nextElement();
+			answer.append("  ");
+			answer.append(p);
+			answer.append(newline);
+		}
+		answer.append(")");
+		return answer.toString();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permissions.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permissions.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permissions.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permissions.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,206 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.Serializable;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.NoSuchElementException;
+import java.util.Vector;
+
+/**
+ * A heterogeneous collection of permissions.
+ * 
+ */
+public final class Permissions extends PermissionCollection implements
+		Serializable {
+	static final long serialVersionUID = 4858622370623524688L;
+
+	/**
+	 * Maps a Permission's class to an appropriate PermissionCollection.
+	 */
+	Hashtable perms = new Hashtable(8);
+
+	/**
+	 * Set to an AllPermissionCollection if this Permissions contains
+	 * AllPermission.
+	 */
+	PermissionCollection allPermission;
+
+	// An Enumeration over the elements in the receiver.
+	// Note that, this is useful for printing them and not much
+	// else, since it ignores the PermissionCollections that
+	// they are stored in. This breaks any added semantics
+	// provided by a particular PermissionCollection class.
+	// In other words, the Permissions object may report that
+	// a permission is implied in cases where that permission
+	// is not implied by any *one* of the entries returned by
+	// this enumeration.
+	private class PermissionsEnumeration implements Enumeration {
+		Enumeration enumMap = perms.elements();
+
+		PermissionCollection c;
+
+		Enumeration enumC;
+
+		Permission next = findNextPermission();
+
+		public boolean hasMoreElements() {
+			return next != null;
+		}
+
+		public Object nextElement() {
+			if (next == null) {
+				throw new NoSuchElementException();
+			}
+			Object answer = next;
+			next = findNextPermission();
+			return answer;
+		}
+
+		// This method is the important one. It looks for and
+		// answers the next available permission. If there are
+		// no permissions left to return, it answers null.
+		private Permission findNextPermission() {
+			// Loop until we get a collection with at least one element.
+			while (c == null && enumMap.hasMoreElements()) {
+				c = (PermissionCollection) enumMap.nextElement();
+				enumC = c.elements();
+				if (!enumC.hasMoreElements())
+					c = null;
+			}
+			// At this point, c == null if there are no more elements,
+			// and otherwise is the first collection with a free element
+			// (with enumC set up to return that element).
+			if (c == null) {
+				// no more elements, so return null;
+				return null;
+			}
+			Permission answer = (Permission) enumC.nextElement();
+			if (!enumC.hasMoreElements()) {
+				c = null;
+			}
+			return answer;
+		}
+	}
+
+	/**
+	 * Constructs a new instance of this class.
+	 * 
+	 */
+	public Permissions() {
+		super();
+	}
+
+	/**
+	 * Adds the argument to the collection.
+	 * 
+	 * 
+	 * @param permission
+	 *            java.security.Permission the permission to add to the
+	 *            collection
+	 */
+	public void add(Permission permission) {
+		if (isReadOnly())
+			throw new SecurityException();
+		if (permission.getClass() == AllPermission.class) {
+			(allPermission = findCollection(permission)).add(permission);
+		} else
+			findCollection(permission).add(permission);
+	}
+
+	/**
+	 * Answers an enumeration of the permissions in the receiver.
+	 * 
+	 * 
+	 * @return Enumeration the permissions in the receiver.
+	 */
+	public Enumeration elements() {
+		PermissionsEnumeration answer = new PermissionsEnumeration();
+		return answer;
+	}
+
+	/**
+	 * Find the appropriate permission collection to use for the given
+	 * permission.
+	 * 
+	 * 
+	 * @param permission
+	 *            Permission the permission to find a collection for
+	 * @return PermissionCollection the collection to use with the permission.
+	 */
+	private PermissionCollection findCollection(Permission permission) {
+		Class cl = permission.getClass();
+		PermissionCollection answer = (PermissionCollection) perms.get(cl);
+		if (answer == null) {
+			answer = permission.newPermissionCollection();
+			if (answer == null)
+				answer = new PermissionsHash();
+			perms.put(cl, answer);
+		}
+		return answer;
+	}
+
+	/**
+	 * Indicates whether the argument permission is implied by the permissions
+	 * contained in the receiver.
+	 * 
+	 * 
+	 * @return boolean <code>true</code> if the argument permission is implied
+	 *         by the permissions in the receiver, and <code>false</code> if
+	 *         it is not.
+	 * @param perm
+	 *            java.security.Permission the permission to check
+	 */
+	public boolean implies(Permission perm) {
+		// Optimization 1: If AllPermission is in there, then assume
+		// we know what it does and return true immediately.
+		if (allPermission != null)
+			return true;
+
+		// Optimization 2: check if permissions of this type have
+		// been added in a collection of their own. If so, look
+		// in that collection first.
+		PermissionCollection bin = (PermissionCollection) perms.get(perm
+				.getClass());
+		if (bin != null)
+			return bin.implies(perm);
+
+		// Resolve any required unresolved permissions
+		UnresolvedPermissionCollection unresolvedCollection = (UnresolvedPermissionCollection) perms
+				.get(UnresolvedPermission.class);
+		if (unresolvedCollection != null) {
+			Vector permissions = unresolvedCollection.getPermissions(perm
+					.getClass().getName());
+			if (permissions != null) {
+				Enumeration permsEnum = permissions.elements();
+				while (permsEnum.hasMoreElements()) {
+					Permission resolved = ((UnresolvedPermission) permsEnum
+							.nextElement()).resolve(perm.getClass()
+							.getClassLoader());
+					if (resolved != null) {
+						bin = findCollection(resolved);
+						bin.add(resolved);
+					}
+				}
+				if (bin != null)
+					return bin.implies(perm);
+			}
+		}
+		return false;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionsHash.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionsHash.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionsHash.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PermissionsHash.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,97 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * A simple Hashtable based collection of Permission objects.
+ * <p>
+ * The class' .implies method simply scans each permission individually and asks
+ * if the permission should be granted. No addition semantics is provided by the
+ * collection, so it is not possible to grant permissions whose "grantedness" is
+ * split across multiple stored Permissions.
+ * <p>
+ * Instances of this class can be used to store heterogeneous collections of
+ * permissions, as long as it is not necessary to remember when multiple
+ * occurances of .equal permissions are added.
+ * 
+ */
+
+class PermissionsHash extends PermissionCollection {
+	static final long serialVersionUID = -8491988220802933440L;
+
+	/**
+	 * A hashtable to store the elements of the collection.
+	 */
+	Hashtable perms = new Hashtable(8);
+
+	/**
+	 * Constructs a new instance of this class.
+	 * 
+	 */
+	public PermissionsHash() {
+		super();
+	}
+
+	/**
+	 * Adds the argument to the collection.
+	 * 
+	 * 
+	 * @param perm
+	 *            java.security.Permission the permission to add to the
+	 *            collection.
+	 * @exception IllegalStateException
+	 *                if the collection is read only.
+	 */
+	public void add(Permission perm) {
+		if (isReadOnly()) {
+			throw new IllegalStateException();
+		}
+		perms.put(perm, perm);
+	}
+
+	/**
+	 * Answers an enumeration of the permissions in the receiver.
+	 * 
+	 * 
+	 * @return Enumeration the permissions in the receiver.
+	 */
+	public Enumeration elements() {
+		return perms.keys();
+	}
+
+	/**
+	 * Indicates whether the argument permission is implied by the permissions
+	 * contained in the receiver.
+	 * 
+	 * 
+	 * @return boolean <code>true</code> if the argument permission is implied
+	 *         by the permissions in the receiver, and <code>false</code> if
+	 *         it is not.
+	 * @param perm
+	 *            java.security.Permission the permission to check
+	 */
+	public boolean implies(Permission perm) {
+		Enumeration elemEnum = elements();
+		while (elemEnum.hasMoreElements())
+			if (((Permission) elemEnum.nextElement()).implies(perm))
+				return true;
+		return false;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Policy.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Policy.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Policy.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Policy.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,155 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Abstract superclass of classes which represent the system security policy.
+ * 
+ */
+public abstract class Policy {
+
+	/**
+	 * The currently in place security policy.
+	 */
+	static Policy policy;
+
+	/**
+	 * Constructs a new instance of this class.
+	 * 
+	 */
+	public Policy() {
+		super();
+	}
+
+	/**
+	 * Answers the current system security policy. If no policy has been
+	 * instantiated then this is done using the security property <EM>policy.provider</EM>
+	 * 
+	 * 
+	 * @return Policy the current system security policy.
+	 */
+	public static Policy getPolicy() {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkPermission(SecurityPermission.permissionToGetPolicy);
+		return getPolicyImpl();
+	}
+
+	static Policy getPolicyImpl() {
+		if (policy == null) {
+			// Get the policy provider before the security manager is set
+			String policyName = Security.getProperty("policy.provider");
+
+			if (System.getSecurityManager() == null) {
+				String clName = System.getProperty("java.security.manager");
+				if (clName != null) {
+					SecurityManager sm = null;
+					if (clName.length() == 0) {
+						sm = new SecurityManager();
+					} else {
+						try {
+							Class cl = Class.forName(clName);
+							sm = (SecurityManager) cl.newInstance();
+						} catch (Exception e) {
+							throw new InternalError(com.ibm.oti.util.Msg
+									.getString("K00e3", clName));
+						}
+					}
+					System.setSecurityManager(sm);
+				}
+			}
+			try {
+				if (policyName != null)
+					policy = (Policy) Class.forName(policyName).newInstance();
+			} catch (Exception e) {
+				// Intentionally empty
+			}
+			if (policy == null) {
+				// if instantiating the policy.provider failed for any reason,
+				// assume use of the default policy provider
+				policy = new com.ibm.oti.util.DefaultPolicy();
+			}
+		}
+		return policy;
+	}
+
+	/**
+	 * Sets the system-wide policy object if it is permitted by the security
+	 * manager.
+	 * 
+	 * @param p
+	 *            Policy the policy object that needs to be set.
+	 */
+	public static void setPolicy(Policy p) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkPermission(SecurityPermission.permissionToSetPolicy);
+		policy = p;
+	}
+
+	/**
+	 * Answers a PermissionCollection describing what permissions are available
+	 * to the given CodeSource based on the current security policy.
+	 * <p>
+	 * Note that this method is <em>not</em> called for classes which are in
+	 * the system domain (i.e. system classes). System classes are
+	 * <em>always</em> given full permissions (i.e. AllPermission). This can
+	 * not be changed by installing a new Policy.
+	 * 
+	 * 
+	 * @param cs
+	 *            CodeSource the code source to compute the permissions for.
+	 * @return PermissionCollection the permissions the code source should have.
+	 */
+	public abstract PermissionCollection getPermissions(CodeSource cs);
+
+	/**
+	 * Reloads the policy configuration, depending on how the type of source
+	 * location for the policy information.
+	 * 
+	 * 
+	 */
+	public abstract void refresh();
+
+	/**
+	 * Answers a PermissionCollection describing what permissions are available
+	 * to the given ProtectionDomain (more specifically, its CodeSource) based
+	 * on the current security policy.
+	 * 
+	 * @param domain
+	 *            ProtectionDomain the protection domain to compute the
+	 *            permissions for.
+	 * @return PermissionCollection the permissions the code source should have.
+	 */
+	public PermissionCollection getPermissions(ProtectionDomain domain) {
+		return getPermissions(domain.getCodeSource());
+	}
+
+	/**
+	 * Answers whether the Permission is implied by the PermissionCollection of
+	 * the Protection Domain
+	 * 
+	 * @param domain
+	 *            ProtectionDomain for which Permission to be checked
+	 * @param permission
+	 *            Permission for which authorization is to be verified
+	 * @return boolean Permission implied by ProtectionDomain
+	 */
+	public boolean implies(ProtectionDomain domain, Permission permission) {
+		return getPermissions(domain).implies(permission);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Principal.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Principal.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Principal.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Principal.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,67 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Principals are objects which have identities. These can be individuals,
+ * groups, corporations, unique program executions, etc.
+ * 
+ */
+public interface Principal {
+	/**
+	 * Compares the argument to the receiver, and answers true if they represent
+	 * the <em>same</em> object using a class specific comparison. The
+	 * implementation in Object answers true only if the argument is the exact
+	 * same object as the receiver (==).
+	 * 
+	 * 
+	 * @param o
+	 *            the object to compare with this object
+	 * @return <code>true</code> if the object is the same as this object
+	 *         <code>false</code> if it is different from this object
+	 * @see #hashCode()
+	 */
+	public abstract boolean equals(Object o);
+
+	/**
+	 * Answers the name of the receiver.
+	 * 
+	 * 
+	 * @return the receiver's name
+	 */
+	public abstract String getName();
+
+	/**
+	 * Answers an integer hash code for the receiver. Any two objects which
+	 * answer <code>true</code> when passed to <code>equals</code> must
+	 * answer the same value for this method.
+	 * 
+	 * @return the receiver's hash
+	 * 
+	 * @see #equals(Object)
+	 */
+	public abstract int hashCode();
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * 
+	 * @return a printable representation for the receiver.
+	 */
+	public abstract String toString();
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedAction.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedAction.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedAction.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedAction.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,39 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Computations to be performed with privileges enabled
+ * 
+ * @see AccessController
+ * @see AccessController#doPrivileged(PrivilegedAction)
+ * @see PrivilegedExceptionAction
+ */
+public abstract interface PrivilegedAction {
+
+	/**
+	 * Performs the actual privileged computation.
+	 * 
+	 * 
+	 * @return an Object that represents the result of the computation.
+	 * 
+	 * @see AccessController#doPrivileged(PrivilegedAction)
+	 * @see AccessController#doPrivileged(PrivilegedAction,
+	 *      AccessControlContext)
+	 */
+	Object run();
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedActionException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedActionException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedActionException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedActionException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,69 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Instances of this class are used to wrap exceptions which occur within
+ * privileged operations.
+ * 
+ */
+public class PrivilegedActionException extends Exception {
+	static final long serialVersionUID = 4724086851538908602L;
+
+	/**
+	 * The exception which occurred.
+	 */
+	private Exception exception;
+
+	/**
+	 * Constructs a new instance of this class with its exception filled in.
+	 * @param ex 
+	 */
+	public PrivilegedActionException(Exception ex) {
+		super(null, ex);
+		exception = ex;
+	}
+
+	/**
+	 * Answers the exception which caused the receiver to be thrown.
+	 * @return exception
+	 */
+	public Exception getException() {
+		return exception;
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * 
+	 * @return String a printable representation for the receiver.
+	 */
+	public String toString() {
+		return super.toString() + ": " + exception;
+	}
+
+	/**
+	 * Answers the cause of this Throwable, or null if there is no cause.
+	 * 
+	 * 
+	 * @return Throwable The receiver's cause.
+	 */
+	public Throwable getCause() {
+		return exception;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedExceptionAction.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedExceptionAction.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedExceptionAction.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PrivilegedExceptionAction.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This class represents privileged actions to be performed, which can throw
+ * checked exceptions.
+ * 
+ * 
+ * @see AccessController
+ * @see AccessController#doPrivileged(PrivilegedExceptionAction)
+ * @see AccessController#doPrivileged(PrivilegedExceptionAction,
+ *      AccessControlContext)
+ * @see PrivilegedAction
+ */
+public abstract interface PrivilegedExceptionAction {
+
+	/**
+	 * Performs the actual privileged computation.
+	 * 
+	 * 
+	 * @return an Object that represents the result of the computation.
+	 * @throws Exception 
+	 * 
+	 * @see AccessController#doPrivileged(PrivilegedAction)
+	 * @see AccessController#doPrivileged(PrivilegedAction,
+	 *      AccessControlContext)
+	 */
+	public Object run() throws Exception;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/ProtectionDomain.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/ProtectionDomain.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/ProtectionDomain.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/ProtectionDomain.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,204 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import com.ibm.oti.util.PriviAction;
+
+/**
+ * This class represents a domain in which classes from the same source (URL)
+ * and signed by the same keys are stored. All the classes inside are given the
+ * same permissions.
+ * <p>
+ * Note: a class can only belong to one and only one protection domain.
+ */
+public class ProtectionDomain {
+
+	/**
+	 * The code source of the classes in this domain.
+	 */
+	private CodeSource cs;
+
+	/**
+	 * The permissions which should be provided to the classes in this domain.
+	 */
+	private PermissionCollection pc;
+
+	/**
+	 * ClassLoader associated with the ProtectionDomain
+	 */
+	private ClassLoader classLoader;
+
+	/**
+	 * Principals associated with the ProtectionDomain
+	 */
+	private Principal[] principals;
+
+	/**
+	 * Allow dynamic permission checking (by delegating to Policy)
+	 */
+	private boolean dynamicPermissionChecking = false;
+
+	/**
+	 * Contructs a protection domain from the given code source and the
+	 * permissions that that should be granted to the classes which are
+	 * encapsulated in it.
+	 * @param codesource 
+	 * @param permissions 
+	 */
+	public ProtectionDomain(CodeSource codesource,
+			PermissionCollection permissions) {
+		super();
+		cs = codesource;
+		pc = permissions;
+		if (pc != null)
+			pc.setReadOnly();
+	}
+
+	/**
+	 * Contructs a protection domain from the given code source and the
+	 * permissions that that should be granted to the classes which are
+	 * encapsulated in it. 
+	 * 
+	 * This constructor also allows the association of a ClassLoader and group
+	 * of Principals.
+	 * 
+	 * @param codesource
+	 *            the CodeSource associated with this domain
+	 * @param permissions
+	 *            the Permissions associated with this domain
+	 * @param classloader
+	 *            the ClassLoader associated with this domain
+	 * @param principals
+	 *            the Principals associated with this domain
+	 */
+	public ProtectionDomain(CodeSource codesource,
+			PermissionCollection permissions, ClassLoader classloader,
+			Principal[] principals) {
+		super();
+		cs = codesource;
+
+		pc = permissions;
+		if (pc != null) {
+			pc.setReadOnly();
+		}
+
+		dynamicPermissionChecking = true;
+
+		this.classLoader = classloader;
+
+		this.principals = principals;
+
+	}
+
+	/**
+	 * Answers the code source of this domain.
+	 * 
+	 * @return java.security.CodeSource the code source of this domain
+	 */
+	public final CodeSource getCodeSource() {
+		return cs;
+	}
+
+	/**
+	 * Answers the permissions that should be granted to the classes which are
+	 * encapsulated in this domain.
+	 * 
+	 * @return java.security.PermissionCollection collection of permissions
+	 *         associated with this domain.
+	 */
+	public final PermissionCollection getPermissions() {
+		return pc;
+	}
+
+	/**
+	 * Returns the Principals associated with this ProtectionDomain. A change to
+	 * the returned array will not impact the ProtectionDomain.
+	 * 
+	 * @return Principals[] Principals associated with the ProtectionDomain.
+	 */
+	public final Principal[] getPrincipals() {
+
+		// No principals? Return an empty array.
+		if (this.principals == null) {
+			return new Principal[0];
+		}
+
+		Principal[] result = new Principal[this.principals.length];
+		System.arraycopy(this.principals, 0, result, 0, this.principals.length);
+		return result;
+
+	}
+
+	/**
+	 * Returns the ClassLoader associated with the ProtectionDomain
+	 * 
+	 * @return ClassLoader associated ClassLoader
+	 */
+	public final ClassLoader getClassLoader() {
+		return classLoader;
+	}
+
+	/**
+	 * Determines whether the permission collection of this domain implies the
+	 * argument permission.
+	 * 
+	 * 
+	 * @return boolean true if this permission collection implies the argument
+	 *         and false otherwise.
+	 * @param perm
+	 *            java.security.Permission the permission to check.
+	 */
+	public boolean implies(Permission perm) {
+
+		PermissionCollection perms = null;
+		final ProtectionDomain domain = this;
+		if (dynamicPermissionChecking) {
+			Policy policy = (Policy) AccessController
+					.doPrivileged(new PriviAction());
+			perms = policy.getPermissions(domain);
+		} else {
+			perms = this.pc;
+		}
+
+		return perms != null && perms.implies(perm);
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * @return String a printable representation for the receiver.
+	 */
+	public String toString() {
+		StringBuffer answer = new StringBuffer("ProtectionDomain ");
+		if (cs == null) {
+			answer.append("null");
+		} else {
+			answer.append(cs.toString());
+		}
+		// The default protection domain grants access to this
+		String crlf = (String) AccessController.doPrivileged(new PriviAction(
+				"line.separator"));
+		answer.append(crlf);
+		if (pc == null) {
+			answer.append("null");
+		} else {
+			answer.append(pc.toString());
+		}
+		return answer.toString();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Provider.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Provider.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Provider.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Provider.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,255 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * Common superclass for providers of Java Security API implementations. Such
+ * implementations may provide a number of services like Message digest, key
+ * generation, certificate support, secure random number generation, etc.
+ * 
+ * @see MessageDigest
+ * @see java.security.cert.CertificateFactory
+ * @see SecureRandom
+ */
+public abstract class Provider extends java.util.Properties {
+
+	static final long serialVersionUID = -4298000515446427739L; 
+
+	private String name; // Name of the provider.
+
+	private String info; // Generic description about what is being provided.
+
+	private double version; // Version number for the services being provided.
+
+	/**
+	 * Constructs a new Provider with the given name, version and info.
+	 * 
+	 * @param name
+	 *            name for this provider
+	 * @param version
+	 *            version number for the services being provided
+	 * @param info
+	 *            generic description of the services being provided
+	 */
+	protected Provider(String name, double version, String info) {
+		super();
+		this.name = name;
+		this.version = version;
+		this.info = info;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#clear()
+	 */
+	public synchronized void clear() {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkSecurityAccess("clearProviderProperties." + name);
+		super.clear();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#entrySet()
+	 */
+	public Set entrySet() {
+		return Collections.unmodifiableSet(super.entrySet());
+	}
+
+	/**
+	 * Returns the generic information about the services being provided.
+	 * 
+	 * 
+	 * 
+	 * @return String generic description of the services being provided
+	 */
+	public String getInfo() {
+		return info;
+	}
+
+	/**
+	 * Returns the name of this provider.
+	 * 
+	 * 
+	 * 
+	 * @return String name of the provider
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * Returns the version number for teh services being provided
+	 * 
+	 * 
+	 * 
+	 * @return double version number for the services being provided
+	 */
+	public double getVersion() {
+		return version;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#keySet()
+	 */
+	public Set keySet() {
+		return Collections.unmodifiableSet(super.keySet());
+	}
+
+	/**
+	 * Loads properties from the specified InputStream. The properties are of
+	 * the form <code>key=value</code>, one property per line.
+	 * 
+	 * @param in
+	 *            the input stream
+	 * @throws IOException 
+	 */
+	public synchronized void load(InputStream in) throws IOException {
+		super.load(in);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
+	 */
+	public synchronized Object put(Object key, Object value) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkSecurityAccess("putProviderProperty." + name);
+		return super.put(key, value);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#putAll(java.util.Map)
+	 */
+	public synchronized void putAll(Map map) {
+		super.putAll(map);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Dictionary#remove(java.lang.Object)
+	 */
+	public synchronized Object remove(Object key) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkSecurityAccess("removeProviderProperty." + name);
+		return super.remove(key);
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * 
+	 * @return a printable representation for the receiver.
+	 */
+	public String toString() {
+		return "Provider : " + name + " at version " + version; //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Map#values()
+	 */
+	public Collection values() {
+		return Collections.unmodifiableCollection(super.values());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
+	 */
+	public String getProperty(String key, String defaultValue) {
+		String result = getProperty(key);
+
+		if (result == null) {
+			return defaultValue;
+		}
+
+		return defaultValue;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.util.Properties#getProperty(java.lang.String)
+	 */
+	public String getProperty(String key) {
+		int index = key.indexOf('.');
+		if (index == -1) {
+			return null;
+		}
+
+		String prefix = key.substring(0, index + 1);
+		String algorithm = key.substring(index + 1, key.length());
+
+		return lookupProperty(prefix, algorithm);
+	}
+
+	String lookupProperty(String property) {
+
+		// Use the Properties.getProperty to determine if property is present
+		// in its original form
+		String result = super.getProperty(property);
+		if (result != null)
+			return result;
+
+		// Look for the property in a case-insensitive fashion
+		String upper = property.toUpperCase();
+		Enumeration keyEnum = keys();
+		while (keyEnum.hasMoreElements()) {
+			String key = (String) keyEnum.nextElement();
+			if (key.toUpperCase().equals(upper))
+				return getProperty(key);
+		}
+
+		// Property was not found
+		return null;
+	}
+
+	String lookupProperty(String prefix, String key) {
+		String property = prefix + key;
+		String result = lookupProperty(property);
+		if (result != null)
+			return result;
+		result = lookupProperty("Alg.Alias." + property);
+		if (result != null)
+			return lookupProperty(prefix + result);
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PublicKey.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PublicKey.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PublicKey.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/PublicKey.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,28 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Superinterface for all specific public key interfaces
+ * 
+ * 
+ * @see PublicKey
+ * @see PrivateKey
+ */
+public interface PublicKey extends Key {
+	public static final long serialVersionUID = 7187392471159151072L; 
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureClassLoader.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureClassLoader.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureClassLoader.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,120 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.util.Hashtable;
+
+/**
+ * SecureClassLoaders are used to dynamically load, link and install classes
+ * into a running image. Additionally, they (optionally) associate the classes
+ * they create with a code source and provide mechanisms to allow the relevant
+ * permissions to be retrieved.
+ * 
+ */
+
+public class SecureClassLoader extends ClassLoader {
+
+	/**
+	 * Maintain a map of CodeSources to ProtectionDomains so we do not have to
+	 * create a new one each time.
+	 */
+	private Hashtable domainForCodeSource = new Hashtable(10);
+
+	/**
+	 * Constructs a new instance of this class with the system class loader as
+	 * its parent.
+	 * 
+	 * @exception SecurityException
+	 *                if a security manager exists and it does not allow the
+	 *                creation of new ClassLoaders.
+	 */
+	protected SecureClassLoader() {
+		super();
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkCreateClassLoader();
+	}
+
+	/**
+	 * Constructs a new instance of this class with the given class loader as
+	 * its parent.
+	 * 
+	 * 
+	 * @param parentLoader
+	 *            ClassLoader the ClassLoader to use as the new class loaders
+	 *            parent.
+	 * @exception SecurityException
+	 *                if a security manager exists and it does not allow the
+	 *                creation of new ClassLoaders.
+	 * @exception NullPointerException
+	 *                if the parent is null.
+	 */
+	protected SecureClassLoader(ClassLoader parentLoader) {
+		super(parentLoader);
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkCreateClassLoader();
+	}
+
+	/**
+	 * Constructs a new class from an array of bytes containing a class
+	 * definition in class file format.
+	 * 
+	 * 
+	 * @return java.lang.Class the newly defined class.
+	 * @param className
+	 *            java.lang.String the name of the new class.
+	 * @param classRep
+	 *            byte[] a memory image of a class file.
+	 * @param offset
+	 *            int the offset into the classRep.
+	 * @param length
+	 *            int the length of the class file.
+	 * @param cs
+	 *            CodeSource the code source that the new class will be
+	 *            associated with.
+	 */
+
+	protected final Class defineClass(String className, byte[] classRep,
+			int offset, int length, final CodeSource cs) {
+		ProtectionDomain pd = null;
+		if (cs != null) {
+			pd = (ProtectionDomain) domainForCodeSource.get(cs);
+			if (pd == null) {
+				pd = new ProtectionDomain(cs, getPermissions(cs));
+				domainForCodeSource.put(cs, pd);
+			}
+		}
+		return defineClass(className, classRep, offset, length, pd);
+	}
+
+	/**
+	 * Answers the permission collection for the given code source. By default,
+	 * it just asks the installed Policy object.
+	 * 
+	 * 
+	 * @return PermissionCollection the permission collection for the code
+	 *         source.
+	 * @param codesource
+	 *            java.security.CodeSource the code source to check permissions
+	 *            for.
+	 */
+	protected PermissionCollection getPermissions(CodeSource codesource) {
+		return Policy.getPolicyImpl().getPermissions(codesource);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandom.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandom.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandom.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandom.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,411 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+
+/**
+ * For the generation of secure pseudo-random numbers.
+ */
+public class SecureRandom extends java.util.Random {
+	static final long serialVersionUID = 4940670005562187L;
+
+	// Algorithm name in case users call the empty constructor
+	private static final String DEFAULT_ALGORITHM_NAME = "SHA1PRNG"; 
+
+	// Key prefix for algorithm name lookup
+	private static final String KEY_PREFIX = "SecureRandom.";
+
+	private static SecureRandom DEFAULT = null; // Default instance for seed
+												// generation for static method
+												// getSeed
+
+	private Provider provider; // Provider of the secure hash algorithm
+
+	// Actual implementation for the secure hash algorithm
+	private SecureRandomSpi secureRandomSpi; 
+	
+	private byte[] state; // None of these are used, needed for serialization
+
+	private MessageDigest digest;
+
+	private byte[] randomBytes;
+
+	private int randomBytesUsed;
+
+	private long counter;
+
+	/**
+	 * Constructs a new instance of this class. Users are encouraged to use
+	 * <code>getInstance()</code> instead.
+	 * 
+	 * An implementation for the highest-priority provider is returned. The
+	 * instance returned will not have been seeded.
+	 */
+	public SecureRandom() {
+		super();
+		try {
+			SecureRandom sr = getInstance(DEFAULT_ALGORITHM_NAME);
+			this.secureRandomSpi = sr.secureRandomSpi;
+			this.provider = sr.provider;
+		} catch (NoSuchAlgorithmException e) {
+			// There should be at least a default implementation for secure
+			// random
+			throw new Error(e.toString());
+		}
+	}
+
+	/**
+	 * Constructs a new instance of this class. Users are encouraged to use
+	 * <code>getInstance()</code> instead.
+	 * 
+	 * An implementation for the highest-priority provider is returned. The
+	 * instance returned will be seeded with the parameter.
+	 * 
+	 * @param seed
+	 *            bytes forming the seed for this generator.
+	 */
+	public SecureRandom(byte[] seed) {
+		this();
+		setSeed(seed);
+	}
+
+	/**
+	 * Constructs a new instance of this class.
+	 * 
+	 * @param secureRandomSpi
+	 *            The actual provider-specific generator
+	 * @param provider
+	 *            The provider of the implementation
+	 */
+	protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider) {
+		super();
+		this.provider = provider;
+		this.secureRandomSpi = secureRandomSpi;
+	}
+
+	/**
+	 * Creates a SecureRandom for a given SecureRandomSpi from a provider
+	 * 
+	 * @param provider
+	 *            The provider that is supplying the implementation for the
+	 *            service
+	 * @param algorithmClass
+	 *            The class that implements the algorithm
+	 * @param algName
+	 *            The name of the algorithm
+	 * @return a SecureRandom
+	 * @throws NoSuchAlgorithmException 
+	 */
+	private static SecureRandom createSecureRandom(Provider provider,
+			Class algorithmClass, String algName)
+			throws NoSuchAlgorithmException {
+		try {
+			SecureRandomSpi secureRandomSpi = (SecureRandomSpi) algorithmClass
+					.newInstance();
+			SecureRandom result = new SecureRandom(secureRandomSpi, provider);
+			return result;
+		} catch (IllegalAccessException e) {
+			// Intentionally empty
+		} catch (InstantiationException e) {
+			// Intentionally empty
+		}
+
+		throw new NoSuchAlgorithmException(algName);
+	}
+
+	/**
+	 * Generates a certain number of seed bytes
+	 * 
+	 * 
+	 * @param numBytes
+	 *            int Number of seed bytes to generate
+	 * @return byte[] The seed bytes generated
+	 */
+	public byte[] generateSeed(int numBytes) {
+		return secureRandomSpi.engineGenerateSeed(numBytes);
+	}
+
+	/**
+	 * Answers a new SecureRandom which is capable of running the algorithm
+	 * described by the argument. The result will be an instance of a subclass
+	 * of SecureRandomSpi which implements that algorithm.
+	 * 
+	 * @param algorithmName
+	 *            java.lang.String Name of the algorithm desired
+	 * @return SecureRandom a concrete implementation for the algorithm desired.
+	 * 
+	 * @exception NoSuchAlgorithmException
+	 *                If the algorithm cannot be found
+	 */
+
+	public static SecureRandom getInstance(String algorithmName)
+			throws NoSuchAlgorithmException {
+		if (algorithmName == null)
+			throw new java.lang.IllegalArgumentException();
+
+		return toSecureRandomImplementation(algorithmName);
+	}
+
+	/**
+	 * Answers a new SecureRandom which is capable of running the algorithm
+	 * described by the argument. The result will be an instance of a subclass
+	 * of SecureRandomSpi which implements that algorithm.
+	 * 
+	 * @param algorithmName
+	 *            java.lang.String Name of the algorithm desired
+	 * @param providerName
+	 *            java.lang.String Name of the provider which has to implement
+	 *            the algorithm
+	 * @return SecureRandom a concrete implementation for the algorithm desired.
+	 * 
+	 * @exception NoSuchAlgorithmException
+	 *                If the algorithm cannot be found
+	 * @exception NoSuchProviderException
+	 *                If the provider cannot be found
+	 */
+	public static SecureRandom getInstance(String algorithmName,
+			String providerName) throws NoSuchAlgorithmException,
+			NoSuchProviderException {
+
+		if (providerName == null)
+			throw new java.lang.IllegalArgumentException();
+		if (algorithmName == null)
+			throw new java.lang.IllegalArgumentException();
+
+		Provider provider = Security.getProvider(providerName);
+		if (provider == null)
+			throw new NoSuchProviderException(providerName);
+
+		return toSecureRandomImplementation(algorithmName, provider);
+	}
+
+	/**
+	 * Answers a new SecureRandom which is capable of running the algorithm
+	 * described by the argument. The result will be an instance of a subclass
+	 * of SecureRandomSpi which implements that algorithm.
+	 * 
+	 * @param algorithm
+	 *            java.lang.String Name of the algorithm desired
+	 * @param provider
+	 *            java.security.Provider Provider which has to implement the
+	 *            algorithm
+	 * @return SecureRandom a concrete implementation for the algorithm desired.
+	 * 
+	 * @exception NoSuchAlgorithmException
+	 *                If the algorithm cannot be found
+	 */
+	public static SecureRandom getInstance(String algorithm, Provider provider)
+			throws NoSuchAlgorithmException {
+		if ((algorithm == null) || (provider == null)) {
+			throw new IllegalArgumentException();
+		}
+
+		return toSecureRandomImplementation(algorithm, provider);
+	}
+
+	/**
+	 * Returns the Provider of the secure random represented by the receiver.
+	 * 
+	 * @return Provider an instance of a subclass of java.security.Provider
+	 */
+	public final Provider getProvider() {
+		return provider;
+	}
+
+	/**
+	 * Returns the given number of seed bytes, computed using the seed
+	 * generation algorithm used by this class.
+	 * 
+	 * @param numBytes
+	 *            int the given number of seed bytes
+	 * @return byte[] The seed bytes generated
+	 */
+	public static byte[] getSeed(int numBytes) {
+		if (DEFAULT == null) {
+			DEFAULT = new SecureRandom();
+		}
+		byte[] result = new byte[numBytes];
+		DEFAULT.nextBytes(result);
+		return result;
+	}
+
+	/**
+	 * Generates an integer with a given number of pseudo-random bits.
+	 * 
+	 * @param numBits
+	 *            int Number of bits to use for the generation
+	 * @return an integer with a given number of pseudo-random bits
+	 */
+	protected final int next(int numBits) {
+		if (numBits == 0)
+			return 0;
+		int need = numBits / 8;
+		int extra = numBits - (need * 8);
+		if (extra > 0)
+			need++;
+		byte[] data = new byte[need];
+		nextBytes(data);
+		int result = data[0] & 0xff;
+		if (extra > 0)
+			result >>= (8 - extra);
+		for (int i = 1; i < need; i++)
+			result = result << 8 | (data[i] & 0xff);
+		return result;
+	}
+
+	/**
+	 * Generates a certain number of random bytes
+	 * 
+	 * 
+	 * @param bytes
+	 *            byte[] array to be filled with random bytes
+	 */
+	public void nextBytes(byte[] bytes) {
+		secureRandomSpi.engineNextBytes(bytes);
+	}
+
+	/**
+	 * Reseeds this random object
+	 * 
+	 * 
+	 * @param seed
+	 *            byte[] Bytes to use to reseed the receiver.
+	 */
+	public void setSeed(byte[] seed) {
+		secureRandomSpi.engineSetSeed(seed);
+	}
+
+	/**
+	 * Reseeds this random object with the eight bytes described by the
+	 * representation of the long provided.
+	 * 
+	 * 
+	 * @param seed
+	 *            long Number whose representation to use to reseed the
+	 *            receiver.
+	 */
+	public void setSeed(long seed) {
+		// For compatibility with Random. This is called by the empty
+		// constructor, but the receiver is still being constructed, so we
+		// must not forward to the concrete implementation if we have none.
+		if (secureRandomSpi == null)
+			return; // no-op when running constructor.
+
+		// A long representation is 8 bytes
+		byte[] representation = new byte[8];
+
+		for (int i = 7; i >= 0; i--) {
+			representation[i] = (byte) (seed & 0xFF);
+			seed = seed >>> 8;
+		}
+		setSeed(representation);
+	}
+
+	/**
+	 * Answers a class which implements the secure random algorithm named by the
+	 * argument. Check all providers for a matching algorithm.
+	 * 
+	 * @param algorithmName
+	 *            java.lang.String the name of the algorithm to search for
+	 * 
+	 * @return The secure random for the algorithm name supplied by any
+	 *         provider.
+	 * 
+	 * @throws NoSuchAlgorithmException
+	 *             If the provider does not implement such algorithm
+	 */
+	private static SecureRandom toSecureRandomImplementation(
+			String algorithmName) throws NoSuchAlgorithmException {
+
+		Provider[] providers = Security.getProviders();
+		for (int i = 0; i < providers.length; i++) {
+			Provider provider = providers[i];
+			try {
+				return toSecureRandomImplementation(algorithmName, provider);
+			} catch (NoSuchAlgorithmException e) {
+				// Just skip to next provider
+			}
+		}
+
+		// Scanned all, found nothing
+		throw new NoSuchAlgorithmException(algorithmName);
+	}
+
+	/**
+	 * Answers a SecureRandom for the algorithm name supplied by the given
+	 * provider.
+	 * 
+	 * @param algorithmName
+	 *            java.lang.String the name of the algorithm to search for
+	 * @param provider
+	 *            java.security.Provider the provider desired for the algorithm.
+	 * 
+	 * @return The secure random for the algorithm name supplied by the given
+	 *         provider.
+	 * 
+	 * @throws NoSuchAlgorithmException
+	 *             If the provider does not implement such algorithm
+	 */
+	private static SecureRandom toSecureRandomImplementation(
+			String algorithmName, Provider provider)
+			throws NoSuchAlgorithmException {
+
+		// First try to find the class corresponding to the algorithm name
+		String secureRandomClassName;
+		try {
+			secureRandomClassName = provider.lookupProperty(KEY_PREFIX,
+					algorithmName);
+		} catch (ClassCastException e) {
+			throw new NoSuchAlgorithmException(algorithmName);
+		}
+
+		// If not found, exception
+		if (secureRandomClassName == null)
+			throw new NoSuchAlgorithmException(algorithmName);
+
+		// Now try to instantiate the digest.
+		try {
+			Class secureRandomClass = Class.forName(secureRandomClassName,
+					true, provider.getClass().getClassLoader());
+			return createSecureRandom(provider, secureRandomClass,
+					algorithmName);
+		} catch (ClassNotFoundException ex) {
+			throw new NoSuchAlgorithmException(algorithmName);
+		}
+	}
+
+	private static final ObjectStreamField[] serialPersistentFields = {
+			// These fields are used
+			new ObjectStreamField("provider", Provider.class),
+			new ObjectStreamField("secureRandomSpi", SecureRandomSpi.class),
+			// These fields are for backwards compatibility
+			new ObjectStreamField("state", byte[].class),
+			new ObjectStreamField("digest", MessageDigest.class),
+			new ObjectStreamField("randomBytes", byte[].class),
+			new ObjectStreamField("randomBytesUsed", Integer.TYPE),
+			new ObjectStreamField("counter", Long.TYPE) };
+
+	private void writeObject(ObjectOutputStream stream) throws IOException {
+		ObjectOutputStream.PutField fields = stream.putFields();
+		fields.put("provider", provider);
+		fields.put("secureRandomSpi", secureRandomSpi);
+		stream.writeFields();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandomSpi.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandomSpi.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandomSpi.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecureRandomSpi.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,60 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.Serializable;
+
+/**
+ * This class is a Service Provider Interface (therefore the Spi suffix) for
+ * secure random number generation algorithms to be supplied by providers.
+ * 
+ */
+public abstract class SecureRandomSpi implements Serializable {
+	/**
+	 * Constructs a new instance of this class.
+	 */
+	public SecureRandomSpi() {
+		// Intentionally empty
+	}
+
+	/**
+	 * Generates a certain number of seed bytes
+	 * 
+	 * @param numBytes
+	 *            int Number of seed bytes to generate
+	 * @return byte[] The seed bytes generated
+	 */
+	protected abstract byte[] engineGenerateSeed(int numBytes);
+
+	/**
+	 * Generates a certain number of random bytes
+	 * 
+	 * 
+	 * @param bytes
+	 *            byte[] array to be filled with random bytes
+	 */
+	protected abstract void engineNextBytes(byte[] bytes);
+
+	/**
+	 * Reseeds this random object
+	 * 
+	 * 
+	 * @param seed
+	 *            byte[] The number of seed bytes to generate
+	 */
+	protected abstract void engineSetSeed(byte[] seed);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Security.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Security.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Security.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Security.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,615 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.Vector;
+
+/**
+ * For access to security providers and properties.
+ */
+public final class Security {
+	// List of alternating key-value pairs which represent the
+	// default content of the securityProperties collection.
+	private static final String[] defaultProperties = { "package.access",
+			"com.ibm.oti.", "policy.provider",
+			"com.ibm.oti.util.DefaultPolicy", "security.provider.1",
+			"com.ibm.oti.security.provider.OTI" };
+
+	// Security Properties.
+	private static final Properties securityProperties = loadSecurityProperties();
+
+	// Providers sorted by priority.
+	private static final Vector providersByPriority = new Vector();
+
+	// Associations between name and Provider.
+	private static final Hashtable providersByName = new Hashtable(20);
+
+	// have the providers been loaded and initialized?
+	private static boolean providersLoaded = false;
+
+	/**
+	 * Constructs a new instance of this class.
+	 * 
+	 */
+	private Security() {
+		super();
+	}
+
+	/**
+	 * Answers the value of the security property named by the argument.
+	 * 
+	 * 
+	 * @param key
+	 *            String The property name
+	 * @return String The property value
+	 * 
+	 * @exception SecurityException
+	 *                If there is a SecurityManager installed and it will not
+	 *                allow the property to be fetched from the current access
+	 *                control context.
+	 */
+	public static String getProperty(String key) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkPermission(new SecurityPermission("getProperty."
+					+ key));
+		return securityProperties.getProperty(key);
+	}
+
+	/**
+	 * Sets a given security property.
+	 * 
+	 * 
+	 * @param key
+	 *            String The property name.
+	 * @param datum
+	 *            String The property value.
+	 * @exception SecurityException
+	 *                If there is a SecurityManager installed and it will not
+	 *                allow the property to be set from the current access
+	 *                control context.
+	 */
+	public static void setProperty(String key, String datum) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkPermission(new SecurityPermission("setProperty."
+					+ key));
+		securityProperties.put(key, datum);
+	}
+
+	/**
+	 * Adds the extra provider to the collection of providers.
+	 * @param provider 
+	 * 
+	 * @return int The priority/position of the provider added.
+	 * @exception SecurityException
+	 *                If there is a SecurityManager installed and it denies
+	 *                adding a new provider.
+	 */
+	public static int addProvider(Provider provider) {
+		// must load providers before getting size
+		if (!providersLoaded)
+			loadSecurityProviders();
+		synchronized (providersByPriority) {
+			return insertProviderAt(provider, providersByPriority.size() + 1);
+		}
+	}
+
+	/**
+	 * Answers a Provider for a given name.
+	 * 
+	 * 
+	 * @param providerName
+	 *            java.lang.String Name of the provider we are trying to find.
+	 * @return Provider if a provider was found, or <code>null</code> if there
+	 *         was no such provider.
+	 */
+	public static Provider getProvider(String providerName) {
+		if (!providersLoaded)
+			loadSecurityProviders();
+		return (Provider) providersByName.get(providerName);
+	}
+
+	/**
+	 * Answers a collection of installed providers.
+	 * 
+	 * 
+	 * @return Provider[] a collection of <code>provider</code> installed.
+	 */
+	public static Provider[] getProviders() {
+		if (!providersLoaded)
+			loadSecurityProviders();
+		synchronized (providersByPriority) {
+			Provider[] result = new Provider[providersByPriority.size()];
+			providersByPriority.copyInto(result);
+			return result;
+		}
+	}
+
+	/**
+	 * Constant value for criteria
+	 */
+	private final static int CRYPTO_SERVICE = 0;
+
+	private final static int ALGORITHM_OR_TYPE = 1;
+
+	private final static int ATTRIBUTE_NAME = 2;
+
+	private final static int ATTRIBUTE_VALUE = 3;
+
+	/**
+	 * Check attribute value
+	 * 
+	 * 
+	 * @param attrName
+	 *            String attribute name
+	 * @param attrValue
+	 *            String attribute value
+	 * @param sourceValue
+	 *            String provider supports this attribute value
+	 * 
+	 * @return boolean true, if condition for attribute is true
+	 * 
+	 */
+	private static boolean checkAttribute(String attrName, String attrValue,
+			String sourceValue) {
+		if (attrValue.length() == 0)
+			return true;
+
+		try {
+			int v1 = Integer.parseInt(sourceValue);
+			int v2 = Integer.parseInt(attrValue);
+			return v1 >= v2;
+		} catch (NumberFormatException e) {
+		}
+		return sourceValue.equals(attrValue);
+	}
+
+	/**
+	 * Parser for filter
+	 * 
+	 * 
+	 * @param filter
+	 *            String the criteria for selecting providers
+	 * 
+	 * @return String[] A list of filter's element for selecting providers
+	 *         {CRYPTO_SERVICE,ALGORITHM_OR_TYPE,ATTRIBUTE_NAME,ATTRIBUTE_VALUE}
+	 */
+	private static String[] parserOfFilter(String filter) {
+		// criterion
+		String[] filters = { null, null, null, null };
+		char[] ch = { '.', ' ', ':' };
+		// parser
+		int begin = 0;
+		int end = 0;
+		int length = filter.length();
+		int i = 0;
+		for (i = 0; (i < ch.length) && (begin < length) && (end != -1); i++) {
+			end = filter.indexOf(ch[i], begin);
+			if (end == -1) {
+				filters[i] = new String(filter.substring(begin, length));
+				break;
+			}
+			filters[i] = new String(filter.substring(begin, end));
+			begin = end + 1;
+			while (begin < length && filter.charAt(begin) == ' ')
+				begin++;
+		}
+		if (end != -1)
+			filters[i] = new String(filter.substring(begin, length));
+		return filters;
+	}
+
+	private static Provider[] getProvidersUsingFilters(Provider[] providers,
+			String[] filters, int typeOfFilter) {
+
+		int numberOfProviders = providers.length;
+
+		if (numberOfProviders > 0) {
+
+			String bufKey = filters[CRYPTO_SERVICE] + "."
+					+ filters[ALGORITHM_OR_TYPE];
+			String algAlias = "Alg.Alias." + bufKey;
+
+			boolean isNotFound = true;
+
+			for (int i = 0; i < providers.length; i++) {
+				isNotFound = true;
+
+				String key = bufKey;
+
+				String alias = providers[i].getProperty(algAlias);
+				if (alias != null) {
+					key = filters[CRYPTO_SERVICE] + "." + alias;
+				}
+
+				String property = providers[i].getProperty(key);
+				if (property != null) {
+					if (typeOfFilter == 1) {
+						isNotFound = false;
+					} else if (typeOfFilter == 2) {
+						key = key + ' ' + filters[ATTRIBUTE_NAME];
+
+						String value = providers[i].getProperty(key);
+
+						if (value != null) {
+							if (checkAttribute(filters[ATTRIBUTE_NAME],
+									filters[ATTRIBUTE_VALUE], value))
+								isNotFound = false;
+						}
+					}
+				}
+
+				if (isNotFound) {
+					providers[i] = null;
+					numberOfProviders--;
+				}
+			}
+
+			if (numberOfProviders > 0) {
+				Provider[] filterResult = new Provider[numberOfProviders];
+				int j = 0;
+				for (int i = 0; i < providers.length; i++) {
+					if (providers[i] != null) {
+						filterResult[j++] = providers[i];
+					}
+				}
+				providers = filterResult;
+			} else {
+				providers = null;
+			}
+		} else {
+			providers = null;
+		}
+		return providers;
+	}
+
+	/**
+	 * Returns the collection of providers which meet the user supplied string
+	 * filter.
+	 * 
+	 * @param filter
+	 *            case-insensitive filter
+	 * @return the providers which meet the user supplied string filter
+	 *         <code>filter</code>. A <code>null</code> value signifies
+	 *         that none of the installed providers meets the filter
+	 *         specification
+	 * @exception InvalidParameterException
+	 *                if an unusable filter is supplied
+	 */
+	public static Provider[] getProviders(String filter) {
+		Provider[] providers = getProviders();
+		if (providers.length == 0)
+			return null;
+		String[] filters = parserOfFilter(filter);
+		int typeOfFilter = 0;
+		if (filters[CRYPTO_SERVICE] != null
+				&& filters[ALGORITHM_OR_TYPE] != null) {
+			if (filters[ATTRIBUTE_NAME] != null
+					|| filters[ATTRIBUTE_VALUE] != null) {
+				if (filters[ATTRIBUTE_NAME] != null
+						&& filters[ATTRIBUTE_VALUE] != null) {
+					if (filters[ATTRIBUTE_NAME].length() > 0) {
+						typeOfFilter = 2;
+					} else if (filters[ATTRIBUTE_VALUE].length() == 0) {
+						typeOfFilter = 1;
+					}
+				}
+			} else {
+				if (filters[ALGORITHM_OR_TYPE].length() > 0)
+					typeOfFilter = 1;
+			}
+		}
+		if (typeOfFilter == 0)
+			throw new InvalidParameterException(com.ibm.oti.util.Msg
+					.getString("K01a6"));
+		return getProvidersUsingFilters(providers, filters, typeOfFilter);
+	}
+
+	/**
+	 * Returns the collection of providers which meet the user supplied map of
+	 * string filter values.
+	 * 
+	 * @param filter
+	 *            a {@link Map} of case-insensitive filter strings each of which
+	 *            must be satisfied before a provider is included as an element
+	 *            in the return value.
+	 * @return the providers which meet the user supplied string filter
+	 *         <code>filter</code>. A <code>null</code> value signifies
+	 *         that none of the installed providers meets the filter
+	 *         specification
+	 * @exception InvalidParameterException
+	 *                if any of the supplied filters are unusable
+	 */
+	public static Provider[] getProviders(Map filter) {
+		Provider[] providers = getProviders();
+		if (providers.length == 0)
+			return null;
+		if (filter == null)
+			return providers;
+		Set keySet = filter.keySet();
+		if (keySet == null)
+			return providers;
+		Iterator keys = keySet.iterator();
+		String key;
+		String value;
+		String[] filters;
+		int typeOfFilter;
+		while (keys.hasNext()) {
+			key = (String) keys.next();
+			value = (String) filter.get(key);
+			filters = parserOfFilter(key);
+			typeOfFilter = 0;
+			if (filters[CRYPTO_SERVICE] != null
+					&& filters[ALGORITHM_OR_TYPE] != null) {
+				if (filters[ATTRIBUTE_NAME] != null) {
+					if (filters[ATTRIBUTE_VALUE] != null) {
+						throw new InvalidParameterException(
+								com.ibm.oti.util.Msg.getString("K01a6"));
+					}
+					// <crypto_service>.<algorithm_or_type> <attribute_name>
+					if (value.length() >= 0) {
+						// <crypto_service>.<algorithm_or_type>
+						// <attribute_name>:<attribute_value>
+						typeOfFilter = 2;
+						filters[ATTRIBUTE_VALUE] = value;
+					}
+				} else if (value.length() == 0) {
+					// <crypto_service>.<algorithm_or_type>
+					if (filters[ALGORITHM_OR_TYPE].length() > 0)
+						typeOfFilter = 1;
+				}
+			}
+			if (typeOfFilter == 0)
+				throw new InvalidParameterException(com.ibm.oti.util.Msg
+						.getString("K01a6"));
+			providers = getProvidersUsingFilters(providers, filters,
+					typeOfFilter);
+			if (providers == null)
+				return null;
+		}
+		return providers;
+	}
+
+	/**
+	 * Adds a provider to the collection of providers, at the specified
+	 * position.
+	 * @param provider 
+	 * @param position 
+	 * 
+	 * @return int The priority/position where the provider was actually added.
+	 * @exception SecurityException
+	 *                If there is a SecurityManager installed and it will not
+	 *                allow a new provider to be installed from the current
+	 *                access control context.
+	 */
+	public static int insertProviderAt(Provider provider, int position) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security
+					.checkSecurityAccess("insertProvider." + provider.getName());
+		if (!providersLoaded)
+			loadSecurityProviders();
+		return insertAt(provider, position);
+	}
+
+	private static int insertAt(Provider provider, int position) {
+		synchronized (providersByPriority) {
+			if (providersByName.get(provider.getName()) != null)
+				// Already registered, no-op and return -1
+				return -1;
+
+			// First adjust, positions are 1-based and Vector is 0-based
+			position--;
+			if (position < 0 || position > providersByPriority.size())
+				position = providersByPriority.size();
+			providersByPriority.insertElementAt(provider, position);
+			providersByName.put(provider.getName(), provider);
+		}
+		// Now adjust again to 1-based offset
+		return ++position;
+	}
+
+	/**
+	 * Removes the provider from the collection of providers.
+	 * 
+	 * 
+	 * @param name
+	 *            String The name of the provider to remove.
+	 * @exception SecurityException
+	 *                If there is a SecurityManager installed and it will not
+	 *                allow the provider to be removed by code in the current
+	 *                access control context.
+	 */
+	public static void removeProvider(String name) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkSecurityAccess("removeProvider." + name);
+		if (!providersLoaded)
+			loadSecurityProviders();
+		synchronized (providersByPriority) {
+			int foundIndex = -1;
+			for (int i = 0; i < providersByPriority.size(); i++) {
+				Provider p = (Provider) providersByPriority.elementAt(i);
+				if (name.equals(p.getName())) {
+					foundIndex = i;
+					break;
+				}
+			}
+			if (foundIndex >= 0) {
+				// Found something
+				providersByPriority.removeElementAt(foundIndex);
+				providersByName.remove(name);
+			}
+		}
+	}
+
+	public static Set getAlgorithms(String serviceName) {
+
+		Set result = new TreeSet();
+
+		Provider[] providers = getProviders();
+		for (int i = 0; i < providers.length; i++) {
+
+			Provider p = providers[i];
+			Set s = p.keySet();
+
+			String searchName = serviceName.toLowerCase();
+
+			for (Iterator iter = s.iterator(); iter.hasNext();) {
+				String element = (String) iter.next();
+				String searchElement = element.toLowerCase();
+				if (searchElement.indexOf(searchName) == 0) {
+					int sepIndex = element.indexOf('.');
+					String algorithm = element.substring(sepIndex + 1);
+					result.add(algorithm);
+				}
+			}
+
+		}
+
+		return result;
+
+	}
+
+	/**
+	 * Answers with the default security properties for the case where the
+	 * receiver was not able to read the java.security file
+	 * 
+	 * 
+	 * @return Properties A list of properties as defined in defaultProperties
+	 */
+	private static Properties loadDefaultProperties() {
+		// Initialize the properties collection.
+		Properties sp = new Properties();
+		for (int i = 0; i < defaultProperties.length; i += 2)
+			sp.put(defaultProperties[i], defaultProperties[i + 1]);
+		return sp;
+	}
+
+	/**
+	 * Answers with the default security properties for the case where the
+	 * receiver was not able to read the java.security file
+	 * 
+	 * 
+	 * @return Properties A list of properties as defined in defaultProperties
+	 */
+	private static Properties loadSecurityProperties() {
+		Properties sp = null;
+		String javahome = System.getProperty("java.home");
+		String securityPropertiesFileName = new StringBuffer(
+				javahome.length() + 30)
+				.append(javahome)
+				.append(
+						System.getProperty("file.separator").equals("\\") ? "\\lib\\security\\java.security"
+								: "/lib/security/java.security").toString();
+		File securityPropertiesFile = new File(securityPropertiesFileName);
+		if (securityPropertiesFile.exists()) {
+			InputStream in = null;
+			try {
+				in = new BufferedInputStream(new FileInputStream(
+						securityPropertiesFile));
+				sp = new Properties();
+				sp.load(in);
+
+				// trim trailing whitespace
+				Enumeration keyEnum = sp.keys();
+				while (keyEnum.hasMoreElements()) {
+					String key = (String) keyEnum.nextElement();
+					sp.put(key, ((String) sp.get(key)).trim());
+				}
+			} catch (FileNotFoundException e) {
+				// shouldn't happen
+			} catch (IOException e) {
+				sp = null;
+			} finally {
+				if (in != null) {
+					try {
+						in.close();
+					} catch (IOException e) {
+					}
+				}
+			}
+		}
+		// if the java.security file load failed, use the default system ones
+		if (sp == null)
+			sp = loadDefaultProperties();
+
+		return sp;
+	}
+
+	/**
+	 * Loads and initializes the security providers specified in the security
+	 * properties list.
+	 * 
+	 * 
+	 */
+	private static void loadSecurityProviders() {
+		synchronized (providersByPriority) {
+			// needed for syncronization issues
+			if (providersLoaded)
+				return;
+			// must be set before calling addProvider()
+			providersLoaded = true;
+			AccessController.doPrivileged(new PrivilegedAction() {
+				public Object run() {
+					int providerNum = 1;
+					String providerName;
+					while ((providerName = getProperty("security.provider."
+							+ providerNum++)) != null) {
+						try {
+							Class providerClass = Class.forName(providerName,
+									true, ClassLoader.getSystemClassLoader());
+							Provider provider = (Provider) providerClass
+									.newInstance();
+							insertAt(provider, providersByPriority.size() + 1);
+						} catch (ClassNotFoundException cnf) {
+						} catch (IllegalAccessException iae) {
+						} catch (InstantiationException ie) {
+						}
+					}
+					return null;
+				}
+			});
+		}
+	}
+
+	/**
+	 * Deprecated method which returns null.
+	 * @param algorithm 
+	 * @param property 
+	 * @return <code>null</code>
+	 *
+	 * @deprecated	Use AlgorithmParameters and KeyFactory instead
+	 */
+	public static String getAlgorithmProperty(String algorithm, String property) {
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecurityPermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecurityPermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecurityPermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/SecurityPermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,58 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * SecurityPermission objects guard access to the mechanisms which implement
+ * security. Security permissions have names, but not actions.
+ * 
+ */
+public final class SecurityPermission extends BasicPermission {
+	static final long serialVersionUID = 5236109936224050470L;
+
+	/**
+	 * Constants for security permissions used in this package.
+	 */
+	static final SecurityPermission permissionToGetPolicy = new SecurityPermission(
+			"getPolicy");
+
+	static final SecurityPermission permissionToSetPolicy = new SecurityPermission(
+			"setPolicy");
+
+	/**
+	 * Creates an instance of this class with the given name.
+	 * 
+	 * @param name
+	 *            String the name of the new permission.
+	 */
+	public SecurityPermission(String name) {
+		super(name);
+	}
+
+	/**
+	 * Creates an instance of this class with the given name and action list.
+	 * The action list is ignored.
+	 * 
+	 * @param name
+	 *            String the name of the new permission.
+	 * @param actions
+	 *            String ignored.
+	 */
+	public SecurityPermission(String name, String actions) {
+		super(name, actions);
+	}
+}



Mime
View raw message