use of java.security.PrivilegedExceptionAction in project jdk8u_jdk by JetBrains.
the class AppletPropsErrorDialog method apply.
void apply() {
String proxyHostValue = proxyHost.getText().trim();
String proxyPortValue = proxyPort.getText().trim();
// Get properties
final Properties props = (Properties) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperties();
}
});
if (proxyHostValue.length() != 0) {
/* 4066402 */
/* Check for parsable value in proxy port number field before */
/* applying. Display warning to user until parsable value is */
/* entered. */
int proxyPortNumber = 0;
try {
proxyPortNumber = Integer.parseInt(proxyPortValue);
} catch (NumberFormatException e) {
}
if (proxyPortNumber <= 0) {
proxyPort.selectAll();
proxyPort.requestFocus();
(new AppletPropsErrorDialog(this, amh.getMessage("title.invalidproxy"), amh.getMessage("label.invalidproxy"), amh.getMessage("button.ok"))).show();
return;
}
/* end 4066402 */
props.put("http.proxyHost", proxyHostValue);
props.put("http.proxyPort", proxyPortValue);
} else {
props.put("http.proxyHost", "");
}
if (amh.getMessage("choice.class.item.restricted").equals(accessMode.getSelectedItem())) {
props.put("package.restrict.access.sun", "true");
} else {
props.put("package.restrict.access.sun", "false");
}
// Save properties
try {
reset();
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
File dotAV = Main.theUserPropertiesFile;
FileOutputStream out = new FileOutputStream(dotAV);
Properties avProps = new Properties();
for (int i = 0; i < Main.avDefaultUserProps.length; i++) {
String avKey = Main.avDefaultUserProps[i][0];
avProps.setProperty(avKey, props.getProperty(avKey));
}
avProps.store(out, amh.getMessage("prop.store"));
out.close();
return null;
}
});
hide();
} catch (java.security.PrivilegedActionException e) {
System.out.println(amh.getMessage("apply.exception", e.getException()));
// XXX what's the general feeling on stack traces to System.out?
e.printStackTrace();
reset();
}
}
use of java.security.PrivilegedExceptionAction in project jdk8u_jdk by JetBrains.
the class FileFont method getPublicFileName.
protected String getPublicFileName() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return platName;
}
boolean canReadProperty = true;
try {
sm.checkPropertyAccess("java.io.tmpdir");
} catch (SecurityException e) {
canReadProperty = false;
}
if (canReadProperty) {
return platName;
}
final File f = new File(platName);
Boolean isTmpFile = Boolean.FALSE;
try {
isTmpFile = AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
public Boolean run() {
File tmp = new File(System.getProperty("java.io.tmpdir"));
try {
String tpath = tmp.getCanonicalPath();
String fpath = f.getCanonicalPath();
return (fpath == null) || fpath.startsWith(tpath);
} catch (IOException e) {
return Boolean.TRUE;
}
}
});
} catch (PrivilegedActionException e) {
// unable to verify whether value of java.io.tempdir will be
// exposed, so return only a name of the font file.
isTmpFile = Boolean.TRUE;
}
return isTmpFile ? "temp file" : platName;
}
use of java.security.PrivilegedExceptionAction in project processdash by dtuma.
the class AbstractRecolorableIcon method recolor.
@Override
public RecolorableIcon recolor(final RGBImageFilter filter) {
try {
// make a copy of this icon
final AbstractRecolorableIcon result = clone();
// scan the fields in this class, looking for values to recolor
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
Class clazz = result.getClass();
do {
for (Field f : clazz.getDeclaredFields()) {
if (Modifier.isStatic(f.getModifiers()))
continue;
Class t = f.getType();
if (Color.class.equals(t)) {
// if we find a field of type Color, tweak it
f.setAccessible(true);
Color c = (Color) f.get(result);
if (c != null) {
int rgb = c.getRGB();
int newRgb = filter.filterRGB(0, 0, rgb);
Color r = new Color(newRgb, true);
f.set(result, r);
}
} else if (RecolorableIcon.class.isAssignableFrom(t)) {
// if we find a RecolorableIcon field, tweak it
f.setAccessible(true);
RecolorableIcon i = (RecolorableIcon) f.get(result);
if (i != null) {
RecolorableIcon r = i.recolor(filter);
f.set(result, r);
}
}
}
clazz = clazz.getSuperclass();
} while (clazz != null && clazz != Object.class);
return null;
}
});
// allow the object to perform any extra steps needed, then return
result.finalizeColors();
return result;
} catch (Exception e) {
e.printStackTrace();
return this;
}
}
use of java.security.PrivilegedExceptionAction in project kernel by exoplatform.
the class StandaloneContainer method getConfigurationURL.
/**
* Gives the configuration URL according to the given {@link ClassLoader}
*/
private static URL getConfigurationURL(ClassLoader configClassLoader) throws MalformedURLException {
final J2EEServerInfo env = new J2EEServerInfo();
// (2) exo-configuration.xml in AS (standalone) home directory
URL configurationURL = SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>() {
public URL run() throws Exception {
return (new File(env.getServerHome() + "/exo-configuration.xml")).toURI().toURL();
}
});
// (3) AS_HOME/conf/exo-conf (JBossAS usecase)
if (!fileExists(configurationURL)) {
configurationURL = SecurityHelper.doPrivilegedMalformedURLExceptionAction(new PrivilegedExceptionAction<URL>() {
public URL run() throws Exception {
return (new File(env.getExoConfigurationDirectory() + "/exo-configuration.xml")).toURI().toURL();
}
});
}
// (4) conf/exo-configuration.xml in war/ear(?)
if (!fileExists(configurationURL) && configClassLoader != null) {
configurationURL = configClassLoader.getResource("conf/exo-configuration.xml");
}
return configurationURL;
}
use of java.security.PrivilegedExceptionAction in project kernel by exoplatform.
the class ContainerUtil method createProxy.
/**
* Creates a proxy of the given super class whose instance will be created accessed lazily thanks to a provider
* @param superClass the super class of the proxy to create
* @param provider the provider that will create the instance lazily
* @return a proxy of the given super class
* @throws UnproxyableResolutionException if any issue occurs while creating the proxy
*/
public static <T> T createProxy(final Class<T> superClass, final Provider<T> provider) throws UnproxyableResolutionException {
PrivilegedExceptionAction<T> action = new PrivilegedExceptionAction<T>() {
public T run() throws Exception {
// We first make sure that there is no non-static, final methods with public, protected or default visibility
Method[] methods = superClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
int modifiers = m.getModifiers();
if (Modifier.isFinal(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isStatic(modifiers)) {
throw new UnproxyableResolutionException("Cannot create a proxy for the class " + superClass.getName() + " because it has at least one non-static, final method with public, protected or default visibility");
}
}
try {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(superClass);
factory.setFilter(MethodFilterHolder.METHOD_FILTER);
MethodHandler handler = new ProxyMethodHandler<T>(provider);
return superClass.cast(factory.create(new Class<?>[0], new Object[0], handler));
} catch (Exception e) {
throw new UnproxyableResolutionException("Cannot create a proxy for the class " + superClass.getName(), e);
}
}
};
try {
return SecurityHelper.doPrivilegedExceptionAction(action);
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause instanceof UnproxyableResolutionException) {
throw (UnproxyableResolutionException) cause;
} else {
throw new UnproxyableResolutionException("Cannot create a proxy for the class " + superClass.getName(), cause);
}
}
}
Aggregations