提交 104c1e52 编写于 作者: M mullan

8001330: Improve on checking order

Reviewed-by: acorn, hawtin
上级 2243ee91
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -77,7 +77,10 @@ import sun.security.util.SecurityConstants; ...@@ -77,7 +77,10 @@ import sun.security.util.SecurityConstants;
public final class AccessControlContext { public final class AccessControlContext {
private ProtectionDomain context[]; private ProtectionDomain context[];
// isPrivileged and isAuthorized are referenced by the VM - do not remove
// or change their names
private boolean isPrivileged; private boolean isPrivileged;
private boolean isAuthorized = false;
// Note: This field is directly used by the virtual machine // Note: This field is directly used by the virtual machine
// native codes. Don't touch it. // native codes. Don't touch it.
...@@ -163,6 +166,7 @@ public final class AccessControlContext { ...@@ -163,6 +166,7 @@ public final class AccessControlContext {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(SecurityConstants.CREATE_ACC_PERMISSION); sm.checkPermission(SecurityConstants.CREATE_ACC_PERMISSION);
this.isAuthorized = true;
} }
this.context = acc.context; this.context = acc.context;
...@@ -184,6 +188,7 @@ public final class AccessControlContext { ...@@ -184,6 +188,7 @@ public final class AccessControlContext {
this.context = context.clone(); this.context = context.clone();
} }
this.combiner = combiner; this.combiner = combiner;
this.isAuthorized = true;
} }
/** /**
...@@ -191,10 +196,11 @@ public final class AccessControlContext { ...@@ -191,10 +196,11 @@ public final class AccessControlContext {
*/ */
AccessControlContext(ProtectionDomain context[], AccessControlContext(ProtectionDomain context[],
boolean isPrivileged) boolean isPrivileged)
{ {
this.context = context; this.context = context;
this.isPrivileged = isPrivileged; this.isPrivileged = isPrivileged;
this.isAuthorized = true;
} }
/** /**
...@@ -475,7 +481,7 @@ public final class AccessControlContext { ...@@ -475,7 +481,7 @@ public final class AccessControlContext {
} }
private AccessControlContext goCombiner(ProtectionDomain[] current, private AccessControlContext goCombiner(ProtectionDomain[] current,
AccessControlContext assigned) { AccessControlContext assigned) {
// the assigned ACC's combiner is not null -- // the assigned ACC's combiner is not null --
// let the combiner do its thing // let the combiner do its thing
...@@ -497,6 +503,7 @@ public final class AccessControlContext { ...@@ -497,6 +503,7 @@ public final class AccessControlContext {
this.context = combinedPds; this.context = combinedPds;
this.combiner = assigned.combiner; this.combiner = assigned.combiner;
this.isPrivileged = false; this.isPrivileged = false;
this.isAuthorized = assigned.isAuthorized;
return this; return this;
} }
......
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -304,28 +304,31 @@ public final class AccessController { ...@@ -304,28 +304,31 @@ public final class AccessController {
/** /**
* Performs the specified <code>PrivilegedAction</code> with privileges * Performs the specified {@code PrivilegedAction} with privileges
* enabled and restricted by the specified * enabled and restricted by the specified {@code AccessControlContext}.
* <code>AccessControlContext</code>.
* The action is performed with the intersection of the permissions * The action is performed with the intersection of the permissions
* possessed by the caller's protection domain, and those possessed * possessed by the caller's protection domain, and those possessed
* by the domains represented by the specified * by the domains represented by the specified {@code AccessControlContext}.
* <code>AccessControlContext</code>.
* <p> * <p>
* If the action's <code>run</code> method throws an (unchecked) exception, * If the action's {@code run} method throws an (unchecked) exception,
* it will propagate through this method. * it will propagate through this method.
* <p>
* If a security manager is installed and the {@code AccessControlContext}
* was not created by system code and the caller's {@code ProtectionDomain}
* has not been granted the {@literal "createAccessControlContext"}
* {@link java.security.SecurityPermission}, then the action is performed
* with no permissions.
* *
* @param action the action to be performed. * @param action the action to be performed.
* @param context an <i>access control context</i> * @param context an <i>access control context</i>
* representing the restriction to be applied to the * representing the restriction to be applied to the
* caller's domain's privileges before performing * caller's domain's privileges before performing
* the specified action. If the context is * the specified action. If the context is
* <code>null</code>, * {@code null}, then no additional restriction is applied.
* then no additional restriction is applied.
* *
* @return the value returned by the action's <code>run</code> method. * @return the value returned by the action's {@code run} method.
* *
* @exception NullPointerException if the action is <code>null</code> * @exception NullPointerException if the action is {@code null}
* *
* @see #doPrivileged(PrivilegedAction) * @see #doPrivileged(PrivilegedAction)
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext)
...@@ -428,30 +431,34 @@ public final class AccessController { ...@@ -428,30 +431,34 @@ public final class AccessController {
/** /**
* Performs the specified <code>PrivilegedExceptionAction</code> with * Performs the specified {@code PrivilegedExceptionAction} with
* privileges enabled and restricted by the specified * privileges enabled and restricted by the specified
* <code>AccessControlContext</code>. The action is performed with the * {@code AccessControlContext}. The action is performed with the
* intersection of the permissions possessed by the caller's * intersection of the permissions possessed by the caller's
* protection domain, and those possessed by the domains represented by the * protection domain, and those possessed by the domains represented by the
* specified <code>AccessControlContext</code>. * specified {@code AccessControlContext}.
* <p> * <p>
* If the action's <code>run</code> method throws an <i>unchecked</i> * If the action's {@code run} method throws an <i>unchecked</i>
* exception, it will propagate through this method. * exception, it will propagate through this method.
* <p>
* If a security manager is installed and the {@code AccessControlContext}
* was not created by system code and the caller's {@code ProtectionDomain}
* has not been granted the {@literal "createAccessControlContext"}
* {@link java.security.SecurityPermission}, then the action is performed
* with no permissions.
* *
* @param action the action to be performed * @param action the action to be performed
* @param context an <i>access control context</i> * @param context an <i>access control context</i>
* representing the restriction to be applied to the * representing the restriction to be applied to the
* caller's domain's privileges before performing * caller's domain's privileges before performing
* the specified action. If the context is * the specified action. If the context is
* <code>null</code>, * {@code null}, then no additional restriction is applied.
* then no additional restriction is applied.
* *
* @return the value returned by the action's <code>run</code> method * @return the value returned by the action's {@code run} method
* *
* @exception PrivilegedActionException if the specified action's * @exception PrivilegedActionException if the specified action's
* <code>run</code> method * {@code run} method threw a <i>checked</i> exception
* threw a <i>checked</i> exception * @exception NullPointerException if the action is {@code null}
* @exception NullPointerException if the action is <code>null</code>
* *
* @see #doPrivileged(PrivilegedAction) * @see #doPrivileged(PrivilegedAction)
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext)
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -277,6 +277,11 @@ public class ProtectionDomain { ...@@ -277,6 +277,11 @@ public class ProtectionDomain {
return false; return false;
} }
// called by the VM -- do not remove
boolean impliesCreateAccessControlContext() {
return implies(SecurityConstants.CREATE_ACC_PERMISSION);
}
/** /**
* Convert a ProtectionDomain to a String. * Convert a ProtectionDomain to a String.
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册