List of usage examples for java.security PrivilegedAction PrivilegedAction
PrivilegedAction
From source file:com.agimatec.validation.jsr303.util.SecureActions.java
public static Class<?> loadClass(final String className, final Class<?> caller) { return run(new PrivilegedAction<Class<?>>() { public Class<?> run() { try { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); if (contextClassLoader != null) { return contextClassLoader.loadClass(className); }// w ww .j av a2 s. com } catch (Throwable e) { // ignore } try { return Class.forName(className, true, caller.getClassLoader()); } catch (ClassNotFoundException e) { throw new ValidationException("Unable to load class: " + className, e); } } }); }
From source file:SecurityActions.java
static void setTCL(final ClassLoader tcl) { if (System.getSecurityManager() == null) { Thread.currentThread().setContextClassLoader(tcl); } else {// ww w . jav a2 s .c om AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { Thread.currentThread().setContextClassLoader(tcl); return null; } }); } }
From source file:org.mule.ibeans.internal.config.IBeansInfo.java
public static Manifest getManifest() { if (manifest == null) { manifest = new Manifest(); InputStream is = null;/* www . jav a2s . com*/ try { // We want to load the MANIFEST.MF from the mule-core jar. Sine we // don't know the version we're using we have to search for the jar on the classpath URL url = AccessController.doPrivileged(new PrivilegedAction<URL>() { public URL run() { try { Enumeration e = MuleConfiguration.class.getClassLoader() .getResources(("META-INF/MANIFEST.MF")); while (e.hasMoreElements()) { URL url = (URL) e.nextElement(); if ((url.toExternalForm().indexOf("ibeans-core") > -1 && url.toExternalForm().indexOf("tests.jar") < 0)) { return url; } } } catch (IOException e1) { logger.warn("Failure reading manifest: " + e1.getMessage(), e1); } return null; } }); if (url != null) { is = url.openStream(); } if (is != null) { manifest.read(is); } } catch (IOException e) { logger.warn("Failed to read manifest Info, Manifest information will not display correctly: " + e.getMessage()); } } return manifest; }
From source file:Main.java
public static IIOMetadataFormat instantiateMetadataFormat(String formatName, boolean standardFormatSupported, String nativeMetadataFormatName, String nativeMetadataFormatClassName, String[] extraMetadataFormatNames, String[] extraMetadataFormatClassNames) { if (formatName == null) { throw new IllegalArgumentException("formatName == null!"); }/*from w w w . j a v a 2 s. c o m*/ if (formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) { if (standardFormatSupported) { return IIOMetadataFormatImpl.getStandardFormatInstance(); } } String className = null; if (formatName.equals(nativeMetadataFormatName)) { className = nativeMetadataFormatClassName; } else if (extraMetadataFormatNames != null) { for (int i = 0; i < extraMetadataFormatNames.length; i++) { if (formatName.equals(extraMetadataFormatNames[i])) { className = extraMetadataFormatClassNames[i]; break; } } } if (className == null) { throw new IllegalArgumentException("Unsupported format name"); } // Get the context class loader and try to use it first ClassLoader contextClassloader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } }); Class cls; try { cls = Class.forName(className, true, contextClassloader); } catch (ClassNotFoundException e) { try { // Use current class loader cls = Class.forName(className); } catch (ClassNotFoundException e1) { throw new IllegalStateException("Can't obtain format"); } } try { //???AWT: //Method getInstance = cls.getMethod("getInstance"); //return (IIOMetadataFormat) getInstance.invoke(null); return null; } catch (Exception e) { IllegalStateException e1 = new IllegalStateException("Can't obtain format"); e1.initCause(e); // Add some details to the message throw e1; } }
From source file:Main.java
/** * Changes the locale of the messages.//ww w .j av a2s .c o m * * @param locale * Locale the locale to change to. * @param resource * the name of the bundle resource */ static public ResourceBundle setLocale(final Locale locale, final String resource) { try { // BEGIN android-removed // final ClassLoader loader = VM.bootCallerClassLoader(); // END android-removed return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { // BEGIN android-changed return ResourceBundle.getBundle(resource, locale, ClassLoader.getSystemClassLoader()); // END android-changed } }); } catch (MissingResourceException e) { } return null; }
From source file:edu.ku.brc.helpers.ZipFileHelper.java
/** * //from ww w. ja va 2 s. c o m */ public ZipFileHelper() { super(); AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { cleanUp(); } }); return null; } }); }
From source file:com.github.persapiens.jsfboot.undertow.JsfUndertowDeploymentInfoCustomizer.java
@Override public void customize(final DeploymentInfo di) { AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override//from www .j a v a2s . co m public Void run() { ClassLoader jsfClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader()); di.setClassLoader(jsfClassLoader); di.setResourceManager( new ClassPathResourceManager(jsfClassLoader, undertowProperties.getClassPathResource())); return null; } }); LOGGER.info("Setting Undertow classLoader to " + undertowProperties.getClassPathResource() + " directory"); }
From source file:SecuritySupport.java
static String getSystemProperty(final String propName) { return (String) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(propName); }// w w w . jav a2 s . c om }); }
From source file:org.apache.axis.utils.BeanUtils.java
private static PropertyDescriptor[] getPropertyDescriptors(final Class secJavaType) { return (PropertyDescriptor[]) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { PropertyDescriptor[] result = null; // START FIX http://nagoya.apache.org/bugzilla/showattachment.cgi?attach_id=4937 try { // privileged code goes here if (AxisFault.class.isAssignableFrom(secJavaType)) { // Don't include AxisFault data result = Introspector.getBeanInfo(secJavaType, AxisFault.class).getPropertyDescriptors(); } else if (Throwable.class != secJavaType && Throwable.class.isAssignableFrom(secJavaType)) { // Don't include Throwable data result = Introspector.getBeanInfo(secJavaType, Throwable.class).getPropertyDescriptors(); } else { // privileged code goes here result = Introspector.getBeanInfo(secJavaType).getPropertyDescriptors(); }/*from ww w . j a v a 2 s . c o m*/ // END FIX http://nagoya.apache.org/bugzilla/showattachment.cgi?attach_id=4937 } catch (java.beans.IntrospectionException Iie) { } return result; } }); }
From source file:spring.osgi.context.internal.classloader.BundleDelegatingClassLoader.java
/** * Factory method for creating a class loader over the given bundle and with * a given class loader as fall-back. In case the bundle cannot find a class * or locate a resource, the given class loader will be used as fall back. * * @param bundle bundle used for class loading and resource acquisition * @param bridge class loader used as fall back in case the bundle cannot * load a class or find a resource. Can be <code>null</code> * @return class loader adapter over the given bundle and class loader *///from w w w. j a v a2 s. c o m public static BundleDelegatingClassLoader createBundleClassLoaderFor(final Bundle bundle, final ClassLoader bridge) { return (BundleDelegatingClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return new BundleDelegatingClassLoader(bundle, bridge); } }); }