Example usage for java.lang System getSecurityManager

List of usage examples for java.lang System getSecurityManager

Introduction

In this page you can find the example usage for java.lang System getSecurityManager.

Prototype

public static SecurityManager getSecurityManager() 

Source Link

Document

Gets the system-wide security manager.

Usage

From source file:org.sonatype.gshell.vfs.provider.truezip.TruezipFileSystem.java

/**
 * Creates a temporary local copy of a file and its descendants.
 *//*from ww w .j  a  v a 2 s  . c  o  m*/
protected java.io.File doReplicateFile(final FileObject fileObject, final FileSelector selector)
        throws Exception {
    final TruezipFileObject localFile = (TruezipFileObject) fileObject;
    final File file = localFile.getLocalFile();

    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        final FilePermission requiredPerm = new FilePermission(file.getAbsolutePath(), "read");
        sm.checkPermission(requiredPerm);
    }

    return file;
}

From source file:com.symbian.driver.remoting.client.TestClient.java

/**
 * //from   www . j  ava  2  s.  co m
 */
public TestClient() {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }
}

From source file:org.rhq.core.pc.util.LoggingThreadFactory.java

/**
 * Creates a factory that will produce either daemon or non-daemon threads. Be careful if you pass in <code>
 * false</code> for the <code>daemon</code> parameter; if you do, make sure your thread pool and all its threads
 * created by this factory are properly shutdown; otherwise you could prevent the VM from exiting properly.
 *
 * @param poolName the name of the thread pool that will be using this factory
 * @param daemon   if <code>true</code>, the factory will create daemon threads; <code>false</code> for non-daemon
 *                 threads//from   w  ww  . j  ava  2s .  c  o  m
 */
public LoggingThreadFactory(String poolName, boolean daemon) {
    this.poolName = poolName;
    this.log = LogFactory.getLog("org.rhq.threadpools." + poolName);
    this.daemon = daemon;

    SecurityManager s = System.getSecurityManager();
    group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
}

From source file:org.siyapath.task.TaskProcessor.java

/**
 * @param task//from   w w  w  . j  a v a2  s . co m
 */
public TaskProcessor(String name, Task task, NodeContext nodeContext) {
    super(name);
    this.task = task;
    context = nodeContext;
    context.increaseProTasksNo(task.getTaskID());
    notifier = new LivenessNotifier("LivenessNotifier-" + context.getNodeInfo().toString());
    siyapathSecurityManager = new SiyapathSecurityManager("secpass");
    defaultSecurityManager = System.getSecurityManager();
    taskResult = new Result(task.getJobID(), task.getTaskID(), TaskStatus.PROCESSING, null,
            CommonUtils.serialize(context.getNodeInfo()), task.getTaskReplicaIndex());
}

From source file:org.rhq.enterprise.server.util.LoggingThreadFactory.java

/**
 * Creates a factory that will produce either daemon or non-daemon threads. Be careful if you pass in <code>
 * false</code> for the <code>daemon</code> parameter; if you do, make sure your thread pool and all its threads
 * created by this factory are properly shutdown; otherwise you could prevent the VM from exiting properly.
 *
 * @param poolName the name of the thread pool that will be using this factory
 * @param daemon   if <code>true</code>, the factory will create daemon threads; <code>false</code> for non-daemon
 *                 threads// ww  w. j av a 2 s.  c om
 */
public LoggingThreadFactory(String poolName, boolean daemon) {
    this.poolName = poolName;
    this.log = LogFactory.getLog("org.rhq.server.threadpools." + poolName);
    this.daemon = daemon;

    SecurityManager s = System.getSecurityManager();
    group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
}

From source file:org.kie.workbench.common.migration.MigrationToolTest.java

@BeforeClass
public static void runToolAndCloneProjectRepos() throws GitAPIException {
    originalSecurityManager = System.getSecurityManager();
    System.setSecurityManager(new NoExitSecurityManager());

    try {/*from w w  w  . j a v  a  2s. c  om*/
        runMigrationTool();
    } catch (ExitException e) {
        assertThat(e.getStatus()).isEqualTo(0);
    } finally {
        System.setSecurityManager(originalSecurityManager);
    }

    cloneAllProjectRepos();
}

From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java

static void disableSystemExitCall() {
    final SecurityManager securityManager = new SecurityManager() {

        @Override/*w  w  w . j  a  v  a  2 s  . c o  m*/
        public void checkPermission(Permission permission) {
            String name = permission.getName();
            if (name.startsWith("exitVM")) {
                throw new ExitTrapped(name);
            }
        }
    };

    oldSM = System.getSecurityManager();
    System.setSecurityManager(securityManager);
}

From source file:org.pepstock.jem.springbatch.tasks.ChunkDataSourcesManager.java

/**
 * Loads a JNDI context with all resources defined for chunk and usable inside of ItemReader, ItemProcessor and ItemWriter.
 * @param ic JNDI context, already created
 * @param dataSourceList list of data sources definitions
 * @throws SpringBatchException if any excetpion occurs
 * @throws NamingException if any excetpion occurs
 * @throws UnknownHostException if any excetpion occurs
 * @throws RemoteException if any excetpion occurs
 *//*from  ww w. jav a  2  s.  c o  m*/
static void loadJNDIContext(InitialContext ic, List<DataSource> dataSourceList)
        throws SpringBatchException, NamingException, RemoteException, UnknownHostException {
    SpringBatchSecurityManager batchSM = (SpringBatchSecurityManager) System.getSecurityManager();
    // scans all datasource passed
    for (DataSource source : dataSourceList) {
        // checks if datasource is well defined
        if (source.getResource() == null) {
            throw new SpringBatchException(SpringBatchMessage.JEMS016E);
        } else if (source.getName() == null) {
            // if name is missing, it uses the same string 
            // used to define the resource
            source.setName(source.getResource());
        }

        // gets the RMi object to get resources
        CommonResourcer resourcer = InitiatorManager.getCommonResourcer();
        // lookups by RMI for the database
        Resource res = resourcer.lookup(JobId.VALUE, source.getResource());
        if (!batchSM.checkResource(res)) {
            throw new SpringBatchException(SpringBatchMessage.JEMS017E, res.toString());
        }

        // all properties create all StringRefAddrs necessary
        Map<String, ResourceProperty> properties = res.getProperties();

        // scans all properteis set by JCL
        for (Property property : source.getProperties()) {
            if (property.isCustom()) {
                if (res.getCustomProperties() == null) {
                    res.setCustomProperties(new HashMap<String, String>());
                }
                if (!res.getCustomProperties().containsKey(property.getName())) {
                    res.getCustomProperties().put(property.getName(), property.getValue());
                } else {
                    throw new SpringBatchException(SpringBatchMessage.JEMS018E, property.getName(), res);
                }
            } else {
                // if a key is defined FINAL, throw an exception
                for (ResourceProperty resProperty : properties.values()) {
                    if (resProperty.getName().equalsIgnoreCase(property.getName())
                            && !resProperty.isOverride()) {
                        throw new SpringBatchException(SpringBatchMessage.JEMS018E, property.getName(), res);
                    }
                }
                ResourcePropertiesUtil.addProperty(res, property.getName(), property.getValue());
            }
        }
        // creates a JNDI reference
        Reference ref = null;
        try {
            ref = resourcer.lookupReference(JobId.VALUE, res.getType());
            if (ref == null) {
                throw new SpringBatchException(SpringBatchMessage.JEMS019E, res.getName(), res.getType());
            }
        } catch (Exception e) {
            throw new SpringBatchException(SpringBatchMessage.JEMS019E, e, res.getName(), res.getType());
        }

        // loads all properties into RefAddr
        for (ResourceProperty property : properties.values()) {
            ref.add(new StringRefAddr(property.getName(), replaceProperties(property.getValue())));
        }

        // loads custom properties in a string format
        if (res.getCustomProperties() != null && !res.getCustomProperties().isEmpty()) {
            // loads all entries and substitute variables
            for (Entry<String, String> entry : res.getCustomProperties().entrySet()) {
                String value = replaceProperties(entry.getValue());
                entry.setValue(value);
            }
            // adds to reference
            ref.add(new StringRefAddr(CommonKeys.RESOURCE_CUSTOM_PROPERTIES, res.getCustomPropertiesString()));
        }

        // binds the object with format {type]/[name]
        LogAppl.getInstance().emit(SpringBatchMessage.JEMS024I, res);
        ic.rebind(source.getName(), ref);
    }
}

From source file:org.firstopen.custom.view.EventMonitorBean.java

public EventMonitorBean(String name) throws InfrastructureException {
    if (System.getSecurityManager() == null) {

        System.setSecurityManager(new SecurityManager());
    }// w  w w.  j  a v a 2  s . c om

    JMSUtil.createQueue(MONITOR_NAME);
    connection = JMSUtil.getQueueConnection();
    try {
        queueSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        MessageConsumer receiver = queueSession.createConsumer(JMSUtil.getQueue(MONITOR_NAME));

        receiver.setMessageListener(this);

        connection.start();
    } catch (JMSException e) {

        log.error("unable to start listener on Queue");
        throw new InfrastructureException(e);
    }
}

From source file:org.apache.hadoop.hive.cli.TestCliDriverMethods.java

@Override
public void setUp() {
    securityManager = System.getSecurityManager();
    System.setSecurityManager(new NoExitSecurityManager(securityManager));
}