List of usage examples for java.lang System getSecurityManager
public static SecurityManager getSecurityManager()
From source file:org.jboss.as.forge.util.Files.java
static String getProperty(final String key) { if (System.getSecurityManager() == null) { return System.getProperty(key); }//from w w w .j av a 2 s. c o m return AccessController.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { return System.getProperty(key); } }); }
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; }/* w w w . j a v a 2 s. c o m*/ }); } else { Thread.currentThread().setContextClassLoader(classLoader); } }
From source file:org.apache.camel.management.DefaultManagementAgent.java
protected void createMBeanServer() { String hostName;//w w w. j av a 2 s .c o m boolean canAccessSystemProps = true; try { // we'll do it this way mostly to determine if we should lookup the hostName SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPropertiesAccess(); } } catch (SecurityException se) { canAccessSystemProps = false; } if (canAccessSystemProps) { try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { LOG.info("Cannot determine localhost name. Using default: " + DEFAULT_REGISTRY_PORT, uhe); hostName = DEFAULT_HOST; } } else { hostName = DEFAULT_HOST; } server = findOrCreateMBeanServer(); try { // Create the connector if we need if (createConnector) { createJmxConnector(hostName); } } catch (IOException ioe) { LOG.warn("Could not create and start JMX connector.", ioe); } }
From source file:org.apache.catalina.core.ApplicationContextFacade.java
public Object getAttribute(String name) { if (System.getSecurityManager() != null) { return doPrivileged("getAttribute", new Object[] { name }); } else {/*w ww .ja v a2 s .c o m*/ return context.getAttribute(name); } }
From source file:org.pepstock.jem.ant.tasks.StepListener.java
/** * Called by ANT engine when a step is ended.<br> * Notifies to JEM a summary about step execution (i.e. return-code, * exception).//from ww w . j a va 2s. c om * * @param event ANT event */ @Override public void targetFinished(BuildEvent event) { AntBatchSecurityManager batchSM = (AntBatchSecurityManager) System.getSecurityManager(); batchSM.setInternalAction(true); // checks if the target name is empty. if yes, does nothing if (!"".equals(event.getTarget().getName())) { try { // creates object to send to JEM Step step = new Step(); // sets step name and description step.setName(event.getTarget().getName()); step.setDescription(event.getTarget().getDescription()); // checks if has an exception.If yes, sets ERROR, otherwise // SUCCESS step.setReturnCode((event.getException() != null) ? Result.ERROR : Result.SUCCESS); // checks if has an exception, sets the exception message if (event.getException() != null) { step.setException(event.getException().getMessage()); } // send to JEM by RMI door.setStepEnded(JobId.VALUE, step); // if setp locking scope is st, unlocks resources if (isStepLockingScope()) { locker.unlock(); } } catch (AntException e) { throw new BuildException(e); } catch (RemoteException e) { throw new BuildException(e); } finally { batchSM.setInternalAction(false); } } batchSM.setInternalAction(false); }
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")); }/* ww w .j a v a2s. c om*/ if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { doSetAttribute(name, attribute); return null; } }); } else { doSetAttribute(name, attribute); } }
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();/* w ww . j a va2s. 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.codehaus.wadi.core.manager.TomcatSessionIdFactory.java
/** Use /dev/random-type special device. This is new code, but may reduce the * big delay in generating the random.//from ww w . java 2 s . c o m * * You must specify a path to a random generator file. Use /dev/urandom * for linux ( or similar ) systems. Use /dev/random for maximum security * ( it may block if not enough "random" exist ). You can also use * a pipe that generates random. * * The code will check if the file exists, and default to java Random * if not found. There is a significant performance difference, very * visible on the first call to getSession ( like in the first JSP ) * - so use it if available. */ public void setRandomFile(String s) { // as a hack, you can use a static file - and genarate the same // session ids ( good for strange traceging ) if (System.getSecurityManager() != null) { randomIS = (DataInputStream) AccessController.doPrivileged(new PrivilegedSetRandomFile()); } else { try { devRandomSource = s; File f = new File(devRandomSource); if (!f.exists()) return; randomIS = new DataInputStream(new FileInputStream(f)); randomIS.readLong(); // if( log.isTraceEnabled() ) // log.trace( "Opening " + devRandomSource ); } catch (IOException ex) { randomIS = null; } } }
From source file:org.apache.catalina.core.ApplicationContextFacade.java
public Enumeration getAttributeNames() { if (System.getSecurityManager() != null) { return (Enumeration) doPrivileged("getAttributeNames", null); } else {/*w ww. j ava 2s . c om*/ return context.getAttributeNames(); } }
From source file:org.apache.cxf.common.logging.LogUtils.java
private static ClassLoader getContextClassLoader() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); }/*from www . j ava2 s .c o m*/ }); } return Thread.currentThread().getContextClassLoader(); }