Example usage for java.security AccessController checkPermission

List of usage examples for java.security AccessController checkPermission

Introduction

In this page you can find the example usage for java.security AccessController checkPermission.

Prototype


public static void checkPermission(Permission perm) throws AccessControlException 

Source Link

Document

Determines whether the access request indicated by the specified permission should be allowed or denied, based on the current AccessControlContext and security policy.

Usage

From source file:org.jwebsocket.plugins.scripting.app.Manifest.java

/**
 * Checks the app sandbox security permissions dependecy.
 *
 * @param aPerms//from  w  w w .j  av  a2s  .  c o  m
 * @param aGrantedPerms
 * @param aAppDirPath
 * @throws Exception
 */
public static void checkPermissions(List<String> aPerms, Permissions aGrantedPerms, String aAppDirPath)
        throws Exception {
    for (String lPerm : aPerms) {
        final String lExpandedPerm = JWebSocketConfig
                .expandEnvVarsAndProps(lPerm.replace("${APP_HOME}", aAppDirPath));
        try {
            Tools.doPrivileged(aGrantedPerms, new PrivilegedAction<Boolean>() {
                @Override
                public Boolean run() {
                    AccessController.checkPermission(Tools.stringToPermission(lExpandedPerm));
                    return true;
                }
            });
        } catch (AccessControlException lEx) {
            throw new Exception(
                    "Unable to load application. Permission requirement '" + lPerm + "' not satisfied!");
        }
    }
}

From source file:org.jwebsocket.util.Tools.java

/**
 *
 */// w ww.ja  va2 s .c  om
public static void startUtilityThreadPool() {
    if (System.getProperties().contains("JWEBSOCKET_HOME")) {
        AccessController.checkPermission(stringToPermission(
                "permission java.util.PropertyPermission \"" + "org.jwebsocket.tools.threadpool\", \"write\""));
    }

    if (null == mThreadPool) {
        mThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r, "jWebSocket Utility ThreadPool");
                    }
                });
    }
}

From source file:org.jwebsocket.util.Tools.java

/**
 *
 *///from w w w . j av a 2  s .c o  m
public static void stopUtilityThreadPool() {
    if (System.getProperties().contains("JWEBSOCKET_HOME")) {
        AccessController.checkPermission(stringToPermission(
                "permission java.util.PropertyPermission \"" + "org.jwebsocket.tools.threadpool\", \"write\""));
    }

    if (null != mThreadPool && !mThreadPool.isShutdown()) {
        mThreadPool.shutdownNow();
    }
    mThreadPool = null;
}

From source file:org.jwebsocket.util.Tools.java

/**
 *
 * @return//from   w w  w  .jav  a  2s.c  o  m
 */
public static ExecutorService getThreadPool() {
    if (System.getProperties().contains("JWEBSOCKET_HOME")) {
        AccessController.checkPermission(stringToPermission(
                "permission java.util.PropertyPermission \"" + "org.jwebsocket.tools.threadpool\", \"write\""));
    }

    if (null == mThreadPool) {
        startUtilityThreadPool();
    }

    return mThreadPool;
}

From source file:org.jwebsocket.util.Tools.java

/**
 * Starts the jWebSocket utility timer. The timer automatically purge expired tasks every 5
 * minute./*from www  . ja va 2 s . co m*/
 */
public static void startUtilityTimer() {
    if (System.getProperties().contains("JWEBSOCKET_HOME")) {
        AccessController.checkPermission(stringToPermission(
                "permission java.util.PropertyPermission \"" + "org.jwebsocket.tools.timer\", \"write\""));
    }

    if (null == mTimer) {
        mTimer = new Timer("jWebSocket Utility Timer");
        final Timer lTimer = mTimer;
        mTimer.scheduleAtFixedRate(new JWSTimerTask() {
            @Override
            public void runTask() {
                lTimer.purge();
            }
        }, 0, 300000);
    }
}

From source file:org.jwebsocket.util.Tools.java

/**
 * Stops the jWebSocket utility time./*  w w  w  . j a v a 2 s. c  o m*/
 */
public static void stopUtilityTimer() {
    if (System.getProperties().contains("JWEBSOCKET_HOME")) {
        AccessController.checkPermission(stringToPermission(
                "permission java.util.PropertyPermission \"" + "org.jwebsocket.tools.timer\", \"write\""));
    }

    if (null != mTimer) {
        mTimer.cancel();
        mTimer.purge();
    }

    mTimer = null;
}

From source file:org.jwebsocket.util.Tools.java

/**
 *
 * @return A jWebSocket shared utility timer
 *//*from w w  w . java2s  .c  o  m*/
public static Timer getTimer() {
    if (System.getProperties().contains("JWEBSOCKET_HOME")) {
        AccessController.checkPermission(stringToPermission(
                "permission java.util.PropertyPermission \"" + "org.jwebsocket.tools.timer\", \"write\""));
    }

    if (null == mTimer) {
        startUtilityTimer();
    }
    return mTimer;
}