use of java.util.PropertyPermission in project jdk8u_jdk by JetBrains.
the class System method clearProperty.
/**
* Removes the system property indicated by the specified key.
* <p>
* First, if a security manager exists, its
* <code>SecurityManager.checkPermission</code> method
* is called with a <code>PropertyPermission(key, "write")</code>
* permission. This may result in a SecurityException being thrown.
* If no exception is thrown, the specified property is removed.
* <p>
*
* @param key the name of the system property to be removed.
* @return the previous string value of the system property,
* or <code>null</code> if there was no property with that key.
*
* @exception SecurityException if a security manager exists and its
* <code>checkPropertyAccess</code> method doesn't allow
* access to the specified system property.
* @exception NullPointerException if <code>key</code> is
* <code>null</code>.
* @exception IllegalArgumentException if <code>key</code> is empty.
* @see #getProperty
* @see #setProperty
* @see java.util.Properties
* @see java.lang.SecurityException
* @see java.lang.SecurityManager#checkPropertiesAccess()
* @since 1.5
*/
public static String clearProperty(String key) {
checkKey(key);
SecurityManager sm = getSecurityManager();
if (sm != null) {
sm.checkPermission(new PropertyPermission(key, "write"));
}
return (String) props.remove(key);
}
use of java.util.PropertyPermission in project checker-framework by typetools.
the class System method setProperty.
/**
* Sets the system property indicated by the specified key.
* <p>
* First, if a security manager exists, its
* <code>SecurityManager.checkPermission</code> method
* is called with a <code>PropertyPermission(key, "write")</code>
* permission. This may result in a SecurityException being thrown.
* If no exception is thrown, the specified property is set to the given
* value.
* <p>
*
* @param key the name of the system property.
* @param value the value of the system property.
* @return the previous value of the system property,
* or <code>null</code> if it did not have one.
*
* @exception SecurityException if a security manager exists and its
* <code>checkPermission</code> method doesn't allow
* setting of the specified property.
* @exception NullPointerException if <code>key</code> or
* <code>value</code> is <code>null</code>.
* @exception IllegalArgumentException if <code>key</code> is empty.
* @see #getProperty
* @see java.lang.System#getProperty(java.lang.String)
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
* @see java.util.PropertyPermission
* @see SecurityManager#checkPermission
* @since 1.2
*/
public static String setProperty(String key, String value) {
checkKey(key);
SecurityManager sm = getSecurityManager();
if (sm != null) {
sm.checkPermission(new PropertyPermission(key, SecurityConstants.PROPERTY_WRITE_ACTION));
}
return (String) props.setProperty(key, value);
}
use of java.util.PropertyPermission in project rt.equinox.framework by eclipse.
the class AdminPermissionTests method testAdminPermission.
public void testAdminPermission() {
AdminPermission p1 = new AdminPermission();
// $NON-NLS-1$ //$NON-NLS-2$
AdminPermission p2 = new AdminPermission("*", "*");
// $NON-NLS-1$ //$NON-NLS-2$
Permission op = new PropertyPermission("java.home", "read");
shouldImply(p1, p2);
shouldImply(p1, p1);
shouldNotImply(p1, op);
shouldEqual(p1, p2);
shouldNotEqual(p1, op);
PermissionCollection pc = p1.newPermissionCollection();
checkEnumeration(pc.elements(), true);
shouldNotImply(pc, p1);
shouldAdd(pc, p1);
shouldAdd(pc, p2);
shouldNotAdd(pc, op);
pc.setReadOnly();
shouldNotAdd(pc, new AdminPermission());
shouldImply(pc, p1);
shouldImply(pc, p2);
shouldNotImply(pc, op);
checkEnumeration(pc.elements(), false);
testSerialization(p1);
testSerialization(p2);
}
use of java.util.PropertyPermission in project Payara by payara.
the class SSLUtils method checkPermission.
public static void checkPermission(String key) {
try {
// Checking a random permission to check if it is server.
if (Util.isEmbeddedServer() || Util.getDefaultHabitat() == null || Util.getInstance().isACC() || Util.getInstance().isNotServerOrACC()) {
return;
}
Permission perm = new RuntimePermission("SSLPassword");
AccessController.checkPermission(perm);
} catch (AccessControlException e) {
String message = e.getMessage();
Permission perm = new PropertyPermission(key, "read");
if (message != null) {
message = message.replace(e.getPermission().toString(), perm.toString());
}
throw new AccessControlException(message, perm);
}
}
use of java.util.PropertyPermission in project Payara by payara.
the class SecuritySupportImpl method checkPermission.
public void checkPermission(String key) {
try {
// Checking a random permission to check if it is server.
if (isEmbeddedServer() || habitat == null || isACC() || isNotServerORACC()) {
return;
}
Permission perm = new RuntimePermission("SSLPassword");
AccessController.checkPermission(perm);
} catch (AccessControlException e) {
String message = e.getMessage();
Permission perm = new PropertyPermission(key, "read");
if (message != null) {
message = message.replace(e.getPermission().toString(), perm.toString());
}
throw new AccessControlException(message, perm);
}
}
Aggregations