use of java.util.PropertyPermission in project jdk8u_jdk by JetBrains.
the class WildcardPrincipalName method main.
public static void main(String[] args) throws Exception {
X500Principal duke = new X500Principal("CN=Duke");
PropertyPermission pp = new PropertyPermission("user.home", "read");
RunAsPrivilegedUserAction runAsPrivilegedUserAction = new RunAsPrivilegedUserAction(duke, new CheckPermissionAction(pp));
AccessController.doPrivileged(runAsPrivilegedUserAction);
System.out.println("test PASSED");
}
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 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