Top Description Inners Fields Constructors Methods
org.apache.tools.ant.types

public Class Permissions

extends ProjectComponent
Class Inheritance
Imports
java.lang.reflect.Constructor, java.net.SocketPermission, java.security.UnresolvedPermission, java.util.HashSet, .LinkedList, .List, .PropertyPermission, .Set, .StringTokenizer, org.apache.tools.ant.BuildException, .ExitException, .Project, .ProjectComponent, org.apache.tools.ant.util.SecurityManagerUtil

This class implements a security manager meant for usage by tasks that run inside the Ant VM. An examples are the Java Task and JUnitTask.

The basic functionality is that nothing (except for a base set of permissions) is allowed, unless the permission is granted either explicitly or implicitly. If a permission is granted this can be overruled by explicitly revoking the permission. It is not permissible to add permissions (either granted or revoked) while the Security Manager is active (after calling setSecurityManager() but before calling restoreSecurityManager()).

Note

This class isn't supported in Java 18 and higher where SecurityManager has been deprecated for removal.

Since
Ant 1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
Permissions.MySM

Deprecated as a consequence of SecurityManager being deprecated.
This inner class implements the actual SecurityManager that can be used by tasks supporting Permissions.
public static class
Permissions.Permission

Represents a permission.

Field Summary

Modifier and TypeField and Description
private boolean
private final boolean
private Permissions
private final List<Permissions.Permission>
private SecurityManager
origSm

Deprecated as a consequence of SecurityManager being deprecated.
private static final Class<?>[]
private final List<Permissions.Permission>
Inherited from org.apache.tools.ant.ProjectComponent:
descriptionlocationproject

Constructor Summary

AccessConstructor and Description
public
Permissions()

Create a set of Permissions.

public
Permissions(final boolean
if true the old security manager will be used if the permission has not been explicitly granted or revoked in this instance.
delegateToOldSM
)

Create a set of permissions.

Method Summary

Modifier and TypeMethod and Description
public void
addConfiguredGrant(final Permissions.Permission
The Permissions.Permission to be granted.
perm
)

Adds a permission to be granted.

public void
addConfiguredRevoke(final Permissions.Permission
The Permissions.Permission to be revoked
perm
)

Adds a permission to be revoked.

private Permission
private void
init()

Initializes the list of granted permissions, checks the list of revoked permissions.

public synchronized void
restoreSecurityManager()

To be used by tasks that just finished executing the parts subject to these permissions.

public synchronized void
setSecurityManager()

To be used by tasks wishing to use this security model before executing the part to be subject to these Permissions.

Inherited from org.apache.tools.ant.ProjectComponent:
clonegetDescriptiongetLocationgetProjectloglogsetDescriptionsetLocationsetProject

Field Detail

activeback to summary
private boolean active
delegateToOldSMback to summary
private final boolean delegateToOldSM
grantedback to summary
private Permissions granted
grantedPermissionsback to summary
private final List<Permissions.Permission> grantedPermissions
origSmback to summary
private SecurityManager origSm

Deprecated

as a consequence of SecurityManager being deprecated. See corresponding docs for further information.

PARAMSback to summary
private static final Class<?>[] PARAMS
revokedPermissionsback to summary
private final List<Permissions.Permission> revokedPermissions

Constructor Detail

Permissionsback to summary
public Permissions()

Create a set of Permissions. Equivalent to calling new Permissions(false).

Permissionsback to summary
public Permissions(final boolean delegateToOldSM)

Create a set of permissions.

Parameters
delegateToOldSM:boolean

if true the old security manager will be used if the permission has not been explicitly granted or revoked in this instance.

Method Detail

addConfiguredGrantback to summary
public void addConfiguredGrant(final Permissions.Permission perm)

Adds a permission to be granted.

Parameters
perm:Permissions.Permission

The Permissions.Permission to be granted.

addConfiguredRevokeback to summary
public void addConfiguredRevoke(final Permissions.Permission perm)

Adds a permission to be revoked.

Parameters
perm:Permissions.Permission

The Permissions.Permission to be revoked

createPermissionback to summary
private Permission createPermission(final Permissions.Permission permission)
initback to summary
private void init() throws BuildException

Initializes the list of granted permissions, checks the list of revoked permissions.

restoreSecurityManagerback to summary
public synchronized void restoreSecurityManager() throws BuildException

To be used by tasks that just finished executing the parts subject to these permissions.

This method is no longer supported in Java 18 and higher versions and throws a BuildException. org.apache.tools.ant.MagicNames#WARN_SECURITY_MANAGER_USAGE property can be set to true to log a warning message instead of throwing the exception.

setSecurityManagerback to summary
public synchronized void setSecurityManager() throws BuildException

To be used by tasks wishing to use this security model before executing the part to be subject to these Permissions. Note that setting the SecurityManager too early may prevent your part from starting, as for instance changing classloaders may be prohibited. The classloader for the new situation is supposed to be present.

This method is no longer supported in Java 18 and higher versions and throws a BuildException. org.apache.tools.ant.MagicNames#WARN_SECURITY_MANAGER_USAGE property can be set to true to log a warning message instead of throwing the exception.

Exceptions
BuildException:
on error
org.apache.tools.ant.types back to summary

private Class Permissions.MySM

extends SecurityManager
Class Inheritance

Deprecated

as a consequence of SecurityManager being deprecated. See corresponding docs for further information.

This inner class implements the actual SecurityManager that can be used by tasks supporting Permissions.

Constructor Summary

AccessConstructor and Description
private
MySM()

Method Summary

Modifier and TypeMethod and Description
public void
checkExit(final int
The exit status requested.
status
)

Overrides java.lang.SecurityManager.checkExit.

Exit is treated in a special way in order to be able to return the exit code towards tasks.
public void
checkPermission(final Permission
The permission requested.
perm
)

Overrides java.lang.SecurityManager.checkPermission.

The central point in checking permissions.
private void
checkRevoked(final Permission
the permission being checked
perm
)

throws an exception if this permission is revoked

Inherited from java.lang.SecurityManager:
checkAcceptcheckAccesscheckAccesscheckConnectcheckConnectcheckCreateClassLoadercheckDeletecheckExeccheckLinkcheckListencheckMulticastcheckMulticastcheckPackageAccesscheckPackageDefinitioncheckPermissioncheckPrintJobAccesscheckPropertiesAccesscheckPropertyAccesscheckReadcheckReadcheckReadcheckSecurityAccesscheckSetFactorycheckWritecheckWritegetClassContextgetSecurityContextgetThreadGroup

Constructor Detail

MySMback to summary
private MySM()

Method Detail

checkExitback to summary
public void checkExit(final int status)

Overrides java.lang.SecurityManager.checkExit.

Exit is treated in a special way in order to be able to return the exit code towards tasks. An ExitException is thrown instead of a simple SecurityException to indicate the exit code. Overridden from java.lang.SecurityManager

Parameters
status:int

The exit status requested.

Annotations
@Override
checkPermissionback to summary
public void checkPermission(final Permission perm)

Overrides java.lang.SecurityManager.checkPermission.

The central point in checking permissions. Overridden from java.lang.SecurityManager

Parameters
perm:Permission

The permission requested.

Annotations
@Override
checkRevokedback to summary
private void checkRevoked(final Permission perm)

throws an exception if this permission is revoked

Parameters
perm:Permission

the permission being checked

org.apache.tools.ant.types back to summary

public Class Permissions.Permission

extends Object
Class Inheritance

Represents a permission.

Field Summary

Modifier and TypeField and Description
private Set<String>
private String
private String
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The actions of the permission.
getActions
()

Get the actions.

public String

Returns:

The class name of the permission.
getClassName
()

Get the class of the permission.

public String

Returns:

The name of the permission.
getName
()

Get the name of the permission.

pack-priv boolean
matches(final Permission
The permission to check against.
perm
)

Learn whether the permission matches in case of a revoked permission.

private Set<String>
parseActions(final String
The actions to be parsed.
actions
)

Parses the actions into a set of separate strings.

public void
setActions(final String
The actions of the permission.
actions
)

Set the actions.

public void
setClass(final String
The class name of the permission.
aClass
)

Set the class, mandatory.

public void
setName(final String
The name of the permission.
aName
)

Set the name of the permission.

public String

Returns:

string description of the permissions.
toString
()

Overrides java.lang.Object.toString.

Get a string description of the permissions.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

actionsback to summary
private Set<String> actions
actionStringback to summary
private String actionString
classNameback to summary
private String className
nameback to summary
private String name

Constructor Detail

Permissionback to summary
public Permission()

Method Detail

getActionsback to summary
public String getActions()

Get the actions.

Returns:String

The actions of the permission.

getClassNameback to summary
public String getClassName()

Get the class of the permission.

Returns:String

The class name of the permission.

getNameback to summary
public String getName()

Get the name of the permission.

Returns:String

The name of the permission.

matchesback to summary
pack-priv boolean matches(final Permission perm)

Learn whether the permission matches in case of a revoked permission.

Parameters
perm:Permission

The permission to check against.

parseActionsback to summary
private Set<String> parseActions(final String actions)

Parses the actions into a set of separate strings.

Parameters
actions:String

The actions to be parsed.

setActionsback to summary
public void setActions(final String actions)

Set the actions.

Parameters
actions:String

The actions of the permission.

setClassback to summary
public void setClass(final String aClass)

Set the class, mandatory.

Parameters
aClass:String

The class name of the permission.

setNameback to summary
public void setName(final String aName)

Set the name of the permission.

Parameters
aName:String

The name of the permission.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Get a string description of the permissions.

Returns:String

string description of the permissions.

Annotations
@Override