List of usage examples for java.security AccessController doPrivileged
@CallerSensitive public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
From source file:org.apache.openjpa.lib.ant.AbstractTask.java
private String[] getFiles() { List<String> files = new ArrayList<String>(); for (FileSet fs : fileSets) { DirectoryScanner ds = fs.getDirectoryScanner(getProject()); String[] dsFiles = ds.getIncludedFiles(); for (int j = 0; j < dsFiles.length; j++) { File f = new File(dsFiles[j]); if (!(AccessController.doPrivileged(J2DoPrivHelper.isFileAction(f))).booleanValue()) f = new File(ds.getBasedir(), dsFiles[j]); files.add(AccessController.doPrivileged(J2DoPrivHelper.getAbsolutePathAction(f))); }/*from w w w .j a v a 2 s . com*/ } return (String[]) files.toArray(new String[files.size()]); }
From source file:org.acmsl.commons.regexpplugin.RegexpManager.java
/** * Retrieves current engine.// ww w. ja va2 s .c o m * Note: The lookup mechanism is adapted from Commons-Logging. * @param useClassLoader whether to use class loader or not. * @return the engine information. * @throws RegexpEngineNotFoundException if no engine can be used. */ @NotNull protected RegexpEngine getEngine(final boolean useClassLoader) throws RegexpEngineNotFoundException { @NotNull final RegexpEngine result; @NotNull ClassLoader t_ClassLoader = getClass().getClassLoader(); if (useClassLoader) { // Identify the class loader we will be using t_ClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return getContextClassLoader(); } }); } result = getEngineUsingClassLoader(t_ClassLoader); return result; }
From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java
public Object getAttribute(final String name) { if (name == null) { throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); }/*w w w. j a v a 2s . c om*/ if (SecurityUtil.isPackageProtectionEnabled()) { return AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return doGetAttribute(name); } }); } else { return doGetAttribute(name); } }
From source file:com.reelfx.controller.LinuxController.java
public static void deleteOutput() { AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override/*from w ww . ja v a 2s .c om*/ public Object run() { try { if (MERGED_OUTPUT_FILE.exists() && !MERGED_OUTPUT_FILE.delete()) throw new Exception("Can't delete the old preview file on Linux!"); } catch (Exception e) { e.printStackTrace(); } return null; } }); }
From source file:org.apache.openjpa.meta.InterfaceImplGenerator.java
private static boolean isGetter(Class<?> iface, FieldMetaData fmd) { if (fmd.getType() != boolean.class && fmd.getType() != Boolean.class) return true; try {//from www.j a v a2 s.c om Method meth = AccessController.doPrivileged(J2DoPrivHelper.getDeclaredMethodAction(iface, "is" + StringUtils.capitalize(fmd.getName()), (Class[]) null)); return meth == null; } catch (PrivilegedActionException pae) { } return true; }
From source file:org.apache.stanbol.commons.sphinx.impl.ModelProviderImpl.java
/** * Lookup an Sphinx data file via the {@link #dataFileProvider} * @param modelName the name of the model * @return the stream or <code>null</code> if not found * @throws IOException an any error while opening the model file *///from w w w .ja v a 2s. co m protected InputStream lookupModelStream(final String modelName) throws IOException { try { return AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() { @Override public InputStream run() throws IOException { return dataFileProvider.getInputStream(bundleSymbolicName, modelName, null); } }); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); if (e instanceof IOException) { throw (IOException) e; } else { throw RuntimeException.class.cast(e); } } }
From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.EventAdminDispatcher.java
public void waiting(final BlueprintEvent event) { if (dispatcher != null) { try {/*from w w w.ja va 2s . c om*/ if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { dispatcher.waiting(event); return null; } }); } else { dispatcher.waiting(event); } } catch (Throwable th) { log.warn("Cannot dispatch event " + event, th); } } }
From source file:com.asakusafw.compiler.bootstrap.BatchCompilerDriver.java
static boolean compile(File outputDirectory, Class<? extends BatchDescription> batchDescription, String packageName, Location hadoopWorkLocation, File compilerWorkDirectory, List<File> linkingResources, List<URL> pluginLibraries) { assert outputDirectory != null; assert batchDescription != null; assert packageName != null; assert hadoopWorkLocation != null; assert compilerWorkDirectory != null; assert linkingResources != null; try {/*from ww w . j a v a 2s. co m*/ BatchDriver analyzed = BatchDriver.analyze(batchDescription); if (analyzed.hasError()) { for (String diagnostic : analyzed.getDiagnostics()) { LOG.error(diagnostic); } return false; } String batchId = analyzed.getBatchClass().getConfig().name(); ClassLoader serviceLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { URLClassLoader loader = new URLClassLoader(pluginLibraries.toArray(new URL[pluginLibraries.size()]), BatchCompilerDriver.class.getClassLoader()); return loader; }); DirectBatchCompiler.compile(analyzed.getDescription(), packageName, hadoopWorkLocation, new File(outputDirectory, batchId), new File(compilerWorkDirectory, batchId), linkingResources, serviceLoader, FlowCompilerOptions.load(System.getProperties())); return true; } catch (Exception e) { LOG.error(MessageFormat.format(Messages.getString("BatchCompilerDriver.errorFailedToCompile"), //$NON-NLS-1$ batchDescription.getName()), e); return false; } }
From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.LocalFileSystemMavenRepository.java
/** * Find a local maven artifact. First tries to find the resource as a * packaged artifact produced by a local maven build, and if that fails will * search the local maven repository./*w w w . j a v a2s . c o m*/ * * @param groupId - the groupId of the organization supplying the bundle * @param artifactId - the artifact id of the bundle * @param version - the version of the bundle * @param type - the extension type of the artifact * @return */ public Resource locateArtifact(final String groupId, final String artifactId, final String version, final String type) { init(); return (Resource) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { return localMavenBuildArtifact(groupId, artifactId, version, type); } catch (IllegalStateException illStateEx) { Resource localMavenBundle = localMavenBundle(groupId, artifactId, version, type); if (log.isDebugEnabled()) { StringBuilder buf = new StringBuilder(); buf.append("["); buf.append(groupId); buf.append("|"); buf.append(artifactId); buf.append("|"); buf.append(version); buf.append("]"); log.debug(buf + " local maven build artifact detection failed, falling back to local maven bundle " + localMavenBundle.getDescription()); } return localMavenBundle; } } }); }
From source file:org.acoveo.tools.Reflection.java
/** * Invokes <code>cls.getDeclaredMethods()</code>, and returns the method * that matches the <code>name</code> and <code>param</code> arguments. * Avoids the exception thrown by <code>Class.getDeclaredMethod()</code> * for performance reasons. <code>param</code> may be null. Additionally, * if there are multiple methods with different return types, this will * return the method defined in the least-derived class. * * @since 0.9.8/* w ww . ja v a 2 s. c o m*/ */ static Method getDeclaredMethod(Class cls, String name, Class param) { Method[] methods = (Method[]) AccessController.doPrivileged(getDeclaredMethodsAction(cls)); Method candidate = null; for (int i = 0; i < methods.length; i++) { if (name.equals(methods[i].getName())) { Class[] methodParams = methods[i].getParameterTypes(); if (param == null && methodParams.length == 0) candidate = mostDerived(methods[i], candidate); else if (param != null && methodParams.length == 1 && param.equals(methodParams[0])) candidate = mostDerived(methods[i], candidate); } } return candidate; }