Search in sources :

Example 6 with PrivilegedAction

use of java.security.PrivilegedAction in project hadoop by apache.

the class MetricsConfig method getPluginLoader.

ClassLoader getPluginLoader() {
    if (pluginLoader != null)
        return pluginLoader;
    final ClassLoader defaultLoader = getClass().getClassLoader();
    Object purls = super.getProperty(PLUGIN_URLS_KEY);
    if (purls == null)
        return defaultLoader;
    Iterable<String> jars = SPLITTER.split((String) purls);
    int len = Iterables.size(jars);
    if (len > 0) {
        final URL[] urls = new URL[len];
        try {
            int i = 0;
            for (String jar : jars) {
                LOG.debug(jar);
                urls[i++] = new URL(jar);
            }
        } catch (Exception e) {
            throw new MetricsConfigException(e);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("using plugin jars: " + Iterables.toString(jars));
        }
        pluginLoader = doPrivileged(new PrivilegedAction<ClassLoader>() {

            @Override
            public ClassLoader run() {
                return new URLClassLoader(urls, defaultLoader);
            }
        });
        return pluginLoader;
    }
    if (parent instanceof MetricsConfig) {
        return ((MetricsConfig) parent).getPluginLoader();
    }
    return defaultLoader;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Example 7 with PrivilegedAction

use of java.security.PrivilegedAction in project cubrid-manager by CUBRID.

the class ClassLoaderManager method getClassLoader.

/**
	 * getClassLoader
	 * 
	 * @param file full name of a file
	 * @return URLClassLoader
	 */
public ClassLoader getClassLoader(String file) {
    synchronized (this) {
        try {
            final URL[] us;
            File file2 = new File(file);
            ClassLoader result = path2Loader.get(file2.getCanonicalPath());
            if (result != null) {
                return result;
            }
            us = new URL[] { file2.toURI().toURL() };
            result = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {

                public URLClassLoader run() {
                    return new URLClassLoader(us);
                }
            });
            path2Loader.put(file2.getCanonicalPath(), result);
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}
Also used : PrivilegedAction(java.security.PrivilegedAction) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) URL(java.net.URL)

Example 8 with PrivilegedAction

use of java.security.PrivilegedAction in project OpenAM by OpenRock.

the class NamingService method initialize.

public static void initialize() {
    namingDebug = Debug.getInstance("amNaming");
    platformProperties = SystemProperties.getAll();
    server_proto = platformProperties.getProperty("com.iplanet.am.server.protocol", "");
    server_host = platformProperties.getProperty("com.iplanet.am.server.host", "");
    server_port = platformProperties.getProperty(Constants.AM_SERVER_PORT, "");
    PrivilegedAction<SSOToken> adminAction = InjectorHolder.getInstance(Key.get(new TypeLiteral<PrivilegedAction<SSOToken>>() {
    }));
    sso = AccessController.doPrivileged(adminAction);
    try {
        ssmNaming = new ServiceSchemaManager(NAMING_SERVICE, sso);
        ssmPlatform = new ServiceSchemaManager(PLATFORM_SERVICE, sso);
        serviceRevNumber = ssmPlatform.getRevisionNumber();
    } catch (SMSException | SSOException e) {
        throw new IllegalStateException(e);
    }
    ServiceListeners.Action action = new ServiceListeners.Action() {

        @Override
        public void performUpdate() {
            try {
                updateNamingTable();
                WebtopNaming.updateNamingTable();
            } catch (Exception ex) {
                namingDebug.error("Error occured in updating naming table", ex);
            }
        }
    };
    ServiceListeners builder = InjectorHolder.getInstance(ServiceListeners.class);
    builder.config(NAMING_SERVICE).global(action).schema(action).listen();
    builder.config(PLATFORM_SERVICE).global(action).schema(action).listen();
}
Also used : ServiceListeners(com.iplanet.services.naming.ServiceListeners) PrivilegedAction(java.security.PrivilegedAction) SSOToken(com.iplanet.sso.SSOToken) TypeLiteral(com.google.inject.TypeLiteral) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) SSOException(com.iplanet.sso.SSOException)

Example 9 with PrivilegedAction

use of java.security.PrivilegedAction in project opennms by OpenNMS.

the class JBossMBeanServerConnector method createConnection.

@Override
public JmxServerConnectionWrapper createConnection(final InetAddress ipAddress, final Map<String, String> propertiesMap) throws JmxServerConnectionException {
    JBossConnectionWrapper wrapper = null;
    ClassLoader icl = null;
    final ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
    String connectionType = ParameterMap.getKeyedString(propertiesMap, "factory", "RMI");
    String timeout = ParameterMap.getKeyedString(propertiesMap, "timeout", "3000");
    String jbossVersion = ParameterMap.getKeyedString(propertiesMap, "version", "4");
    String port = ParameterMap.getKeyedString(propertiesMap, "port", "1099");
    if (jbossVersion == null || jbossVersion.startsWith("4")) {
        try {
            icl = new IsolatingClassLoader("jboss", new URL[] { new File(System.getProperty("opennms.home") + "/lib/jboss/jbossall-client.jar").toURI().toURL() }, originalLoader, PACKAGES, true);
        } catch (MalformedURLException e) {
            LOG.error("JBossConnectionWrapper MalformedURLException", e);
        } catch (InvalidContextClassLoaderException e) {
            LOG.error("JBossConnectionWrapper InvalidContextClassLoaderException", e);
        }
    } else if (jbossVersion.startsWith("3")) {
        PrivilegedAction<IsolatingClassLoader> action = new PrivilegedAction<IsolatingClassLoader>() {

            @Override
            public IsolatingClassLoader run() {
                try {
                    return new IsolatingClassLoader("jboss", new URL[] { new File(System.getProperty("opennms.home") + "/lib/jboss/jbossall-client32.jar").toURI().toURL() }, originalLoader, PACKAGES, true);
                } catch (MalformedURLException e) {
                    LOG.error("JBossConnectionWrapper MalformedURLException", e);
                } catch (InvalidContextClassLoaderException e) {
                    LOG.error("JBossConnectionWrapper InvalidContextClassLoaderException", e);
                }
                return null;
            }
        };
        AccessController.doPrivileged(action);
    }
    if (icl == null) {
        return null;
    }
    Thread.currentThread().setContextClassLoader(icl);
    if (connectionType.equals("RMI")) {
        InitialContext ctx = null;
        final String hostAddress = InetAddressUtils.toUrlIpAddress(ipAddress);
        try {
            Hashtable<String, String> props = new Hashtable<String, String>();
            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
            props.put(Context.PROVIDER_URL, "jnp://" + hostAddress + ":" + port);
            props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            props.put("jnp.sotimeout", timeout);
            ctx = new InitialContext(props);
            Object rmiAdaptor = ctx.lookup("jmx/rmi/RMIAdaptor");
            wrapper = new JBossConnectionWrapper(MBeanServerProxy.buildServerProxy(rmiAdaptor));
        } catch (Throwable e) {
            LOG.debug("JBossConnectionFactory - unable to get MBeanServer using RMI on {}:{}", hostAddress, port);
        } finally {
            try {
                if (ctx != null) {
                    ctx.close();
                }
            } catch (Throwable e1) {
                LOG.debug("JBossConnectionFactory error closing initial context");
            }
        }
    } else if (connectionType.equals("HTTP")) {
        InitialContext ctx = null;
        String invokerSuffix = null;
        final String hostAddress = InetAddressUtils.toUrlIpAddress(ipAddress);
        try {
            Hashtable<String, String> props = new Hashtable<String, String>();
            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
            props.put(Context.PROVIDER_URL, "http://" + hostAddress + ":" + port + "/invoker/JNDIFactory");
            props.put("jnp.sotimeout", timeout);
            ctx = new InitialContext(props);
            Object rmiAdaptor = ctx.lookup("jmx/rmi/RMIAdaptor");
            wrapper = new JBossConnectionWrapper(MBeanServerProxy.buildServerProxy(rmiAdaptor));
        } catch (Throwable e) {
            LOG.debug("JBossConnectionFactory - unable to get MBeanServer using HTTP on {}{}", hostAddress, invokerSuffix);
        } finally {
            try {
                if (ctx != null)
                    ctx.close();
            } catch (NamingException e1) {
                LOG.debug("JBossConnectionFactory error closing initial context");
            }
        }
    }
    Thread.currentThread().setContextClassLoader(originalLoader);
    return wrapper;
}
Also used : MalformedURLException(java.net.MalformedURLException) Hashtable(java.util.Hashtable) InvalidContextClassLoaderException(org.opennms.netmgt.jmx.impl.connection.connectors.IsolatingClassLoader.InvalidContextClassLoaderException) URL(java.net.URL) InitialContext(javax.naming.InitialContext) PrivilegedAction(java.security.PrivilegedAction) NamingException(javax.naming.NamingException) File(java.io.File)

Example 10 with PrivilegedAction

use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.

the class ButtonArraysEquality method main.

public static void main(String[] s) {
    int[] buttonDownMasksAPI = new int[MouseInfo.getNumberOfButtons()];
    for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++) {
        buttonDownMasksAPI[i] = InputEvent.getMaskForButton(i + 1);
        System.out.println("TEST: " + buttonDownMasksAPI[i]);
    }
    // getButtonDownMasks()
    Object obj = AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            try {
                Class clazz = Class.forName("java.awt.event.InputEvent");
                Method method = clazz.getDeclaredMethod("getButtonDownMasks", new Class[] {});
                if (method != null) {
                    method.setAccessible(true);
                    return method.invoke(null, (Object[]) null);
                }
            } catch (Exception e) {
                throw new RuntimeException("Test failed. Exception occured:", e);
            }
            return null;
        }
    });
    int[] buttonDownMasks = new int[Array.getLength(obj)];
    checkNullAndPutValuesToArray(buttonDownMasks, obj);
    //check lengths: array shouldn't contain less elements then the number of buttons on a mouse
    if (buttonDownMasks.length < buttonDownMasksAPI.length) {
        throw new RuntimeException("Test failed. The lengths array is less then the number of buttons");
    }
    // verify values for first three buttons
    for (int i = 0; i < 3; i++) {
        if (eventDownMask[i] != buttonDownMasks[i]) {
            System.out.println("Test : " + i + " | " + " | " + eventDownMask[i] + " | " + buttonDownMasks[i]);
            throw new RuntimeException("Failure: masks are not correct for standard buttons");
        }
    }
    // verify values for extra buttons if any
    for (int i = 3; i < MouseInfo.getNumberOfButtons(); i++) {
        if (buttonDownMasksAPI[i] != buttonDownMasks[i]) {
            throw new RuntimeException("Failure: masks are not the same for extra buttons");
        }
    }
    System.out.println("Test passed.");
}
Also used : PrivilegedAction(java.security.PrivilegedAction)

Aggregations

PrivilegedAction (java.security.PrivilegedAction)359 IOException (java.io.IOException)85 Subject (javax.security.auth.Subject)61 AccessControlContext (java.security.AccessControlContext)31 File (java.io.File)29 HashMap (java.util.HashMap)29 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)29 Method (java.lang.reflect.Method)24 ArrayList (java.util.ArrayList)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)21 InputStream (java.io.InputStream)21 URL (java.net.URL)21 FileNotFoundException (java.io.FileNotFoundException)18 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 Iterator (java.util.Iterator)18 MalformedURLException (java.net.MalformedURLException)17 List (java.util.List)17 UnknownHostException (java.net.UnknownHostException)16 Principal (java.security.Principal)15 PrivilegedActionException (java.security.PrivilegedActionException)15