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:SecretWordPermission.java

public String getWord() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(new SecretWordPermission("AccessPermission"));
    }//  ww  w. java2  s.co  m
    return "Secret";
}

From source file:SecurityActions.java

static ClassLoader getClassLoader(final Class<?> clazz) {
    if (System.getSecurityManager() == null) {
        return clazz.getClassLoader();
    } else {/* w  w  w. ja  v  a 2s . c o m*/
        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
            public ClassLoader run() {
                return clazz.getClassLoader();
            }
        });
    }

}

From source file:org.mobicents.slee.container.util.ObjectCloner.java

public static <T> T makeDeepCopy(final T orig) {

    if (System.getSecurityManager() != null) {
        try {//from   w w w .j a v a  2  s . co m
            return AccessController.doPrivileged(new PrivilegedExceptionAction<T>() {

                public T run() throws Exception {

                    return _makeDeepCopy(orig);
                }
            });
        } catch (PrivilegedActionException e) {
            if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            } else {
                throw new SLEEException("Failed to create object copy.", e);
            }
        }
    } else {
        return _makeDeepCopy(orig);
    }
}

From source file:org.eclipse.gemini.blueprint.util.LogUtils.java

/**
 * Set the TCCL of the bundle before creating the logger. This helps if commons-logging is used since it looks at
 * the existing TCCL before associating a LogFactory with it and since the TCCL can be the
 * BundleDelegatingClassLoader, loading a LogFactory using the BundleDelegatingClassLoader will result in an
 * infinite cycle or chained failures that would be swallowed.
 * //from   ww  w.  ja  v a2 s.  c  o m
 * <p/> Create the logger using LogFactory but use a simple implementation if something goes wrong.
 * 
 * @param logName log name
 * @return logger implementation
 */
public static Log createLogger(final Class<?> logName) {
    if (System.getSecurityManager() != null) {
        return AccessController.doPrivileged(new PrivilegedAction<Log>() {
            public Log run() {
                return doCreateLogger(logName);
            }
        });
    }
    return doCreateLogger(logName);
}

From source file:org.apache.hadoop.hdfs.DnsMonitorSecurityManager.java

/**
 * Update's the system's security manager to an instance of this class if
 * system property dns_call_stack_logging is set to true.
 *//*  w w w. j a va  2s.  c  o m*/
public static void setTheManager() {
    if ("true".equalsIgnoreCase(System.getProperty(ACTIVATE_FLAG))) {
        if (!(System.getSecurityManager() instanceof DnsMonitorSecurityManager)) {
            System.setSecurityManager(theManager);
        }
    }
}

From source file:Main.java

/**
 * checks the security permissions for accessing system clipboard
 *
 * for untrusted context (see isTrustedContext) checks the
 * permissions for the current event being handled
 *
 *//*  w w w  . j  a  va  2s  . c om*/
public static boolean canAccessSystemClipboard() {
    boolean canAccess = false;
    if (!GraphicsEnvironment.isHeadless()) {
        SecurityManager sm = System.getSecurityManager();
        if (sm == null) {
            canAccess = true;
        } else {
            try {
                sm.checkSystemClipboardAccess();
                canAccess = true;
            } catch (SecurityException e) {
            }
            if (canAccess && !isTrustedContext()) {
                canAccess = canCurrentEventAccessSystemClipboard(true);
            }
        }
    }
    return canAccess;
}

From source file:SecurityActions.java

static void setTCL(final ClassLoader tcl) {
    if (System.getSecurityManager() == null) {
        Thread.currentThread().setContextClassLoader(tcl);
    } else {/*from  www .  j a  v  a 2 s .  com*/
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                Thread.currentThread().setContextClassLoader(tcl);
                return null;
            }
        });
    }
}

From source file:org.ngrinder.sm.SecurityManagerTest.java

@Before
public void init() {
    System.setProperty("ngrinder.exec.path", PATH);
    System.setProperty("ngrinder.etc.hosts", "10.34.64.36,CN14748-D-1:127.0.0.1,localhost:127.0.0.1");
    System.setProperty("ngrinder.console.ip", "10.34.63.53");
    preSecurityManager = System.getSecurityManager();
    System.setSecurityManager(new MockNGrinderSecurityManager());
}

From source file:org.apache.accumulo.server.security.SecurityConstants.java

public static TCredentials getSystemCredentials() {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(SYSTEM_CREDENTIALS_PERMISSION);
    }//from  w w w .  j a va  2  s  . co  m
    return systemCredentials;
}

From source file:com.symbian.driver.remoting.master.TestMaster.java

/**
 * //from  w w w.  ja  v  a  2s  .  c o  m
 */
public TestMaster() {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }
}