Browse Source

Javadoc + very slight code reworking

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278370 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
013b691060
1 changed files with 25 additions and 23 deletions
  1. +25
    -23
      src/main/org/apache/tools/ant/types/Permissions.java

+ 25
- 23
src/main/org/apache/tools/ant/types/Permissions.java View File

@@ -29,12 +29,12 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitException; import org.apache.tools.ant.ExitException;


/** /**
* This class implements a security manager meant for useage by tasks that run inside the
* ant VM. An examples are the Java Task and JUnitTask.
* 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 basic functionality is that nothing (except for a base set of permissions) is allowed, unless
* the permission is granted either explicitly or implicitly. * the permission is granted either explicitly or implicitly.
* If an permission is granted this can be overruled by explicitly revoking the permission.
* 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 * It is not permissible to add permissions (either granted or revoked) while the Security Manager
* is active (after calling setSecurityManager() but before calling restoreSecurityManager()). * is active (after calling setSecurityManager() but before calling restoreSecurityManager()).
@@ -48,23 +48,26 @@ public class Permissions {
private java.security.Permissions granted = null; private java.security.Permissions granted = null;
private SecurityManager origSm = null; private SecurityManager origSm = null;
private boolean active = false; private boolean active = false;
private boolean delegateToOldSM = false;
private boolean delegateToOldSM;


/** /**
* default constructor
* Create a set of Permissions. Equivalent to calling
* <code>new Permissions(false)</code>.
*/ */
public Permissions() { public Permissions() {
this(false);
} }

/** /**
* create a new set of permissions
* Create a set of permissions.
* @param delegateToOldSM if <code>true</code> the old security manager * @param delegateToOldSM if <code>true</code> the old security manager
* will be used if the permission has not been explicitly granted or revoked * will be used if the permission has not been explicitly granted or revoked
* in this instance
* if false, it behaves like the default constructor
* in this instance.
*/ */
public Permissions(boolean delegateToOldSM) { public Permissions(boolean delegateToOldSM) {
this.delegateToOldSM = delegateToOldSM; this.delegateToOldSM = delegateToOldSM;
} }

/** /**
* Adds a permission to be granted. * Adds a permission to be granted.
* @param perm The Permissions.Permission to be granted. * @param perm The Permissions.Permission to be granted.
@@ -88,7 +91,7 @@ public class Permissions {
* The classloader for the new situation is supposed to be present. * The classloader for the new situation is supposed to be present.
* @throws BuildException on error * @throws BuildException on error
*/ */
public void setSecurityManager() throws BuildException {
public synchronized void setSecurityManager() throws BuildException {
origSm = System.getSecurityManager(); origSm = System.getSecurityManager();
init(); init();
System.setSecurityManager(new MySM()); System.setSecurityManager(new MySM());
@@ -143,7 +146,7 @@ public class Permissions {
/** /**
* To be used by tasks that just finished executing the parts subject to these permissions. * To be used by tasks that just finished executing the parts subject to these permissions.
*/ */
public void restoreSecurityManager() {
public synchronized void restoreSecurityManager() {
active = false; active = false;
System.setSecurityManager(origSm); System.setSecurityManager(origSm);
} }
@@ -200,6 +203,7 @@ public class Permissions {
} }
} }
} }

/** /**
* throws an exception if this permission is revoked * throws an exception if this permission is revoked
* @param perm the permission being checked * @param perm the permission being checked
@@ -222,14 +226,15 @@ public class Permissions {
private Set actions; private Set actions;


/** /**
* Sets the class, mandatory.
* Set the class, mandatory.
* @param aClass The class name of the permission. * @param aClass The class name of the permission.
*/ */
public void setClass(String aClass) { public void setClass(String aClass) {
className = aClass.trim(); className = aClass.trim();
} }


/** Get the class of the permission
/**
* Get the class of the permission.
* @return The class name of the permission. * @return The class name of the permission.
*/ */
public String getClassName() { public String getClassName() {
@@ -237,7 +242,7 @@ public class Permissions {
} }


/** /**
* Sets the name of the permission.
* Set the name of the permission.
* @param aName The name of the permission. * @param aName The name of the permission.
*/ */
public void setName(String aName) { public void setName(String aName) {
@@ -246,14 +251,14 @@ public class Permissions {


/** /**
* Get the name of the permission. * Get the name of the permission.
* @return The name of the permission.
* @return The name of the permission.
*/ */
public String getName() { public String getName() {
return name; return name;
} }


/** /**
* Sets the actions.
* Set the actions.
* @param actions The actions of the permission. * @param actions The actions of the permission.
*/ */
public void setActions(String actions) { public void setActions(String actions) {
@@ -264,7 +269,7 @@ public class Permissions {
} }


/** /**
* Gets the actions.
* Get the actions.
* @return The actions of the permission. * @return The actions of the permission.
*/ */
public String getActions() { public String getActions() {
@@ -272,15 +277,13 @@ public class Permissions {
} }


/** /**
* Checks if the permission matches in case of a revoked permission.
* Learn whether the permission matches in case of a revoked permission.
* @param perm The permission to check against. * @param perm The permission to check against.
*/ */
boolean matches(java.security.Permission perm) { boolean matches(java.security.Permission perm) {

if (!className.equals(perm.getClass().getName())) { if (!className.equals(perm.getClass().getName())) {
return false; return false;
} }

if (name != null) { if (name != null) {
if (name.endsWith("*")) { if (name.endsWith("*")) {
if (!perm.getName().startsWith(name.substring(0, name.length() - 1))) { if (!perm.getName().startsWith(name.substring(0, name.length() - 1))) {
@@ -292,7 +295,6 @@ public class Permissions {
} }
} }
} }

if (actions != null) { if (actions != null) {
Set as = parseActions(perm.getActions()); Set as = parseActions(perm.getActions());
int size = as.size(); int size = as.size();
@@ -302,7 +304,6 @@ public class Permissions {
return false; return false;
} }
} }

return true; return true;
} }


@@ -321,9 +322,10 @@ public class Permissions {
} }
return result; return result;
} }

/** /**
* get a string description of the permissions
* @return string description of the permissions
* Get a string description of the permissions.
* @return string description of the permissions.
*/ */
public String toString() { public String toString() {
return ("Permission: " + className + " (\"" + name + "\", \"" + actions + "\")"); return ("Permission: " + className + " (\"" + name + "\", \"" + actions + "\")");


Loading…
Cancel
Save