List of usage examples for java.security PrivilegedAction PrivilegedAction
PrivilegedAction
From source file:org.javascool.polyfilewriter.Gateway.java
/** * Create a File object from the Path./*from www. ja v a 2s .com*/ * * @param path * @return */ private File getFile(final String path) { return AccessController.doPrivileged(new PrivilegedAction<File>() { public File run() { return new File(path); } }); }
From source file:org.commonjava.sshwrap.config.DefaultSSHConfiguration.java
static String userHome() { return AccessController.doPrivileged(new PrivilegedAction<String>() { @Override/* ww w . j a v a 2 s.c o m*/ public String run() { return System.getProperty("user.home"); } }); }
From source file:org.apache.axis2.jaxws.server.JAXWSMessageReceiver.java
/** * Set context class loader of the current thread. * * @param cl the context ClassLoader for the Thread *///from w w w . java2 s . c o m private void setContextClassLoader(final ClassLoader cl) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { Thread.currentThread().setContextClassLoader(cl); return null; } }); }
From source file:org.eclipse.gemini.blueprint.config.internal.adapter.OsgiServiceLifecycleListenerAdapter.java
public void unbind(final Object service, final Map properties) throws Exception { boolean trace = log.isTraceEnabled(); if (!initialized) retrieveTarget();/*from ww w. j av a 2s .com*/ if (trace) log.trace("Invoking unbind method for service " + ObjectUtils.identityToString(service) + " with props=" + properties); boolean isSecurityEnabled = (System.getSecurityManager() != null); AccessControlContext acc = null; if (isSecurityEnabled) { acc = SecurityUtils.getAccFrom(beanFactory); } // first call interface method (if it exists) if (isLifecycleListener) { if (trace) log.trace("Invoking listener interface methods"); try { if (isSecurityEnabled) { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { ((OsgiServiceLifecycleListener) target).unbind(service, properties); return null; } }, acc); } else { ((OsgiServiceLifecycleListener) target).unbind(service, properties); } } catch (Exception ex) { log.warn("Standard unbind method on [" + target.getClass().getName() + "] threw exception", ex); } } if (isSecurityEnabled) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { CustomListenerAdapterUtils.invokeCustomMethods(target, unbindMethods, service, properties); invokeCustomServiceReferenceMethod(target, unbindReference, service); return null; } }, acc); } else { CustomListenerAdapterUtils.invokeCustomMethods(target, unbindMethods, service, properties); invokeCustomServiceReferenceMethod(target, unbindReference, service); } }
From source file:org.apache.axis2.jaxws.client.async.CallbackFuture.java
@SuppressWarnings("unchecked") public Object call() throws Exception { ClassLoader oldCL = null;/*from w ww . ja v a2 s .c o m*/ try { if (log.isDebugEnabled()) { log.debug("Setting up the thread's context classLoader"); log.debug(handlerCL.toString()); } // Retrieve the existing classloader from the thread. oldCL = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return Thread.currentThread().getContextClassLoader(); } }); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { Thread.currentThread().setContextClassLoader(handlerCL); return null; } }); // Set the response or fault content on the AsyncResponse object // so that it can be collected inside the Executor thread and processed. if (error != null) { response.onError(error, msgCtx, handlerCL); } else { response.onComplete(msgCtx, handlerCL); } // Now that the content is available, call the JAX-WS AsyncHandler class // to deliver the response to the user. if (debug) { log.debug("Calling JAX-WS AsyncHandler.handleResponse() with response object: " + CallbackFuture.displayHandle(response)); } handler.handleResponse(response); if (debug) { log.debug("Returned from handleResponse() invocation..."); } } catch (Throwable t) { if (debug) { log.debug("An error occurred while invoking the callback object."); log.debug("Error: " + t.toString()); t.printStackTrace(); } } finally { synchronized (this) { // Restore the old classloader on this thread. if (oldCL != null) { final ClassLoader t = oldCL; AccessController.doPrivileged(new PrivilegedAction() { public Object run() { Thread.currentThread().setContextClassLoader(t); return null; } }); if (debug) { log.debug("Restored thread context classloader: " + oldCL.toString()); } } done = true; this.notifyAll(); } } return null; }
From source file:org.apache.axis2.jaxws.description.impl.DescriptionUtils.java
/** * A doPriv version of getInputStream//from www . ja v a 2s .c o m * @return */ private static InputStream getInputStream_priv(final String path, final ClassLoader classLoader) { return (InputStream) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return getInputStream(path, classLoader); } }); }
From source file:org.acmsl.commons.BundleI14able.java
/** * Builds an internationalized message for given key, parameters * and locale./*from w ww . j a v a 2 s. com*/ * @param key the message key. * @param params the message parameters. * @param locale the locale. * @param bundleName the bundle name. * @param systemProperty the name of the bundle. * @param useClassLoader whether to use class loader or not. * @param firstBundle the first bundle. * @param secondBundle the second bundle. * @param retryBundles whether to retry bundle retrieval or not. * @return the customized message. */ protected String buildMessage(@NotNull final String key, @NotNull final Object[] params, @NotNull final Locale locale, @NotNull final String bundleName, @NotNull final String systemProperty, final boolean useClassLoader, @Nullable final ResourceBundle firstBundle, @Nullable final ResourceBundle secondBundle, final boolean retryBundles) { ResourceBundle t_FirstBundle = firstBundle; ResourceBundle t_SecondBundle = secondBundle; if (retryBundles) { ClassLoader t_ClassLoader = getClass().getClassLoader(); if (useClassLoader) { // Identify the class loader we will be using final ClassLoader t_AnotherClassLoader = AccessController .doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { ClassLoader result = null; try { result = getContextClassLoader(); } catch (final IllegalAccessException exception) { // We'll use the Class.getClassLoader(); } catch (final InvocationTargetException exception) { // We'll use the Class.getClassLoader(); } return result; } }); if (t_AnotherClassLoader != null) { t_ClassLoader = t_AnotherClassLoader; } } if (t_FirstBundle == null) { t_FirstBundle = retrieveSystemPropertyBundle(systemProperty, locale, t_ClassLoader); if (t_FirstBundle != null) { setFirstBundle(t_FirstBundle); } } if (t_SecondBundle == null) { t_SecondBundle = retrieveBundle(bundleName, locale, t_ClassLoader); if (t_SecondBundle != null) { setSecondBundle(t_SecondBundle); } } setRetryBundles(false); } return buildMessage(key, params, t_FirstBundle, t_SecondBundle); }
From source file:org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingProvider.java
public Invoker createInvoker(Operation operation) { Options options = new Options(); org.apache.axis2.addressing.EndpointReference epTo = getWSATOEPR(wsBinding); if (epTo != null) { options.setTo(epTo);/* w w w.j a va2 s. c o m*/ } options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); String operationName = operation.getName(); String soapAction = getSOAPAction(operationName); if (soapAction != null && soapAction.length() > 1) { options.setAction(soapAction); } options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds // Allow privileged access to read properties. Requires PropertiesPermission read in // security policy. SOAPFactory soapFactory = AccessController.doPrivileged(new PrivilegedAction<SOAPFactory>() { public SOAPFactory run() { if (isSOAP12Required) return OMAbstractFactory.getSOAP12Factory(); else return OMAbstractFactory.getSOAP11Factory(); } }); QName wsdlOperationQName = new QName(operationName); if (isMTOMRequired) { options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); } return new Axis2ReferenceBindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); /* if (operation.isNonBlocking()) { invoker = new Axis2OneWayBindingInvoker(this, wsdlOperationQName, options, soapFactory, wsBinding); } else { invoker = new Axis2BindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); } return invoker; */ }
From source file:org.apache.axis2.util.Utils.java
private static boolean exists(final File file) { Boolean exists = (Boolean) org.apache.axis2.java.security.AccessController .doPrivileged(new PrivilegedAction<Boolean>() { public Boolean run() { return new Boolean(file.exists()); }/* ww w . ja v a2s .c om*/ }); return exists.booleanValue(); }
From source file:org.openconcerto.sql.model.SQLBase.java
private final <T extends Exception, S extends StructureSource<T>> S refreshTables(final S src) throws T { this.checkDropped(); synchronized (getTreeMutex()) { src.init();//from ww w. j a va2 s. co m // refresh schemas final Set<String> newSchemas = src.getTotalSchemas(); final Set<String> currentSchemas = src.getExistingSchemasToRefresh(); mustContain(this, newSchemas, currentSchemas, "schemas"); final CollectionChangeEventCreator c = this.createChildrenCreator(); // remove all schemas that are not there anymore for (final String schema : CollectionUtils.substract(currentSchemas, newSchemas)) { this.schemas.remove(schema).dropped(); } // delete the saved schemas that we could have fetched, but haven't // (schemas that are not in scope are simply ignored, NOT deleted) AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { for (final DBItemFileCache savedSchema : getSavedCaches(false)) { if (src.isInTotalScope(savedSchema.getName()) && !newSchemas.contains(savedSchema.getName())) { savedSchema.delete(); } } return null; } }); // clearNonPersistent (will be recreated by fillTables()) for (final String schema : CollectionUtils.inter(currentSchemas, newSchemas)) { this.getSchema(schema).clearNonPersistent(); } // create the new ones for (final String schema : newSchemas) { this.createAndGetSchema(schema); } // refresh tables final Set<SQLName> newTableNames = src.getTotalTablesNames(); final Set<SQLName> currentTables = src.getExistingTablesToRefresh(); // we can only add, cause instances of SQLTable are everywhere mustContain(this, newTableNames, currentTables, "tables"); // remove dropped tables for (final SQLName tableName : CollectionUtils.substract(currentTables, newTableNames)) { final SQLSchema s = this.getSchema(tableName.getItemLenient(-2)); s.rmTable(tableName.getName()); } // clearNonPersistent for (final SQLName tableName : CollectionUtils.inter(newTableNames, currentTables)) { final SQLSchema s = this.getSchema(tableName.getItemLenient(-2)); s.getTable(tableName.getName()).clearNonPersistent(); } // create new table descendants (including empty tables) for (final SQLName tableName : CollectionUtils.substract(newTableNames, currentTables)) { final SQLSchema s = this.getSchema(tableName.getItemLenient(-2)); s.addTable(tableName.getName()); } // fill with columns src.fillTables(); this.fireChildrenChanged(c); // don't signal our systemRoot if our server doesn't yet reference us, // otherwise the server will create another instance and enter an infinite loop assert this.getServer().getBase(this.getName()) == this; final TablesMap byRoot; final TablesMap toRefresh = src.getToRefresh(); if (toRefresh == null) { byRoot = TablesMap.createByRootFromChildren(this, null); } else { final DBRoot root = this.getDBRoot(); if (root != null) { byRoot = TablesMap.createFromTables(root.getName(), toRefresh.get(null)); } else { byRoot = toRefresh; } } this.getDBSystemRoot().descendantsChanged(byRoot, src.hasExternalStruct()); } src.save(); return src; }