You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2005/05/27 21:35:00 UTC
cvs commit: ant/src/main/org/apache/tools/ant/types Permissions.java
mbenson 2005/05/27 12:35:00
Modified: src/main/org/apache/tools/ant/types Permissions.java
Log:
Javadoc + very slight code reworking
Revision Changes Path
1.10 +25 -23 ant/src/main/org/apache/tools/ant/types/Permissions.java
Index: Permissions.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Permissions.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Permissions.java 14 Mar 2005 17:47:01 -0000 1.9
+++ Permissions.java 27 May 2005 19:35:00 -0000 1.10
@@ -29,12 +29,12 @@
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 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
* is active (after calling setSecurityManager() but before calling restoreSecurityManager()).
@@ -48,23 +48,26 @@
private java.security.Permissions granted = null;
private SecurityManager origSm = null;
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() {
+ this(false);
}
+
/**
- * create a new set of permissions
+ * Create a set of permissions.
* @param delegateToOldSM if <code>true</code> the old security manager
* 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) {
this.delegateToOldSM = delegateToOldSM;
}
+
/**
* Adds a permission to be granted.
* @param perm The Permissions.Permission to be granted.
@@ -88,7 +91,7 @@
* The classloader for the new situation is supposed to be present.
* @throws BuildException on error
*/
- public void setSecurityManager() throws BuildException {
+ public synchronized void setSecurityManager() throws BuildException {
origSm = System.getSecurityManager();
init();
System.setSecurityManager(new MySM());
@@ -143,7 +146,7 @@
/**
* To be used by tasks that just finished executing the parts subject to these permissions.
*/
- public void restoreSecurityManager() {
+ public synchronized void restoreSecurityManager() {
active = false;
System.setSecurityManager(origSm);
}
@@ -200,6 +203,7 @@
}
}
}
+
/**
* throws an exception if this permission is revoked
* @param perm the permission being checked
@@ -222,14 +226,15 @@
private Set actions;
/**
- * Sets the class, mandatory.
+ * Set the class, mandatory.
* @param aClass The class name of the permission.
*/
public void setClass(String aClass) {
className = aClass.trim();
}
- /** Get the class of the permission
+ /**
+ * Get the class of the permission.
* @return The class name of the permission.
*/
public String getClassName() {
@@ -237,7 +242,7 @@
}
/**
- * Sets the name of the permission.
+ * Set the name of the permission.
* @param aName The name of the permission.
*/
public void setName(String aName) {
@@ -246,14 +251,14 @@
/**
* Get the name of the permission.
- * @return The name of the permission.
+ * @return The name of the permission.
*/
public String getName() {
return name;
}
/**
- * Sets the actions.
+ * Set the actions.
* @param actions The actions of the permission.
*/
public void setActions(String actions) {
@@ -264,7 +269,7 @@
}
/**
- * Gets the actions.
+ * Get the actions.
* @return The actions of the permission.
*/
public String getActions() {
@@ -272,15 +277,13 @@
}
/**
- * 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.
*/
boolean matches(java.security.Permission perm) {
-
if (!className.equals(perm.getClass().getName())) {
return false;
}
-
if (name != null) {
if (name.endsWith("*")) {
if (!perm.getName().startsWith(name.substring(0, name.length() - 1))) {
@@ -292,7 +295,6 @@
}
}
}
-
if (actions != null) {
Set as = parseActions(perm.getActions());
int size = as.size();
@@ -302,7 +304,6 @@
return false;
}
}
-
return true;
}
@@ -321,9 +322,10 @@
}
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() {
return ("Permission: " + className + " (\"" + name + "\", \"" + actions + "\")");
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org