List of usage examples for java.security AccessController doPrivileged
@CallerSensitive public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
From source file:org.nebulaframework.deployment.classloading.GridArchiveClassLoader.java
/** * Attempts to find the given Class with in the {@code GridArchive}. If * found (either as direct class file or with in a {@code .jar} library * inside {@code .nar} file), returns the Class instance for it. * /*from ww w . j a v a 2 s . c om*/ * @return the {@code Class<?>} instance for the class to be loaded * * @throws ClassNotFoundException if unable to find the class */ @Override public Class<?> findClass(String name) throws ClassNotFoundException { try { // Convert class name to file name final String fileName = name.replaceAll("\\.", "/") + ".class"; // Search in Archive | Exception if failed byte[] bytes = AccessController.doPrivileged(new PrivilegedExceptionAction<byte[]>() { @Override public byte[] run() throws IOException, ClassNotFoundException { return findInArchive(fileName); } }); // If found, define class and return return defineClass(name, bytes, 0, bytes.length, REMOTE_CODESOURCE); } catch (Exception e) { throw new ClassNotFoundException("Unable to locate class", e); } }
From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java
public void removeAttribute(final String name, final int scope) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }/*from w w w. jav a 2s.com*/ if (SecurityUtil.isPackageProtectionEnabled()) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { doRemoveAttribute(name, scope); return null; } }); } else { doRemoveAttribute(name, scope); } }
From source file:edu.ku.brc.af.ui.forms.validation.TypeSearchForQueryFactory.java
/** * Returns the instance to the singleton * // w w w . ja v a 2 s.co m * @return the instance to the singleton */ public static TypeSearchForQueryFactory getInstance() { if (instance != null) { return instance; } // else String factoryNameStr = AccessController.doPrivileged(new java.security.PrivilegedAction<String>() { public String run() { return System.getProperty(factoryName); } }); if (isNotEmpty(factoryNameStr)) { try { return instance = (TypeSearchForQueryFactory) Class.forName(factoryNameStr).newInstance(); } catch (Exception e) { e.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SecurityMgr.class, e); InternalError error = new InternalError( "Can't instantiate TypeSearchForQueryFactory factory " + factoryNameStr); //$NON-NLS-1$ error.initCause(e); throw error; } } return instance = new TypeSearchForQueryFactory(); }
From source file:org.apache.openjpa.enhance.Reflection.java
/** * Make the given member accessible if it isn't already. *//*from w ww .j av a2 s . c om*/ private static void makeAccessible(AccessibleObject ao, int mods) { try { if (!Modifier.isPublic(mods) && !ao.isAccessible()) AccessController.doPrivileged(J2DoPrivHelper.setAccessibleAction(ao, true)); } catch (SecurityException se) { throw new UserException(_loc.get("reflect-security", ao)).setFatal(true); } }
From source file:org.apache.axis.AxisProperties.java
/** * !WARNING!/*from w w w .j a v a 2 s. c o m*/ * SECURITY issue. * * See bug 11874 * * The solution to both is to move doPrivilege UP within AXIS to a * class that is either private (cannot be reached by code outside * AXIS) or that represents a secure public interface... * * This is going to require analysis and (probably) rearchitecting. * So, I'm taking taking the easy way out until we are at a point * where we can reasonably rearchitect for security. */ private static Object newInstance(final SPInterface spi, final DefaultClassHolder defaultClass) { return AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { return DiscoverClass.newInstance(null, spi, (PropertiesHolder) null, defaultClass); } catch (Exception e) { log.error(Messages.getMessage("exception00"), e); } return null; } }); }
From source file:org.apache.openjpa.lib.meta.ClassArgParser.java
/** * Returns the class named in the given .class file. *//* ww w.ja va 2 s.c om*/ private String getFromClassFile(File file) throws IOException { FileInputStream fin = null; try { fin = AccessController.doPrivileged(J2DoPrivHelper.newFileInputStreamAction(file)); return getFromClass(fin); } catch (PrivilegedActionException pae) { throw (FileNotFoundException) pae.getException(); } finally { if (fin != null) try { fin.close(); } catch (IOException ioe) { } } }
From source file:org.apache.cxf.common.logging.LogUtils.java
private static void setContextClassLoader(final ClassLoader classLoader) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { Thread.currentThread().setContextClassLoader(classLoader); return null; }//www .ja v a 2 s .com }); } else { Thread.currentThread().setContextClassLoader(classLoader); } }
From source file:com.aliyun.odps.local.common.utils.LocalRunUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Collection<File> listFiles(final File dir, final String relativePath) throws IOException { // privileged code, for this method may be invoked by user code try {/*from w w w .ja v a2s . c o m*/ return (Collection<File>) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { File relativeDir = new File(dir, relativePath); checkParent(dir, relativePath); if (relativeDir.isDirectory()) { return FileUtils.listFiles(relativeDir, new InternalIOFilter(), new InternalIOFilter()); } else { Collection<File> files = new java.util.LinkedList<File>(); files.add(relativeDir); return files; } } }); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw e; } } }
From source file:org.apache.jasper.runtime.PageContextImpl.java
public void setAttribute(final String name, final Object attribute) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }//w w w . j a v a 2 s . co m if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { doSetAttribute(name, attribute); return null; } }); } else { doSetAttribute(name, attribute); } }
From source file:es.mityc.javasign.pkstore.mscapi.mityc.SunMSCAPI_MITyC.java
public SunMSCAPI_MITyC() { super("SunMSCAPI_MITyC", 1.71d, INFO); // if there is no security manager installed, put directly into // the provider. Otherwise, create a temporary map and use a // doPrivileged() call at the end to transfer the contents final Map<Object, Object> map = (System.getSecurityManager() == null) ? (Map<Object, Object>) this : new HashMap<Object, Object>(); /*//from ww w . java 2 s . c o m * Secure random */ map.put("SecureRandom.Windows-PRNG", "es.mityc.javasign.pkstore.mscapi.mityc.PRNG"); /* * Key store */ map.put("KeyStore.Windows-MY", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$MY"); map.put("KeyStore.Windows-ROOT", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$ROOT"); map.put("KeyStore.Windows-CA", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$CA"); map.put("KeyStore.Windows-LocalMachine-MY", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$LocalMachineMY"); map.put("KeyStore.Windows-LocalMachine-ROOT", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$LocalMachineROOT"); map.put("KeyStore.Windows-LocalMachine-CA", "es.mityc.javasign.pkstore.mscapi.mityc.KeyStore$LocalMachineCA"); /* * Signature engines */ map.put("Signature.SHA1withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA1"); map.put("Signature.SHA256withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA256"); map.put("Signature.SHA384withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA384"); map.put("Signature.SHA512withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$SHA512"); map.put("Signature.MD5withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$MD5"); map.put("Signature.MD2withRSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSASignature$MD2"); /* * Algorithms aliases */ map.put("Alg.Alias.Signature.RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA/RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA-1/RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1/RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHAwithRSA", "SHA1witRSA"); map.put("Alg.Alias.Signature.RSAWithSHA1", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.29", "SHA1withRSA"); map.put("Alg.Alias.Signature.OID.1.3.14.3.2.29", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1withRSAEncryption", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1WithRSAEncryption", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1RSA", "SHA1withRSA"); map.put("Alg.Alias.Signature.SHA1WITHRSAENCRYPTION", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.1", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.26with1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.11", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256withRSAEncryption", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256WithRSAEncryption", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256/RSA", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA-256/RSA", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256RSA", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA256WITHRSAENCRYPTION", "SHA256withRSA"); map.put("Alg.Alias.Signature.SHA384withRSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.12", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384withRSAEncryption", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384WithRSAEncryption", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384/RSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA-384/RSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384RSA", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA384WITHRSAENCRYPTION", "SHA384withRSA"); map.put("Alg.Alias.Signature.SHA512withRSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.13", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512withRSAEncryption", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512WithRSAEncryption", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512/RSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA-512/RSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512RSA", "SHA512withRSA"); map.put("Alg.Alias.Signature.SHA512WITHRSAENCRYPTION", "SHA512withRSA"); // supported key classes map.put("Signature.SHA1withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.SHA256withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.SHA384withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.SHA512withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.MD5withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.MD2withRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); map.put("Signature.NONEwithRSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); /* * Key Pair Generator engines */ map.put("KeyPairGenerator.RSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSAKeyPairGenerator"); map.put("KeyPairGenerator.RSA KeySize", "1024"); /* * Cipher engines */ map.put("Cipher.RSA", "es.mityc.javasign.pkstore.mscapi.mityc.RSACipher"); map.put("Cipher.RSA/ECB/PKCS1Padding", "es.mityc.javasign.pkstore.mscapi.mityc.RSACipher"); map.put("Cipher.RSA SupportedModes", "ECB"); map.put("Cipher.RSA SupportedPaddings", "PKCS1PADDING"); map.put("Cipher.RSA SupportedKeyClasses", "es.mityc.javasign.pkstore.mscapi.mityc.Key"); if (map != this) { AccessController.doPrivileged(new PutAllAction(this, map)); } }