public final class DelegatePermission extends Permission
A DelegatePermission represents any other Permission, called a candidate Permission. A user granted a DelegatePermission does not have the privilege of the candidate Permission, although a user with a candidate Permission has the privilege of the DelegatePermission that represents the candidate, while the @ref DelegateSecurityManager is in force.
A DelegatePermission requires a method guard delegate to encapsulate a privileged resource. The developer is responsible for developing the method guard wrapper, an example for SocketFactory can be found on Apache River's svn.
A method guard delegates ProtectionDomain is granted the candidate permission, the security delegate allows any user granted a DelegatePermission to utilise the functions that its candidate Permission guards, when the user no longer has the DelegatePermission, the method guard delegate no longer allows the user to access the functions guarded by the candidate permission. A security delegate has the responsibility to prevent security sensitive objects guarded by the candidate permission from escaping. In order to do so, a security delegate utilises Li Gong's proposed method guard pattern.
Security Delegates enable sensitive objects to be used by code that isn't fully trusted you may want to monitor, such as a file write that is limited by the number of bytes written, or a Permission to write a file, that we might decide to retract or revoke if a user does something we don't like, such as exceed a pre set limit or behave in a manner we would like to avoid, such as hogging network bandwidth.
If the SecurityManager installed doesn't implement DelegateSecurityManager, DelegatePermission's will be disabled. This allows delegate's to be included in code, the decision to utilise delegate functionality may delayed until runtime or deployment.
The DelegatePermissionCollection returned by newPermissionCollection() is not synchronized, this decision was made because PermissionCollection's are usually accessed from within a heterogenous PermissionCollection like Permissions that synchronizes anyway. The decision made for the PermissionCollection contract to be synchronized has been broken deliberately in this case, existing PermissionCollection implementations don't cleanly protect their internal state with synchronization, since the Enumeration returned by elements() will throw a ConcurrentModificationException if in a loop when Permission's are being added to a PermissionCollection. In this case external synchronization must be used.
Serialization has been implemented so the implementation is not tied to the serialized form, instead serialization proxy's are used.
A candidate permission is referred to as a target in the following explanation of DelegatePermission policy file syntax.
The syntax of the target name approximates that used for specifying permissions in the default security policy file; it is listed below using the same grammar notation employed by The Java(TM) Language Specification:
Target: DelimiterDeclarationopt Permissions ;opt DelimiterDeclaration: delim = DelimiterCharacter Permissions: Permission Permissions ; Permission Permission: PermissionClassName PermissionClassName Name PermissionClassName Name , Actions PermissionClassName: ClassName Name: DelimitedString Actions: DelimitedStringThe production for ClassName is the same as that used in The Java Language Specification. DelimiterCharacter can be any unquoted non-whitespace character other than ';' (single and double-quote characters themselves are allowed). If DelimiterCharacter is not specified, then the double-quote character is the default delimiter. DelimitedString is the same as the StringLiteral production in The Java Language Specification, except that it is delimited by the DelimiterDeclaration-specified (or default) delimiter character instead of the double-quote character exclusively.
Note that if the double-quote character is used as the delimiter and the
name or actions strings of specified permissions themselves contain nested
double-quote characters, then those characters must be escaped (or in some
cases doubly-escaped) appropriately. For example, the following policy file
entry would yield a GrantPermission
containing a
FooPermission
in which the target name would include the word
"quoted" surrounded by double-quote characters:
permission org.apache.river.api.security.DelegatePermission "FooPermission \"a \\\"quoted\\\" string\"";For comparison, the following policy file entry which uses a custom delimiter would yield an equivalent
GrantPermission
:
permission org.apache.river.api.security.DelegatePermission "delim=| FooPermission |a \"quoted\" string|";Some additional example policy file permissions:
// allow granting of permission to listen for and accept connections permission org.apache.river.api.security.DelegatePermission "java.net.SocketPermission \"localhost:1024-\", \"accept,listen\""; // allow granting of permissions to read files under /foo, /bar directories permission org.apache.river.api.security.DelegatePermission "delim=' java.io.FilePermission '/foo/-', 'read'; java.io.FilePermission '/bar/-', 'read'";
Modifier and Type | Method and Description |
---|---|
void |
checkGuard(Object object) |
boolean |
equals(Object obj) |
static Permission |
get(Permission p)
Factory method to obtain a DelegatePermission, this is essential to
overcome broken equals contract in some jvm Permission implementations
like SocketPermission and to allow caching.
|
String |
getActions() |
Permission |
getPermission() |
int |
hashCode() |
boolean |
implies(Permission permission) |
PermissionCollection |
newPermissionCollection() |
getName, toString
public static Permission get(Permission p)
p
- Permission to be represented.public void checkGuard(Object object) throws SecurityException
checkGuard
in interface Guard
checkGuard
in class Permission
SecurityException
public boolean implies(Permission permission)
implies
in class Permission
public Permission getPermission()
public boolean equals(Object obj)
equals
in class Permission
public int hashCode()
hashCode
in class Permission
public String getActions()
getActions
in class Permission
public PermissionCollection newPermissionCollection()
newPermissionCollection
in class Permission
Copyright © 2016–2018 The Apache Software Foundation. All rights reserved.