Index: vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
===================================================================
--- vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java (revision 529804)
+++ vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java (working copy)
@@ -28,7 +28,7 @@
import java.util.Map;
import org.apache.harmony.lang.RuntimePermissionCollection;
-import org.apache.harmony.fortress.security.SecurityUtils;
+import org.apache.harmony.security.fortress.SecurityUtils;
import org.apache.harmony.vm.VMStack;
/**
Index: vm/vmcore/src/kernel_classes/javasrc/java/security/AccessControlContext.java
===================================================================
--- vm/vmcore/src/kernel_classes/javasrc/java/security/AccessControlContext.java (revision 529804)
+++ vm/vmcore/src/kernel_classes/javasrc/java/security/AccessControlContext.java (working copy)
@@ -22,7 +22,7 @@
package java.security;
import java.util.ArrayList;
-import org.apache.harmony.fortress.security.PolicyUtils;
+import org.apache.harmony.security.fortress.PolicyUtils;
/**
* @com.intel.drl.spec_ref
Index: vm/vmcore/src/kernel_classes/javasrc/java/security/AccessController.java
===================================================================
--- vm/vmcore/src/kernel_classes/javasrc/java/security/AccessController.java (revision 529804)
+++ vm/vmcore/src/kernel_classes/javasrc/java/security/AccessController.java (working copy)
@@ -20,7 +20,7 @@
import java.util.ArrayList;
import java.util.WeakHashMap;
-import org.apache.harmony.fortress.security.SecurityUtils;
+import org.apache.harmony.security.fortress.SecurityUtils;
/**
* @com.intel.drl.spec_ref
Index: vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/fortress/security/PolicyUtils.java
===================================================================
--- vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/fortress/security/PolicyUtils.java (revision 530008)
+++ vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/fortress/security/PolicyUtils.java (working copy)
@@ -1,571 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-/**
-* @author Alexey V. Varlamov
-* @version $Revision: 1.1.6.4 $
-*/
-
-package org.apache.harmony.fortress.security;
-
-import java.io.File;
-import java.lang.reflect.Constructor;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Permissions;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
-import java.security.Security;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * This class consist of a number of static methods, which provide a common functionality
- * for various policy and configuration providers.
- *
- */
-public class PolicyUtils {
-
- // No reason to instantiate
- private PolicyUtils() {}
-
- /**
- * Auxiliary action for opening InputStream from specified location.
- */
- public static class URLLoader implements PrivilegedExceptionAction {
-
- /**
- * URL of target location.
- */
- public URL location;
-
- /**
- * Constructor with target URL parameter.
- */
- public URLLoader(URL location) {
- this.location = location;
- }
-
- /**
- * Returns InputStream from the target URL.
- */
- public Object run() throws Exception {
- return location.openStream();
- }
- }
-
- /**
- * Auxiliary action for accessing system properties in a bundle.
- */
- public static class SystemKit implements PrivilegedAction {
-
- /**
- * Returns system properties.
- */
- public Object run() {
- return System.getProperties();
- }
- }
-
- /**
- * Auxiliary action for accessing specific system property.
- */
- public static class SystemPropertyAccessor implements PrivilegedAction {
-
- /**
- * A key of a required system property.
- */
- public String key;
-
- /**
- * Constructor with a property key parameter.
- */
- public SystemPropertyAccessor(String key) {
- this.key = key;
- }
-
- /**
- * Handy one-line replacement of
- * "provide key and supply action" code block,
- * for reusing existing action instance.
- */
- public PrivilegedAction key(String key) {
- this.key = key;
- return this;
- }
-
- /**
- * Returns specified system property.
- */
- public Object run() {
- return System.getProperty(key);
- }
- }
-
- /**
- * Auxiliary action for accessing specific security property.
- */
- public static class SecurityPropertyAccessor extends SystemPropertyAccessor {
-
- /**
- * Constructor with a property key parameter.
- */
- public SecurityPropertyAccessor(String key) {
- super(key);
- }
-
- /**
- * Returns specified security property.
- */
- public Object run() {
- return Security.getProperty(key);
- }
- }
-
- /**
- * Auxiliary action for loading a provider by specific security property.
- */
- public static class ProviderLoader extends SystemPropertyAccessor {
-
- /**
- * Acceptable provider superclass.
- */
- public Class expectedType;
-
- /**
- * Constructor taking property key and acceptable provider
- * superclass parameters.
- */
- public ProviderLoader(String key, Class expected) {
- super(key);
- expectedType = expected;
- }
-
- /**
- * Returns provider instance by specified security property.
- * The key should map to a fully qualified classname.
- *
- * @throws SecurityException if no value specified for the key
- * in security properties or if an Exception has occured
- * during classloading and instantiating.
- */
- public Object run() {
- String klassName = Security.getProperty(key);
- if (klassName == null || klassName.length() == 0) {
- throw new SecurityException("Provider implementation should be specified via \""
- + key + "\" security property");
- }
- // TODO accurate classloading
- try {
- Class klass = Class.forName(klassName, true,
- Thread.currentThread().getContextClassLoader());
- if (expectedType != null && klass.isAssignableFrom(expectedType)){
- throw new SecurityException("Provided class "
- + klassName
- + " does not implement "
- + expectedType.getName());
- }
- return klass.newInstance();
- }
- catch (SecurityException se){
- throw se;
- }
- catch (Exception e) {
- // TODO log error ??
- SecurityException se = new SecurityException(
- "Unable to instantiate provider : " + klassName);
- se.initCause(e);
- throw se;
- }
- }
- }
-
- /**
- * Specific exception to signal that property expansion failed
- * due to unknown key.
- */
- public static class ExpansionFailedException extends Exception {
-
- /**
- * Constructor with user-friendly message parameter.
- */
- public ExpansionFailedException(String message) {
- super(message);
- }
-
- /**
- * Constructor with user-friendly message and causing error.
- */
- public ExpansionFailedException(String message, Throwable cause) {
- super(message, cause);
- }
- }
-
- /**
- * Substitutes all entries like ${some.key}, found in specified string,
- * for specified values.
- * If some key is unknown, throws ExpansionFailedException.
- * @param str the string to be expanded
- * @param properties available key-value mappings
- * @return expanded string
- * @throws ExpansionFailedException
- */
- public static String expand(String str, Properties properties)
- throws ExpansionFailedException {
- final String START_MARK = "${";
- final String END_MARK = "}";
- final int START_OFFSET = START_MARK.length();
- final int END_OFFSET = END_MARK.length();
-
- StringBuffer result = new StringBuffer(str);
- int start = result.indexOf(START_MARK);
- while (start >= 0) {
- int end = result.indexOf(END_MARK, start);
- if (end >= 0) {
- String key = result.substring(start + START_OFFSET, end);
- String value = properties.getProperty(key);
- if (value != null) {
- result.replace(start, end + END_OFFSET, value);
- start += value.length();
- } else {
- throw new ExpansionFailedException("Unknown key: " + key);
- }
- }
- start = result.indexOf(START_MARK, start);
- }
- return result.toString();
- }
-
- /**
- * Handy shortcut for
- * expand(str, properties).replace(File.separatorChar, '/').
- * @see #expand(String, Properties)
- */
- public static String expandURL(String str, Properties properties)
- throws ExpansionFailedException {
- return expand(str, properties).replace(File.separatorChar, '/');
- }
-
- /**
- * Instances of this interface are intended for resolving
- * generalized expansion expressions, of the form ${{protocol:data}}.
- * Such functionality is applicable to security policy files, for example.
- * @see org.apache.harmony.security.PolicyUtils#expandGeneral(String, GeneralExpansionHandler)
- */
- public static interface GeneralExpansionHandler {
-
- /**
- * Resolves general expansion expressions of the form ${{protocol:data}}.
- * @param protocol denotes type of resolution
- * @param data data to be resolved, optional (may be null)
- * @return resolved value, must not be null
- * @throws PolicyUtils.ExpansionFailedException if expansion is impossible
- */
- String resolve(String protocol, String data)
- throws ExpansionFailedException;
- }
-
- /**
- * Substitutes all entries like ${{protocol:data}}, found in specified string,
- * for values resolved by passed handler.
- * The data part may be empty, and in this case expression
- * may have simplified form, as ${{protocol}}.
- * If some entry cannot be resolved, throws ExpansionFailedException;
- * @param str the string to be expanded
- * @param handler the handler to resolve data denoted by protocol
- * @return expanded string
- * @throws ExpansionFailedException
- */
- public static String expandGeneral(String str,
- GeneralExpansionHandler handler) throws ExpansionFailedException {
- final String START_MARK = "${{";
- final String END_MARK = "}}";
- final int START_OFFSET = START_MARK.length();
- final int END_OFFSET = END_MARK.length();
-
- StringBuffer result = new StringBuffer(str);
- int start = result.indexOf(START_MARK);
- while (start >= 0) {
- int end = result.indexOf(END_MARK, start);
- if (end >= 0) {
- String key = result.substring(start + START_OFFSET, end);
- int separator = key.indexOf(':');
- String protocol = (separator >= 0) ? key
- .substring(0, separator) : key;
- String data = (separator >= 0) ? key.substring(separator + 1)
- : null;
- String value = handler.resolve(protocol, data);
- result.replace(start, end + END_OFFSET, value);
- start += value.length();
- }
- start = result.indexOf(START_MARK, start);
- }
- return result.toString();
- }
-
- /**
- * A key to security properties, deciding whether usage of
- * dynamic policy location via system properties is allowed.
- * @see #getPolicyURLs(Properties, String, String)
- */
- public static final String POLICY_ALLOW_DYNAMIC = "policy.allowSystemProperty";
-
- /**
- * A key to security properties, deciding whether expansion of
- * system properties is allowed
- * (in security properties values, policy files, etc).
- * @see #expand(String, Properties)
- */
- public static final String POLICY_EXPAND = "policy.expandProperties";
-
- /**
- * Positive value of switching properties.
- */
- public static final String TRUE = "true";
-
- /**
- * Negative value of switching properties.
- */
- public static final String FALSE = "false";
-
- /**
- * Returns false if current security settings disable to perform
- * properties expansion, true otherwise.
- * @see #expand(String, Properties)
- */
- public static boolean canExpandProperties() {
- return !FALSE.equalsIgnoreCase((String) AccessController
- .doPrivileged(new SecurityPropertyAccessor(POLICY_EXPAND)));
- }
-
- /**
- * Obtains a list of locations for a policy or configuration provider.
- * The search algorithm is as follows:
- *
prefix + n,
- * where n is an integer and prefix is a passed parameter.
- * Sequence starts with n=1, and keeps incrementing n
- * until next key is not found. what array are all
- * presented in where array.
- *
- * @param what first array, may be null
- * @param where second array, may be null
- * @return true if the first array is null
- * or if each and every object (ignoring null values)
- * from the first array has a twin in the second array; false otherwise
- */
- public static boolean matchSubset(Object[] what, Object[] where) {
- if (what == null) {
- return true;
- }
-
- for (int i = 0; i < what.length; i++) {
- if (what[i] != null) {
- if (where == null) {
- return false;
- }
- boolean found = false;
- for (int j = 0; j < where.length; j++) {
- if (what[i].equals(where[j])) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
- }
- return true;
- }
-}
\ No newline at end of file
Index: vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/fortress/security/SecurityUtils.java
===================================================================
--- vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/fortress/security/SecurityUtils.java (revision 530008)
+++ vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/fortress/security/SecurityUtils.java (working copy)
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-/**
-* @author Alexander V. Astapchuk
-* @version $Revision: 1.1.6.3 $
-*/
-
-package org.apache.harmony.fortress.security;
-
-import java.security.AccessControlContext;
-import java.util.WeakHashMap;
-
-//FIXME: move this class under umbrella of protected packages -
-// see lib/java.security: property 'package.access',
-// so only trusted classes like Thread and AccessController will
-// have an access to this class.
-// This is to remove dependency on VMStack, to reduce number
-// of VM2API-dependent classes.
-
-/**
- * The class is used to perform an exchange of information between
- * java.lang.Thread and java.security.AccessController.
- *
- * Thread() {
- *
- * The method throws SecurityException if the method is called more than
- * once for a given thread. The first call to
- * SecurityUtils.putContext(this,AccessController.getContext());
- * ...do the stuff you need...
- * }
- * putContext is
- * always performed in the Thread's constructor so this effectively means
- * that no one can replace the snapshot taken.
- *
- * @throws SecurityException if a context for the passed
- * thread already exists in the map.
- * @throws NullPointerException if thread is null
- * @throws Error if context is null AND if null context is already stored
- * in the map
- */
- public static void putContext(Thread thread, AccessControlContext context)
- throws SecurityException {
- if (thread == null) {
- throw new NullPointerException("thread can not be null");
- }
- synchronized (map) {
- if (map.containsKey(thread)) {
- throw new SecurityException("You can not modify this map.");
- }
- if (context == null) {
- // this only allowed once - for the very first thread.
- if (map.containsValue(null)) {
- throw new Error("null context may be stored only once.");
- }
- }
- map.put(thread, context);
- }
- }
-
- /**
- * Returns the AccessControlContext stored for a given thread.
- * The method may return null - for the very first thread created
- * by the VM which does not have inherited context.
- * It may also return null if no Thread found in the map - that seems
- * possible during VM startup process.
- */
- public static AccessControlContext getContext(Thread thread)
- throws SecurityException {
-
- // ~fixme: see 'fixme' at the top of the file
- /*
- Class cl = VMStack.getCallerClass(0);
- if (cl != AccessController.class) {
- throw new SecurityException("You ["+cl+"] do not have access to this resource.");
- }
- */
-
- synchronized (map) {
- return map.get(thread);
- }
- }
-}
\ No newline at end of file