List of usage examples for java.security PrivilegedAction PrivilegedAction
PrivilegedAction
From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java
private void initializeJarCreator() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { jarCreator = new JarCreator(); return null; }// ww w. j a v a 2 s.c o m }); }
From source file:org.java.plugin.standard.StandardPluginLifecycleHandler.java
/** * Creates standard implementation of plug-in class loader. * @see org.java.plugin.standard.PluginLifecycleHandler#createPluginClassLoader( * org.java.plugin.registry.PluginDescriptor) *///w w w.j a v a 2 s. co m protected org.java.plugin.PluginClassLoader createPluginClassLoader(final PluginDescriptor descr) { /*StandardPluginClassLoader result = new StandardPluginClassLoader( getPluginManager(), descr, getClass().getClassLoader());*/ StandardPluginClassLoader result = (StandardPluginClassLoader) AccessController .doPrivileged(new PrivilegedAction() { public Object run() { return new StandardPluginClassLoader(getPluginManager(), descr, StandardPluginLifecycleHandler.this.getClass().getClassLoader()); } }); result.setProbeParentLoaderLast(probeParentLoaderLast); result.setStickySynchronizing(stickySynchronizing); result.setLocalClassLoadingOptimization(localClassLoadingOptimization); result.setForeignClassLoadingOptimization(foreignClassLoadingOptimization); return result; }
From source file:org.apache.hadoop.hbase.tool.coprocessor.CoprocessorValidator.java
private ResolverUrlClassLoader createClassLoader(URL[] urls, ClassLoader parent) { return AccessController.doPrivileged(new PrivilegedAction<ResolverUrlClassLoader>() { @Override/*from ww w . j a v a 2 s . com*/ public ResolverUrlClassLoader run() { return new ResolverUrlClassLoader(urls, parent); } }); }
From source file:tools.xor.util.ClassUtil.java
/** * Invoke the given method as a privileged action, if necessary. * @param target the object on which the method needs to be invoked * @param method to invoke//from www . ja v a2s. co m * @param args to the method * @return result of the invocation * @throws InvocationTargetException while invoking the method * @throws IllegalAccessException when accessing the meta data */ //public static Object invokeMethodAsPrivileged(final Object target, final Method method, final Object[] args) public static Object invokeMethodAsPrivileged(final Object target, final Method method, final Object... args) throws InvocationTargetException, IllegalAccessException { if (Modifier.isPublic(method.getModifiers())) if (args == null) return method.invoke(target); else return method.invoke(target, args); return AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { method.setAccessible(true); Object result = null; try { if (args == null) result = method.invoke(target); else result = method.invoke(target, args); } catch (Exception e) { throw wrapRun(e); } return result; } }); }
From source file:de.fuberlin.wiwiss.r2r.FunctionFactoryLoader.java
/** * tries to instantiate an FunctionFactory object. * It tries to load the class referenced by the TransformationFunction URI from the class path first. * The it tries to load it from the code location. * @param URI The URI of the TransformationFunction * @return the FunctionFactory object described by the information found at the given URI or null. * @throws MalformedURLException/*from w w w. j ava2 s.com*/ */ public FunctionFactory getFunctionFactory(String URI) throws MalformedURLException { boolean loadFromURLs = Config.getProperty("r2r.FunctionManager.loadFromURLs", "false") .equalsIgnoreCase("true"); FunctionFactory functionFactory = null; String codeLocation = null; String qualifiedClassName = null; String error = null; String query = "DESCRIBE <" + URI + ">"; Model model = repository.executeDescribeQuery(query); if (model.isEmpty()) { if (log.isDebugEnabled()) log.debug("External Function <" + URI + "> not found in repository."); return null; } Resource funcRes = model.getResource(URI); StmtIterator it = funcRes.listProperties(model.getProperty(R2R.qualifiedClassName)); if (it.hasNext()) qualifiedClassName = it.next().getString(); else { if (log.isDebugEnabled()) log.debug("External Function <" + URI + "> did not specify a qualified class name for loading!"); return null; } try { // First try to load from class path functionFactory = loadFunctionFactory(qualifiedClassName, ClassLoader.getSystemClassLoader()); // If FunctionFactory has been loaded, return it if (functionFactory != null) return functionFactory; if (!loadFromURLs) { if (log.isDebugEnabled()) log.debug("External Function <" + URI + "> could not be loaded from class path and loading by URL is disabled!"); return null; } // Now try the original code location it = funcRes.listProperties(model.getProperty(R2R.codeLocation)); if (it.hasNext()) codeLocation = it.next().getString(); else { if (log.isDebugEnabled()) log.debug("External Function <" + URI + "> could not be loaded from class path and did not specify any further code location!"); return null; } final String cl = codeLocation; URLClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { try { return new URLClassLoader(new URL[] { new URL(cl) }); } catch (MalformedURLException e) { if (log.isDebugEnabled()) log.debug("Malformed URL for code location: " + cl); return null; } } }); functionFactory = loadFunctionFactory(qualifiedClassName, loader); if (functionFactory != null) return functionFactory; else { if (log.isDebugEnabled()) log.debug("External Function <" + URI + "> could not be loaded: class " + qualifiedClassName + " could not be loaded from " + codeLocation + "."); return null; } } catch (InstantiationException e) { error = e.toString(); } catch (IllegalAccessException e) { error = e.toString(); } catch (ClassCastException e) { error = e.toString(); } if (error != null && log.isDebugEnabled()) log.debug("External Function <" + URI + "> could not be loaded: " + error); return functionFactory; }
From source file:org.apache.axis2.jaxws.client.async.AsyncResponse.java
protected void onError(Throwable flt, MessageContext mc, ClassLoader cl) { ClassLoader contextCL = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return Thread.currentThread().getContextClassLoader(); }// w ww. j a v a 2 s . c o m }); onError(flt, mc); checkClassLoader(cl, contextCL); }
From source file:com.agimatec.validation.jsr303.util.SecureActions.java
public static <T> Constructor<T> getConstructor(final Class<T> clazz, final Class<?>... params) { return run(new PrivilegedAction<Constructor<T>>() { public Constructor<T> run() { try { return clazz.getConstructor(params); } catch (NoSuchMethodException e) { return null; }/*from w w w .jav a 2s.c om*/ } }); }
From source file:org.jwebsocket.plugins.scripting.app.js.JavaScriptApp.java
/** * {@inheritDoc }/*from ww w. ja v a 2 s . c om*/ */ @Override public void notifyEvent(final String aEventName, final Object[] aArgs) { Settings lSettings = (Settings) JWebSocketBeanFactory.getInstance(ScriptingPlugIn.NS) .getBean("org.jwebsocket.plugins.scripting.settings"); // notifying event into security sandbox Tools.doPrivileged(lSettings.getAppPermissions(getName(), getPath()), new PrivilegedAction<Object>() { @Override public Object run() { try { // notifying event ((Invocable) getScriptApp()).invokeMethod(mApp, "notifyEvent", new Object[] { aEventName, aArgs }); return true; } catch (Exception lEx) { if (BaseScriptApp.EVENT_FILTER_IN.equals(aEventName)) { if (mLog.isDebugEnabled()) { mLog.debug( Logging.getSimpleExceptionMessage(lEx, "notifying '" + aEventName + "' event")); } throw new RuntimeException(lEx.getMessage()); } else { mLog.error(Logging.getSimpleExceptionMessage(lEx, "notifying '" + aEventName + "' event")); return false; } } } }); }
From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java
public static void assertManagementAccess(final SecurityManager securityManager, Subject subject) { Subject.doAs(subject, new PrivilegedAction<Void>() { @Override/* ww w . ja v a 2s.c om*/ public Void run() { securityManager.accessManagement(); return null; } }); }
From source file:org.mule.util.IOUtils.java
/** * Attempts to load a resource from the file system or from the classpath, in * that order./*from w ww . j a v a 2 s. co m*/ * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object * @param tryAsFile - try to load the resource from the local file system * @param tryAsUrl - try to load the resource as a Url string * @return an URL to the resource or null if resource not found */ public static URL getResourceAsUrl(final String resourceName, final Class callingClass, boolean tryAsFile, boolean tryAsUrl) { if (resourceName == null) { throw new IllegalArgumentException(CoreMessages.objectIsNull("Resource name").getMessage()); } URL url = null; // Try to load the resource from the file system. if (tryAsFile) { try { File file = FileUtils.newFile(resourceName); if (file.exists()) { url = file.getAbsoluteFile().toURL(); } else { logger.debug("Unable to load resource from the file system: " + file.getAbsolutePath()); } } catch (Exception e) { logger.debug("Unable to load resource from the file system: " + e.getMessage()); } } // Try to load the resource from the classpath. if (url == null) { try { url = (URL) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return ClassUtils.getResource(resourceName, callingClass); } }); if (url == null) { logger.debug("Unable to load resource " + resourceName + " from the classpath"); } } catch (Exception e) { logger.debug("Unable to load resource " + resourceName + " from the classpath: " + e.getMessage()); } } if (url == null) { try { url = new URL(resourceName); } catch (MalformedURLException e) { //ignore } } return url; }