Search in sources :

Example 61 with PrivilegedExceptionAction

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();
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Properties(java.util.Properties) PrivilegedAction(java.security.PrivilegedAction)

Example 62 with PrivilegedExceptionAction

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;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) File(java.io.File)

Example 63 with PrivilegedExceptionAction

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;
    }
}
Also used : Field(java.lang.reflect.Field) Color(java.awt.Color) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 64 with PrivilegedExceptionAction

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;
}
Also used : J2EEServerInfo(org.exoplatform.container.monitor.jvm.J2EEServerInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) File(java.io.File) URL(java.net.URL) ConfigurationException(org.exoplatform.container.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 65 with PrivilegedExceptionAction

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);
        }
    }
}
Also used : ProxyFactory(javassist.util.proxy.ProxyFactory) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException) DefinitionException(org.exoplatform.container.context.DefinitionException) UnproxyableResolutionException(javax.enterprise.inject.UnproxyableResolutionException) IOException(java.io.IOException) MethodHandler(javassist.util.proxy.MethodHandler) UnproxyableResolutionException(javax.enterprise.inject.UnproxyableResolutionException)

Aggregations

PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)387 IOException (java.io.IOException)199 PrivilegedActionException (java.security.PrivilegedActionException)135 Test (org.junit.Test)104 Connection (org.apache.hadoop.hbase.client.Connection)81 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)76 Table (org.apache.hadoop.hbase.client.Table)62 TableName (org.apache.hadoop.hbase.TableName)57 Result (org.apache.hadoop.hbase.client.Result)56 Scan (org.apache.hadoop.hbase.client.Scan)55 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)53 Delete (org.apache.hadoop.hbase.client.Delete)48 InterruptedIOException (java.io.InterruptedIOException)47 Cell (org.apache.hadoop.hbase.Cell)38 CellScanner (org.apache.hadoop.hbase.CellScanner)38 Configuration (org.apache.hadoop.conf.Configuration)36 File (java.io.File)33 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)33 Path (org.apache.hadoop.fs.Path)23 ArrayList (java.util.ArrayList)22