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;
}
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;
}
}
}
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();
}
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;
}
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.");
}
Aggregations