List of usage examples for java.security AccessController doPrivileged
@CallerSensitive public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
From source file:com.googlecode.arit.jmx.LeakDetector.java
public void afterPropertiesSet() throws Exception { timer = AccessController.doPrivileged(new PrivilegedAction<Timer>() { public Timer run() { timer = new Timer("LeakDetectorTimer"); timer.schedule(new TimerTask() { @Override/*from w w w. j a va2 s . co m*/ public void run() { try { runDetection(); } catch (Throwable ex) { log.error("Leak detection failed", ex); } } }, 0, 60000); return timer; } }); }
From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.EventAdminDispatcher.java
public void beforeClose(final BlueprintEvent event) { if (dispatcher != null) { try {// w w w.j a v a 2 s. co m if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { dispatcher.beforeClose(event); return null; } }); } else { dispatcher.beforeClose(event); } } catch (Throwable th) { log.warn("Cannot dispatch event " + event, th); } } }
From source file:org.apache.axis.configuration.EngineConfigurationFactoryFinder.java
/** * Create the default engine configuration and detect whether the user * has overridden this with their own.//from www .j a v a2 s.com * * The discovery mechanism will use the following logic: * * - discover all available EngineConfigurationFactories * - find all META-INF/services/org.apache.axis.EngineConfigurationFactory * files available through class loaders. * - read files (see Discovery) to obtain implementation(s) of that * interface * - For each impl, call 'newFactory(Object param)' * - Each impl should examine the 'param' and return a new factory ONLY * - if it knows what to do with it * (i.e. it knows what to do with the 'real' type) * - it can find it's configuration information * - Return first non-null factory found. * - Try EngineConfigurationFactoryServlet.newFactory(obj) * - Try EngineConfigurationFactoryDefault.newFactory(obj) * - If zero found (all return null), throw exception * * *** * This needs more work: System.properties, etc. * Discovery will have more tools to help with that * (in the manner of use below) in the near future. * *** * */ public static EngineConfigurationFactory newFactory(final Object obj) { /** * recreate on each call is critical to gaining * the right class loaders. Do not cache. */ final Object[] params = new Object[] { obj }; /** * Find and examine each service */ return (EngineConfigurationFactory) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ResourceClassIterator services = AxisProperties.getResourceClassIterator(mySpi); EngineConfigurationFactory factory = null; while (factory == null && services.hasNext()) { try { Class service = services.nextResourceClass().loadClass(); /* service == null * if class resource wasn't loadable */ if (service != null) { factory = newFactory(service, newFactoryParamTypes, params); } } catch (Exception e) { // there was an exception creating the factory // the most likely cause was the JDK 1.4 problem // in the discovery code that requires servlet.jar // to be in the client classpath. For now, fall // through to the next factory } } if (factory != null) { if (log.isDebugEnabled()) { log.debug(Messages.getMessage("engineFactory", factory.getClass().getName())); } } else { log.error(Messages.getMessage("engineConfigFactoryMissing")); // we should be throwing an exception here, // // but again, requires more refactoring than we want to swallow // at this point in time. Ifthis DOES occur, it's a coding error: // factory should NEVER be null. // Testing will find this, as NullPointerExceptions will be generated // elsewhere. } return factory; } }); }
From source file:com.apress.springosgi.ch9.testsosgi.testivyprovisions.LocalFileSystemIvyRepository.java
/** * Initialization method It determines the repository path by checking the * existence of <code>localRepository</code> system property and falling * back to the default <code>user.home/.ivy2/cache</code>. * /*from w w w. j a v a2s .co m*/ * <p/> This method is used to postpone initialization until an artifact is * actually located. As the test class is instantiated on each test run, the * init() method prevents repetitive, waste-less initialization. * */ private void init() { // already discovered a repository home, bailing out if (repositoryHome != null) return; boolean trace = log.isDebugEnabled(); final String[] sysProperties = new String[2]; // check system property AccessController.doPrivileged(new PrivilegedAction() { public Object run() { sysProperties[0] = System.getProperty(SYS_PROPERTY); sysProperties[1] = System.getProperty(USER_HOME_PROPERTY); return null; } }); String localRepository = sysProperties[0]; String userHome = sysProperties[1]; if (trace) log.trace("IVY2 system property [" + SYS_PROPERTY + "] has value=" + localRepository); if (localRepository == null) { // fall back to the default location localRepository = new File(userHome, DEFAULT_DIR).getAbsolutePath(); if (trace) log.trace("No custom setting found; using default M2 local repository=" + localRepository); } repositoryHome = localRepository; log.info("Local Ivy2 repository used: [" + repositoryHome + "]"); }
From source file:org.apache.webdav.connector.WebDAVManagedConnectionFactory.java
/** * @see ManagedConnectionFactory#createManagedConnection(Subject, * ConnectionRequestInfo)//from w ww.j a va 2 s.c o m */ public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { if (subject != null) { Properties props = new Properties(); WebDAVSubjectAction action = new WebDAVSubjectAction(subject, props, this); Boolean matched = (Boolean) AccessController.doPrivileged(action); if (matched.booleanValue()) { String userName = props.getProperty("userName"); String password = props.getProperty("password"); try { WebDAVConnectionSpec spec = new WebDAVConnectionSpec(connectionURL, userName, password, timeout.intValue()); System.out.println("Creating WebDAVConnection using JAAS Subject: " + userName); return new WebDAVManagedConnection(spec); } catch (IOException e) { throw new ResourceException("Could not create managed connection", e.toString()); } } else { // No matching credentials were found on the subject throw new ResourceException("Could not create managed connection"); } } if (cxRequestInfo instanceof WebDAVConnectionSpec) { try { System.out.println("Creating WebDAVConnection with WebDAVConnectionSpec"); return new WebDAVManagedConnection(cxRequestInfo); } catch (HttpException e) { if (writer != null) { writer.println("Exception: " + e); e.printStackTrace(writer); } // XXX only in 1.4 // throw new ResourceException("Could not create managed connection", e); throw new ResourceException("Could not create managed connection", e.toString()); } catch (IOException e) { if (writer != null) { writer.println("Exception: " + e); e.printStackTrace(writer); } // XXX only in 1.4 // throw new ResourceException("Could not create managed connection", e); throw new ResourceException("Could not create managed connection", e.toString()); } } try { if (connectionURL != null && username != null) { System.out.println("Creating WebDAVConnection with configured properties"); WebDAVConnectionSpec spec = new WebDAVConnectionSpec(connectionURL, username, password, timeout.intValue()); return new WebDAVManagedConnection(spec); } else { throw new ResourceException("Could not create managed connection"); } } catch (Exception e) { throw new ResourceException("Could not create managed connection", e.toString()); } }
From source file:org.apache.openjpa.lib.conf.ObjectValue.java
/** * Allow subclasses to instantiate additional plugins. This method does * not perform configuration./* w w w. j av a 2 s. com*/ */ public Object newInstance(String clsName, Class<?> type, Configuration conf, boolean fatal) { ClassLoader cl = (ClassLoader) _classloaderCache.get(type); if (cl == null) { cl = AccessController.doPrivileged(J2DoPrivHelper.getClassLoaderAction(type)); if (cl == null) { // System classloader is returned as null cl = AccessController.doPrivileged(J2DoPrivHelper.getSystemClassLoaderAction()); } _classloaderCache.put(type, cl); } return Configurations.newInstance(clsName, this, conf, cl, fatal); }
From source file:com.wavemaker.commons.classloader.ClassLoaderUtils.java
/** * Get a temporary classloader. By default, this will use the parent classloader as a base. * /* w ww .j ava 2 s .co m*/ * @param files * @return */ public static ClassLoader getTempClassLoaderForResources(Resource... files) { final List<Resource> filesList = Arrays.asList(files); ClassLoader ret = AccessController.doPrivileged(new PrivilegedAction<ThrowawayFileClassLoader>() { @Override public ThrowawayFileClassLoader run() { return new ThrowawayFileClassLoader(filesList, getClassLoader().getParent()); } }); return ret; }
From source file:com.liferay.portal.template.velocity.internal.LiferayResourceManager.java
@Override public Resource getResource(final String resourceName, final int resourceType, final String encoding) throws Exception, ParseErrorException, ResourceNotFoundException { for (String macroTemplateId : _macroTemplateIds) { if (resourceName.equals(macroTemplateId)) { // This resource is provided by the portal, so invoke it from an // access controller try { return AccessController.doPrivileged( new ResourcePrivilegedExceptionAction(resourceName, resourceType, encoding)); } catch (PrivilegedActionException pae) { throw pae.getException(); }/*from w w w . ja v a 2s .co m*/ } } return _getResource(resourceName, resourceType, encoding); }
From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapter.java
private String getCaCISRequestxml(final CaCISRequest parameter) { return AccessController.doPrivileged(new PrivilegedAction<String>() { public String run() { try { final CaCISURLClassLoader cl = new CaCISURLClassLoader(customLibDir, ClassLoader.getSystemClassLoader()); final Class jmClass = Class.forName("gov.nih.nci.cacis.sa.mirthconnect.JAXBMarshaller", true, cl);/*from w w w . j a v a 2 s. c o m*/ final Method m = jmClass.getMethod("marshal", Object.class); return (String) m.invoke(jmClass.newInstance(), parameter); // CHECKSTYLE:OFF } catch (Exception ex) { // CHECKSTYLE:ON LOG.error("Error marshalling CaCISRequest!", ex); return null; } } }); }
From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.LocalFileSystemMavenRepository.java
/** * Initialization method It determines the repository path by checking the * existence of <code>localRepository</code> system property and falling * back to the <code>settings.xml</code> file and then the traditional * <code>user.home/.m2/repository</code>. * //from w w w .j av a2 s . c o m * <p/> This method is used to postpone initialization until an artifact is * actually located. As the test class is instantiated on each test run, the * init() method prevents repetitive, waste-less initialization. * */ private void init() { // already discovered a repository home, bailing out if (repositoryHome != null) return; boolean trace = log.isDebugEnabled(); final String[] sysProperties = new String[2]; // check system property AccessController.doPrivileged(new PrivilegedAction() { public Object run() { sysProperties[0] = System.getProperty(SYS_PROPERTY); sysProperties[1] = System.getProperty(USER_HOME_PROPERTY); return null; } }); String localRepository = sysProperties[0]; String userHome = sysProperties[1]; if (trace) log.trace("M2 system property [" + SYS_PROPERTY + "] has value=" + localRepository); if (localRepository == null) { // if it's not present then check settings.xml local repository property Resource settingsFile = new FileSystemResource(new File(userHome, M2_SETTINGS)); localRepository = getMavenSettingsLocalRepository(settingsFile); if (trace) log.trace("Falling back to M2 settings.xml [" + settingsFile + "]; found value=" + localRepository); if (localRepository == null) { // fall back to the default location localRepository = new File(userHome, DEFAULT_DIR).getAbsolutePath(); if (trace) log.trace("No custom setting found; using default M2 local repository=" + localRepository); } } repositoryHome = localRepository; log.info("Local Maven2 repository used: [" + repositoryHome + "]"); }