You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/09/15 03:25:02 UTC
svn commit: r443541 - in
/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel:
.settings/ META-INF/ make/ src/main/java/java/security/
Author: ndbeyer
Date: Thu Sep 14 18:25:01 2006
New Revision: 443541
URL: http://svn.apache.org/viewvc?view=rev&rev=443541
Log:
Set eol-style = native for security-kernel module.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.core.prefs (contents, props changed)
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.ui.prefs (contents, props changed)
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.pde.core.prefs (contents, props changed)
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/META-INF/MANIFEST.MF (contents, props changed)
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/make/patternset.txt (contents, props changed)
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessControlContext.java (contents, props changed)
incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessController.java (contents, props changed)
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.core.prefs?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.core.prefs (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.core.prefs Thu Sep 14 18:25:01 2006
@@ -1,12 +1,12 @@
-#Wed May 03 13:10:22 BST 2006
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+#Wed May 03 13:10:22 BST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.core.prefs
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.ui.prefs
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.ui.prefs?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.ui.prefs (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.ui.prefs Thu Sep 14 18:25:01 2006
@@ -1,3 +1,3 @@
-#Wed May 03 13:10:00 BST 2006
-eclipse.preferences.version=1
-internal.default.compliance=user
+#Wed May 03 13:10:00 BST 2006
+eclipse.preferences.version=1
+internal.default.compliance=user
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.jdt.ui.prefs
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.pde.core.prefs
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.pde.core.prefs?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.pde.core.prefs (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.pde.core.prefs Thu Sep 14 18:25:01 2006
@@ -1,4 +1,4 @@
-#Wed Apr 05 20:59:48 BST 2006
-eclipse.preferences.version=1
-pluginProject.equinox=false
-pluginProject.extensions=false
+#Wed Apr 05 20:59:48 BST 2006
+eclipse.preferences.version=1
+pluginProject.equinox=false
+pluginProject.extensions=false
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/.settings/org.eclipse.pde.core.prefs
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/META-INF/MANIFEST.MF?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/META-INF/MANIFEST.MF (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/META-INF/MANIFEST.MF Thu Sep 14 18:25:01 2006
@@ -1,9 +1,9 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Harmony Security Kernel
-Fragment-Host: org.apache.harmony.security;bundle-version="1.0.0"
-Bundle-SymbolicName: org.apache.harmony.security.kernel
-Bundle-Version: 1.0.0
-Bundle-ClassPath: .
-Eclipse-JREBundle: true
-Export-Package: java.security
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Harmony Security Kernel
+Fragment-Host: org.apache.harmony.security;bundle-version="1.0.0"
+Bundle-SymbolicName: org.apache.harmony.security.kernel
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Eclipse-JREBundle: true
+Export-Package: java.security
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/make/patternset.txt
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/make/patternset.txt?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/make/patternset.txt (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/make/patternset.txt Thu Sep 14 18:25:01 2006
@@ -1,18 +1,18 @@
-# Copyright 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.
-
-java/security/AccessController.*
-java/security/AccessController$*.*
-java/security/AccessControlContext.*
-java/security/AccessControlContext$*.*
+# Copyright 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.
+
+java/security/AccessController.*
+java/security/AccessController$*.*
+java/security/AccessControlContext.*
+java/security/AccessControlContext$*.*
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/make/patternset.txt
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessControlContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessControlContext.java?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessControlContext.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessControlContext.java Thu Sep 14 18:25:01 2006
@@ -1,163 +1,163 @@
-/* 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;
-
-/**
- * The vm vendor may choose to implement this class. The reference
- * implementation must be used if the reference implementation of
- * AccessController is used.
- *
- * An AccessControlContext encapsulates the information which is needed by class
- * AccessController to detect if a Permission would be granted at a particular
- * point in a programs execution.
- *
- */
-
-public final class AccessControlContext {
- DomainCombiner domainCombiner;
-
- ProtectionDomain[] domainsArray;
-
- private static final SecurityPermission createAccessControlContext = new SecurityPermission(
- "createAccessControlContext");
-
- private static final SecurityPermission getDomainCombiner = new SecurityPermission(
- "getDomainCombiner");
-
- /**
- * Constructs a new instance of this class given an array of protection
- * domains.
- *
- */
- public AccessControlContext(ProtectionDomain[] context) {
- int length = context.length;
- int domainIndex = 0;
- this.domainsArray = new ProtectionDomain[length];
- next: for (int i = 0; i < length; i++) {
- ProtectionDomain current = context[i];
- for (int j = 0; j < i; j++)
- if (current == this.domainsArray[j])
- continue next;
- this.domainsArray[domainIndex++] = current;
- }
- if (domainIndex != length) {
- ProtectionDomain[] copy = new ProtectionDomain[domainIndex];
- System.arraycopy(this.domainsArray, 0, copy, 0, domainIndex);
- this.domainsArray = copy;
- }
- }
-
- AccessControlContext(ProtectionDomain[] context, boolean ignored) {
- domainsArray = context;
- }
-
- /**
- * Constructs a new instance of this class given a context and a
- * DomainCombiner
- */
- public AccessControlContext(AccessControlContext acc,
- DomainCombiner combiner) {
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkPermission(createAccessControlContext);
- this.domainsArray = acc.domainsArray;
- this.domainCombiner = combiner;
- }
-
- /**
- * Checks if the permission <code>perm</code> is allowed in this context.
- * All ProtectionDomains must grant the permission for it to be granted.
- *
- * @param perm
- * java.security.Permission the permission to check
- * @exception java.security.AccessControlException
- * thrown when perm is not granted.
- */
- public void checkPermission(Permission perm) throws AccessControlException {
- if (perm == null)
- throw new NullPointerException();
- int i = domainsArray.length;
- while (--i >= 0 && domainsArray[i].implies(perm))
- ;
- if (i >= 0) {
- throw new AccessControlException("Access Denied", perm);
- }
- }
-
- /**
- * Compares the argument to the receiver, and answers true if they represent
- * the <em>same</em> object using a class specific comparison. In this
- * case, they must both be AccessControlContexts and contain the same
- * protection domains.
- *
- *
- * @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 boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || this.getClass() != o.getClass())
- return false;
- AccessControlContext otherContext = (AccessControlContext) o;
- ProtectionDomain[] otherDomains = otherContext.domainsArray;
- int length = domainsArray.length;
- if (length != otherDomains.length)
- return false;
-
- next: for (int i = 0; i < length; i++) {
- ProtectionDomain current = domainsArray[i];
- for (int j = 0; j < length; j++)
- if (current == otherDomains[j])
- continue next;
- return false;
- }
- return true;
- }
-
- /**
- * 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
- */
- public int hashCode() {
- int result = 0;
- int i = domainsArray.length;
- while (--i >= 0)
- result ^= domainsArray[i].hashCode();
- return result;
- }
-
- /**
- * Answers the DomainCombiner for the receiver.
- *
- */
- public DomainCombiner getDomainCombiner() {
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkPermission(getDomainCombiner);
- return domainCombiner;
- }
-
-}
+/* 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;
+
+/**
+ * The vm vendor may choose to implement this class. The reference
+ * implementation must be used if the reference implementation of
+ * AccessController is used.
+ *
+ * An AccessControlContext encapsulates the information which is needed by class
+ * AccessController to detect if a Permission would be granted at a particular
+ * point in a programs execution.
+ *
+ */
+
+public final class AccessControlContext {
+ DomainCombiner domainCombiner;
+
+ ProtectionDomain[] domainsArray;
+
+ private static final SecurityPermission createAccessControlContext = new SecurityPermission(
+ "createAccessControlContext");
+
+ private static final SecurityPermission getDomainCombiner = new SecurityPermission(
+ "getDomainCombiner");
+
+ /**
+ * Constructs a new instance of this class given an array of protection
+ * domains.
+ *
+ */
+ public AccessControlContext(ProtectionDomain[] context) {
+ int length = context.length;
+ int domainIndex = 0;
+ this.domainsArray = new ProtectionDomain[length];
+ next: for (int i = 0; i < length; i++) {
+ ProtectionDomain current = context[i];
+ for (int j = 0; j < i; j++)
+ if (current == this.domainsArray[j])
+ continue next;
+ this.domainsArray[domainIndex++] = current;
+ }
+ if (domainIndex != length) {
+ ProtectionDomain[] copy = new ProtectionDomain[domainIndex];
+ System.arraycopy(this.domainsArray, 0, copy, 0, domainIndex);
+ this.domainsArray = copy;
+ }
+ }
+
+ AccessControlContext(ProtectionDomain[] context, boolean ignored) {
+ domainsArray = context;
+ }
+
+ /**
+ * Constructs a new instance of this class given a context and a
+ * DomainCombiner
+ */
+ public AccessControlContext(AccessControlContext acc,
+ DomainCombiner combiner) {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(createAccessControlContext);
+ this.domainsArray = acc.domainsArray;
+ this.domainCombiner = combiner;
+ }
+
+ /**
+ * Checks if the permission <code>perm</code> is allowed in this context.
+ * All ProtectionDomains must grant the permission for it to be granted.
+ *
+ * @param perm
+ * java.security.Permission the permission to check
+ * @exception java.security.AccessControlException
+ * thrown when perm is not granted.
+ */
+ public void checkPermission(Permission perm) throws AccessControlException {
+ if (perm == null)
+ throw new NullPointerException();
+ int i = domainsArray.length;
+ while (--i >= 0 && domainsArray[i].implies(perm))
+ ;
+ if (i >= 0) {
+ throw new AccessControlException("Access Denied", perm);
+ }
+ }
+
+ /**
+ * Compares the argument to the receiver, and answers true if they represent
+ * the <em>same</em> object using a class specific comparison. In this
+ * case, they must both be AccessControlContexts and contain the same
+ * protection domains.
+ *
+ *
+ * @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 boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || this.getClass() != o.getClass())
+ return false;
+ AccessControlContext otherContext = (AccessControlContext) o;
+ ProtectionDomain[] otherDomains = otherContext.domainsArray;
+ int length = domainsArray.length;
+ if (length != otherDomains.length)
+ return false;
+
+ next: for (int i = 0; i < length; i++) {
+ ProtectionDomain current = domainsArray[i];
+ for (int j = 0; j < length; j++)
+ if (current == otherDomains[j])
+ continue next;
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * 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
+ */
+ public int hashCode() {
+ int result = 0;
+ int i = domainsArray.length;
+ while (--i >= 0)
+ result ^= domainsArray[i].hashCode();
+ return result;
+ }
+
+ /**
+ * Answers the DomainCombiner for the receiver.
+ *
+ */
+ public DomainCombiner getDomainCombiner() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(getDomainCombiner);
+ return domainCombiner;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessControlContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessController.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessController.java?view=diff&rev=443541&r1=443540&r2=443541
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessController.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessController.java Thu Sep 14 18:25:01 2006
@@ -1,271 +1,271 @@
-/* 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;
-
-/**
- * This class must be implemented by the vm vendor, or the reference
- * implementation can be used if the documented native is implemented.
- *
- * Checks access to system resources. Supports marking of code as priveleged.
- * Makes context snapshots to allow checking from other contexts.
- *
- */
-
-public final class AccessController {
- static {
- // Initialize vm-internal caches
- initializeInternal();
- }
-
- private static native void initializeInternal();
-
- /**
- * Prevents this class from being instantiated.
- */
- private AccessController() {
- }
-
- /**
- * This native must be implemented to use the reference implementation of
- * this class. It is used by checkPermission() and getContext(), which call
- * this native with depth = 1.
- *
- * Returns an array of ProtectionDomain from the classes on the stack, from
- * the specified depth up to the first privileged frame, or the end of the
- * stack if there is not a privileged frame. The array may be larger than
- * required, but must be null terminated. As bootstrap classes have all
- * permissions, bootstrap class frames SHOULD be skipped. Bootstrap class
- * frames MUST be skipped if the ProtectionDomain of bootstrap classes is
- * null. Duplicate ProtectionDomains SHOULD be removed.
- *
- * The first element of the result is the AccessControlContext, which may be
- * null, either from the privileged frame, or from the current Thread if
- * there is not a privileged frame.
- *
- * A privileged frame is any frame running one of the following methods:
- *
- * <code><ul>
- * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object;</li>
- * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;)Ljava/lang/Object;</li>
- * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;</li>
- * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;</li>
- * </ul></code>
- *
- * @param depth
- * The stack depth at which to start. Depth 0 is the current
- * frame (the caller of this native).
- *
- * @return an Object[] where the first element is AccessControlContext, and
- * the other elements are ProtectionsDomain.
- */
-
- private static native Object[] getProtectionDomains(int depth);
-
- /**
- * Checks whether the running program is allowed to access the resource
- * being guarded by the given Permission argument.
- *
- *
- * @param perm
- * the permission to check
- * @exception AccessControlException
- * if access is not allowed.
- */
- public static void checkPermission(Permission perm)
- throws AccessControlException {
- if (perm == null)
- throw new NullPointerException();
- Object[] domains = getProtectionDomains(1);
- AccessControlContext acc = (AccessControlContext) domains[0];
- ProtectionDomain[] pDomains = null;
- if (acc != null && acc.domainCombiner != null) {
- pDomains = acc.domainCombiner.combine(toArrayOfProtectionDomains(
- domains, null), acc.domainsArray);
- } else {
- pDomains = toArrayOfProtectionDomains(domains, acc);
- }
- for (int i = 0, length = pDomains.length; i < length; i++) {
- if (!pDomains[i].implies(perm)) {
- throw new AccessControlException("Access Denied " + perm, perm);
- }
- }
- }
-
- /**
- * Used to keep the context live during doPrivileged().
- *
- *
- * @see #doPrivileged(PrivilegedAction<T>, AccessControlContext)
- */
- private static void keepalive(AccessControlContext context) {
- }
-
- /**
- * Answers the access controller context of the current thread, including
- * the inherited ones. It basically retrieves all the protection domains
- * from the calling stack and creates an <code>AccessControlContext</code>
- * with them.
- *
- *
- * @see AccessControlContext
- */
- public static AccessControlContext getContext() {
- Object[] domains = getProtectionDomains(1);
- AccessControlContext acc = (AccessControlContext) domains[0];
- ProtectionDomain[] pDomains = null;
- if (acc != null && acc.domainCombiner != null) {
- pDomains = acc.domainCombiner.combine(toArrayOfProtectionDomains(
- domains, null), acc.domainsArray);
- AccessControlContext result = new AccessControlContext(pDomains,
- false);
- result.domainCombiner = acc.domainCombiner;
- return result;
- }
- return new AccessControlContext(
- toArrayOfProtectionDomains(domains, acc), false);
- }
-
- private static ProtectionDomain[] toArrayOfProtectionDomains(
- Object[] domains, AccessControlContext acc) {
- int len = 0, size = domains.length - 1;
- int extra = acc == null ? 0 : acc.domainsArray.length;
- ProtectionDomain[] answer = new ProtectionDomain[size + extra];
- for (int i = 1; i <= size; i++) {
- boolean found = false;
- if ((answer[len] = (ProtectionDomain) domains[i]) == null)
- break;
- if (acc != null) {
- for (int j = 0; j < acc.domainsArray.length; j++) {
- if (answer[len] == acc.domainsArray[j]) {
- found = true;
- break;
- }
- }
- }
- if (!found)
- len++;
- }
- if (len == 0 && acc != null)
- return acc.domainsArray;
- else if (len < size) {
- ProtectionDomain[] copy = new ProtectionDomain[len + extra];
- System.arraycopy(answer, 0, copy, 0, len);
- answer = copy;
- }
- if (acc != null)
- System.arraycopy(acc.domainsArray, 0, answer, len,
- acc.domainsArray.length);
- return answer;
- }
-
- /**
- * Performs the privileged action specified by <code>action</code>.
- * <p>
- * When permission checks are made, if the permission has been granted by
- * all frames below and including the one representing the call to this
- * method, then the permission is granted. In otherwords, the check stops
- * here.
- *
- * Any unchecked exception generated by this method will propagate up the
- * chain.
- *
- *
- * @see #doPrivileged(PrivilegedAction<T>)
- */
- public static <T> T doPrivileged(PrivilegedAction<T> action) {
- return action.run();
- }
-
- /**
- * Performs the privileged action specified by <code>action</code>.
- * <p>
- * When permission checks are made, if the permission has been granted by
- * all frames below and including the one representing the call to this
- * method, then the permission is granted iff it is granted by the
- * AccessControlContext <code>context</code>. In otherwords, no more
- * checking of the current stack is performed. Instead, the passed in
- * context is checked.
- *
- * Any unchecked exception generated by this method will propagate up the
- * chain.
- *
- *
- * @see #doPrivileged(PrivilegedAction<T>)
- */
- public static <T> T doPrivileged(PrivilegedAction<T> action,
- AccessControlContext context) {
- T result = action.run();
- keepalive(context);
- return result;
- }
-
- /**
- * Performs the privileged action specified by <code>action</code>.
- * <p>
- * When permission checks are made, if the permission has been granted by
- * all frames below and including the one representing the call to this
- * method, then the permission is granted. In otherwords, the check stops
- * here.
- *
- * Any unchecked exception generated by this method will propagate up the
- * chain. However, checked exceptions will be caught an re-thrown as
- * PrivilegedActionExceptions
- *
- *
- * @see #doPrivileged(PrivilegedAction<T>)
- */
- public static <T> T doPrivileged(PrivilegedExceptionAction<T> action)
- throws PrivilegedActionException {
- try {
- return action.run();
- } catch (RuntimeException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new PrivilegedActionException(ex);
- }
- }
-
- /**
- * Performs the privileged action specified by <code>action</code>.
- * <p>
- * When permission checks are made, if the permission has been granted by
- * all frames below and including the one representing the call to this
- * method, then the permission is granted iff it is granted by the
- * AccessControlContext <code>context</code>. In otherwords, no more
- * checking of the current stack is performed. Instead, the passed in
- * context is checked.
- *
- * Any unchecked exception generated by this method will propagate up the
- * chain. However, checked exceptions will be caught an re-thrown as
- * PrivilegedActionExceptions
- *
- *
- * @see #doPrivileged(PrivilegedAction<T>)
- */
- public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
- AccessControlContext context) throws PrivilegedActionException {
- try {
- T result = action.run();
- keepalive(context);
- return result;
- } catch (RuntimeException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new PrivilegedActionException(ex);
- }
- }
-
-}
+/* 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;
+
+/**
+ * This class must be implemented by the vm vendor, or the reference
+ * implementation can be used if the documented native is implemented.
+ *
+ * Checks access to system resources. Supports marking of code as priveleged.
+ * Makes context snapshots to allow checking from other contexts.
+ *
+ */
+
+public final class AccessController {
+ static {
+ // Initialize vm-internal caches
+ initializeInternal();
+ }
+
+ private static native void initializeInternal();
+
+ /**
+ * Prevents this class from being instantiated.
+ */
+ private AccessController() {
+ }
+
+ /**
+ * This native must be implemented to use the reference implementation of
+ * this class. It is used by checkPermission() and getContext(), which call
+ * this native with depth = 1.
+ *
+ * Returns an array of ProtectionDomain from the classes on the stack, from
+ * the specified depth up to the first privileged frame, or the end of the
+ * stack if there is not a privileged frame. The array may be larger than
+ * required, but must be null terminated. As bootstrap classes have all
+ * permissions, bootstrap class frames SHOULD be skipped. Bootstrap class
+ * frames MUST be skipped if the ProtectionDomain of bootstrap classes is
+ * null. Duplicate ProtectionDomains SHOULD be removed.
+ *
+ * The first element of the result is the AccessControlContext, which may be
+ * null, either from the privileged frame, or from the current Thread if
+ * there is not a privileged frame.
+ *
+ * A privileged frame is any frame running one of the following methods:
+ *
+ * <code><ul>
+ * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object;</li>
+ * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;)Ljava/lang/Object;</li>
+ * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;</li>
+ * <li>java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;</li>
+ * </ul></code>
+ *
+ * @param depth
+ * The stack depth at which to start. Depth 0 is the current
+ * frame (the caller of this native).
+ *
+ * @return an Object[] where the first element is AccessControlContext, and
+ * the other elements are ProtectionsDomain.
+ */
+
+ private static native Object[] getProtectionDomains(int depth);
+
+ /**
+ * Checks whether the running program is allowed to access the resource
+ * being guarded by the given Permission argument.
+ *
+ *
+ * @param perm
+ * the permission to check
+ * @exception AccessControlException
+ * if access is not allowed.
+ */
+ public static void checkPermission(Permission perm)
+ throws AccessControlException {
+ if (perm == null)
+ throw new NullPointerException();
+ Object[] domains = getProtectionDomains(1);
+ AccessControlContext acc = (AccessControlContext) domains[0];
+ ProtectionDomain[] pDomains = null;
+ if (acc != null && acc.domainCombiner != null) {
+ pDomains = acc.domainCombiner.combine(toArrayOfProtectionDomains(
+ domains, null), acc.domainsArray);
+ } else {
+ pDomains = toArrayOfProtectionDomains(domains, acc);
+ }
+ for (int i = 0, length = pDomains.length; i < length; i++) {
+ if (!pDomains[i].implies(perm)) {
+ throw new AccessControlException("Access Denied " + perm, perm);
+ }
+ }
+ }
+
+ /**
+ * Used to keep the context live during doPrivileged().
+ *
+ *
+ * @see #doPrivileged(PrivilegedAction<T>, AccessControlContext)
+ */
+ private static void keepalive(AccessControlContext context) {
+ }
+
+ /**
+ * Answers the access controller context of the current thread, including
+ * the inherited ones. It basically retrieves all the protection domains
+ * from the calling stack and creates an <code>AccessControlContext</code>
+ * with them.
+ *
+ *
+ * @see AccessControlContext
+ */
+ public static AccessControlContext getContext() {
+ Object[] domains = getProtectionDomains(1);
+ AccessControlContext acc = (AccessControlContext) domains[0];
+ ProtectionDomain[] pDomains = null;
+ if (acc != null && acc.domainCombiner != null) {
+ pDomains = acc.domainCombiner.combine(toArrayOfProtectionDomains(
+ domains, null), acc.domainsArray);
+ AccessControlContext result = new AccessControlContext(pDomains,
+ false);
+ result.domainCombiner = acc.domainCombiner;
+ return result;
+ }
+ return new AccessControlContext(
+ toArrayOfProtectionDomains(domains, acc), false);
+ }
+
+ private static ProtectionDomain[] toArrayOfProtectionDomains(
+ Object[] domains, AccessControlContext acc) {
+ int len = 0, size = domains.length - 1;
+ int extra = acc == null ? 0 : acc.domainsArray.length;
+ ProtectionDomain[] answer = new ProtectionDomain[size + extra];
+ for (int i = 1; i <= size; i++) {
+ boolean found = false;
+ if ((answer[len] = (ProtectionDomain) domains[i]) == null)
+ break;
+ if (acc != null) {
+ for (int j = 0; j < acc.domainsArray.length; j++) {
+ if (answer[len] == acc.domainsArray[j]) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ len++;
+ }
+ if (len == 0 && acc != null)
+ return acc.domainsArray;
+ else if (len < size) {
+ ProtectionDomain[] copy = new ProtectionDomain[len + extra];
+ System.arraycopy(answer, 0, copy, 0, len);
+ answer = copy;
+ }
+ if (acc != null)
+ System.arraycopy(acc.domainsArray, 0, answer, len,
+ acc.domainsArray.length);
+ return answer;
+ }
+
+ /**
+ * Performs the privileged action specified by <code>action</code>.
+ * <p>
+ * When permission checks are made, if the permission has been granted by
+ * all frames below and including the one representing the call to this
+ * method, then the permission is granted. In otherwords, the check stops
+ * here.
+ *
+ * Any unchecked exception generated by this method will propagate up the
+ * chain.
+ *
+ *
+ * @see #doPrivileged(PrivilegedAction<T>)
+ */
+ public static <T> T doPrivileged(PrivilegedAction<T> action) {
+ return action.run();
+ }
+
+ /**
+ * Performs the privileged action specified by <code>action</code>.
+ * <p>
+ * When permission checks are made, if the permission has been granted by
+ * all frames below and including the one representing the call to this
+ * method, then the permission is granted iff it is granted by the
+ * AccessControlContext <code>context</code>. In otherwords, no more
+ * checking of the current stack is performed. Instead, the passed in
+ * context is checked.
+ *
+ * Any unchecked exception generated by this method will propagate up the
+ * chain.
+ *
+ *
+ * @see #doPrivileged(PrivilegedAction<T>)
+ */
+ public static <T> T doPrivileged(PrivilegedAction<T> action,
+ AccessControlContext context) {
+ T result = action.run();
+ keepalive(context);
+ return result;
+ }
+
+ /**
+ * Performs the privileged action specified by <code>action</code>.
+ * <p>
+ * When permission checks are made, if the permission has been granted by
+ * all frames below and including the one representing the call to this
+ * method, then the permission is granted. In otherwords, the check stops
+ * here.
+ *
+ * Any unchecked exception generated by this method will propagate up the
+ * chain. However, checked exceptions will be caught an re-thrown as
+ * PrivilegedActionExceptions
+ *
+ *
+ * @see #doPrivileged(PrivilegedAction<T>)
+ */
+ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action)
+ throws PrivilegedActionException {
+ try {
+ return action.run();
+ } catch (RuntimeException ex) {
+ throw ex;
+ } catch (Exception ex) {
+ throw new PrivilegedActionException(ex);
+ }
+ }
+
+ /**
+ * Performs the privileged action specified by <code>action</code>.
+ * <p>
+ * When permission checks are made, if the permission has been granted by
+ * all frames below and including the one representing the call to this
+ * method, then the permission is granted iff it is granted by the
+ * AccessControlContext <code>context</code>. In otherwords, no more
+ * checking of the current stack is performed. Instead, the passed in
+ * context is checked.
+ *
+ * Any unchecked exception generated by this method will propagate up the
+ * chain. However, checked exceptions will be caught an re-thrown as
+ * PrivilegedActionExceptions
+ *
+ *
+ * @see #doPrivileged(PrivilegedAction<T>)
+ */
+ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
+ AccessControlContext context) throws PrivilegedActionException {
+ try {
+ T result = action.run();
+ keepalive(context);
+ return result;
+ } catch (RuntimeException ex) {
+ throw ex;
+ } catch (Exception ex) {
+ throw new PrivilegedActionException(ex);
+ }
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security-kernel/src/main/java/java/security/AccessController.java
------------------------------------------------------------------------------
svn:eol-style = native