org.jboss.arquillian.drone.webdriver.utils.PropertySecurityAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arquillian-drone-webdriver Show documentation
Show all versions of arquillian-drone-webdriver Show documentation
Extension for functional testing based on web view layer (Ajocado, Selenium, WebDriver)
package org.jboss.arquillian.drone.webdriver.utils;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
/**
*
*/
public class PropertySecurityAction {
// TODO: make the class protected
public static String getProperty(final String key) {
try {
String value = AccessController.doPrivileged(new PrivilegedExceptionAction() {
public String run() {
return System.getProperty(key);
}
});
return value;
}
// Unwrap
catch (final PrivilegedActionException pae) {
final Throwable t = pae.getCause();
// Rethrow
if (t instanceof SecurityException) {
throw (SecurityException) t;
}
if (t instanceof NullPointerException) {
throw (NullPointerException) t;
} else if (t instanceof IllegalArgumentException) {
throw (IllegalArgumentException) t;
} else {
// No other checked Exception thrown by System.getProperty
try {
throw (RuntimeException) t;
}
// Just in case we've really messed up
catch (final ClassCastException cce) {
throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
}
}
}
}
public static String setProperty(final String key, final String value) {
try {
String oldValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {
public String run() {
if (value == null) {
return System.clearProperty(key);
}
return System.setProperty(key, value);
}
});
return oldValue;
}
// Unwrap
catch (final PrivilegedActionException pae) {
final Throwable t = pae.getCause();
// Rethrow
if (t instanceof SecurityException) {
throw (SecurityException) t;
}
if (t instanceof NullPointerException) {
throw (NullPointerException) t;
} else if (t instanceof IllegalArgumentException) {
throw (IllegalArgumentException) t;
} else {
// No other checked Exception thrown by System.getProperty
try {
throw (RuntimeException) t;
}
// Just in case we've really messed up
catch (final ClassCastException cce) {
throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
}
}
}
}
public static boolean isArquillianDebug(){
return Boolean.valueOf(PropertySecurityAction.getProperty("arquillian.debug"));
}
}