Example usage for java.lang SecurityException SecurityException

List of usage examples for java.lang SecurityException SecurityException

Introduction

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

Prototype

public SecurityException() 

Source Link

Document

Constructs a SecurityException with no detail message.

Usage

From source file:Main.java

@Override
public void checkListen(int port) {
    throw new SecurityException();
}

From source file:Main.java

@Override
public void checkPackageAccess(String pkg) {
    throw new SecurityException();
}

From source file:Main.java

@Override
public void checkPackageDefinition(String pkg) {
    throw new SecurityException();
}

From source file:Main.java

@Override
public void checkMemberAccess(Class<?> clazz, int which) {
    throw new SecurityException();
}

From source file:hu.tvdr.serialport.serialport.java

public void SerialPortCall(File device, int baudrate, int flags) throws SecurityException, IOException {

    /* Check access permission */
    if (!device.canRead() || !device.canWrite()) {
        try {//from  ww w.j  a v  a 2s. c o m
            /* Missing read/write permission, trying to chmod the file */
            Process su;
            su = Runtime.getRuntime().exec("/system/bin/su");
            String cmd = "chmod 666 " + device.getAbsolutePath() + "\n" + "exit\n";
            su.getOutputStream().write(cmd.getBytes());
            if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
                throw new SecurityException();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new SecurityException();
        }
    }

    mFd = open(device.getAbsolutePath(), baudrate, flags);
    if (mFd == null) {
        Log.e(TAG, "native open returns null");
        throw new IOException();
    }
    mFileInputStream = new FileInputStream(mFd);
    mFileOutputStream = new FileOutputStream(mFd);
}

From source file:com.samczsun.helios.Helios.java

public static void main(String[] args, Shell shell, Splash splashScreen) {
    System.setSecurityManager(new SecurityManager() {
        @Override//from www .  ja v  a  2 s .  c  o  m
        public void checkPermission(Permission perm) {
        }

        @Override
        public void checkPermission(Permission perm, Object context) {
        }

        @Override
        public void checkCreateClassLoader() {
        }

        @Override
        public void checkAccess(Thread t) {
        }

        @Override
        public void checkAccess(ThreadGroup g) {
        }

        @Override
        public void checkExit(int status) {
            if (!getClassContext()[3].getCanonicalName().startsWith("com.samczsun")) {
                throw new SecurityException(); //Baksmali
            }
        }

        @Override
        public void checkExec(String cmd) {
        }

        @Override
        public void checkLink(String lib) {
        }

        @Override
        public void checkRead(FileDescriptor fd) {
        }

        @Override
        public void checkRead(String file) {
        }

        @Override
        public void checkRead(String file, Object context) {
        }

        @Override
        public void checkWrite(FileDescriptor fd) {
        }

        @Override
        public void checkWrite(String file) {
        }

        @Override
        public void checkDelete(String file) {
        }

        @Override
        public void checkConnect(String host, int port) {
        }

        @Override
        public void checkConnect(String host, int port, Object context) {
        }

        @Override
        public void checkListen(int port) {
        }

        @Override
        public void checkAccept(String host, int port) {
        }

        @Override
        public void checkMulticast(InetAddress maddr) {
        }

        @Override
        public void checkMulticast(InetAddress maddr, byte ttl) {
        }

        @Override
        public void checkPropertiesAccess() {
        }

        @Override
        public void checkPropertyAccess(String key) {
        }

        @Override
        public boolean checkTopLevelWindow(Object window) {
            return true;
        }

        @Override
        public void checkPrintJobAccess() {
        }

        @Override
        public void checkSystemClipboardAccess() {
        }

        @Override
        public void checkAwtEventQueueAccess() {
        }

        @Override
        public void checkPackageAccess(String pkg) {
        }

        @Override
        public void checkPackageDefinition(String pkg) {
        }

        @Override
        public void checkSetFactory() {
        }

        @Override
        public void checkMemberAccess(Class<?> clazz, int which) {
        }

        @Override
        public void checkSecurityAccess(String target) {
        }
    });
    try {
        if (!System.getProperty("os.name").toLowerCase().contains("linux")) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
    } catch (Exception exception) { //Not important. No point notifying the user
    }
    splashScreen.updateState(BootSequence.LOADING_SETTINGS);
    Settings.loadSettings();
    backgroundTaskGui = new BackgroundTaskGui();
    backgroundTaskHandler = new BackgroundTaskHandler();
    splashScreen.updateState(BootSequence.LOADING_ADDONS);
    AddonHandler.registerPreloadedAddons();
    for (File file : Constants.ADDONS_DIR.listFiles()) {
        AddonHandler.getAllHandlers().stream().filter(handler -> handler.accept(file)).findFirst()
                .ifPresent(handler -> {
                    handler.run(file);
                });
    }
    splashScreen.updateState(BootSequence.SETTING_UP_GUI);
    gui = new GUI(shell);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        Settings.saveSettings();
        getBackgroundTaskHandler().shutdown();
        processes.forEach(Process::destroy);
    }));
    splashScreen.updateState(BootSequence.COMPLETE);
    while (!splashScreen.isDisposed())
        ;
    Display.getDefault().syncExec(() -> getGui().getShell().open());

    List<File> open = new ArrayList<>();

    for (String name : args) {
        File file = new File(name);
        if (file.exists()) {
            open.add(file);
        }
    }

    submitBackgroundTask(() -> {
        Map<String, LoadedFile> newPath = new HashMap<>();
        for (String strFile : Sets.newHashSet(Settings.PATH.get().asString().split(";"))) {
            File file = new File(strFile);
            if (file.exists()) {
                try {
                    LoadedFile loadedFile = new LoadedFile(file);
                    newPath.put(loadedFile.getName(), loadedFile);
                } catch (IOException e1) {
                    ExceptionHandler.handle(e1);
                }
            }
        }
        synchronized (Helios.class) {
            path.clear();
            path.putAll(newPath);
        }
    });

    if (open.size() > 0) {
        openFiles(open.toArray(new File[open.size()]), true);
    }
}

From source file:it.smartcommunitylab.aac.apikey.APIKeyController.java

/**
 * Delete a specified API key/*  w  w  w . j  a  v a 2  s. co  m*/
 * @param apiKey
 * @return
 */
@ApiOperation(value = "Delete key")
@DeleteMapping(value = "/apikey/{apiKey:.*}")
public @ResponseBody void deleteKey(HttpServletRequest request, @PathVariable String apiKey)
        throws SecurityException {
    APIKey key = keyManager.findKey(apiKey);
    if (key != null) {
        String clientId = getClientId(request);
        if (!clientId.equals(key.getClientId())) {
            throw new SecurityException();
        }
        keyManager.deleteKey(apiKey);
    }
}

From source file:com.link_intersystems.lang.reflect.SerializableMethodTest.java

@Override
protected Method getMethod(Class<?> declaringClass, String methodName, Class<?>[] parameterTypes)
        throws NoSuchMethodException {
    throw new SecurityException();
}

From source file:com.link_intersystems.lang.reflect.SerializableConstructorTest.java

@Override
protected Constructor<?> getConstructor(Class<?> declaringClass, Class<?>[] parameterTypes)
        throws NoSuchMethodException {
    throw new SecurityException();
}

From source file:com.liferay.maven.arquillian.internal.tasks.ExecuteDeployerTask.java

protected void executeTool(String deployerClassName, ClassLoader classLoader, String[] args) throws Exception {

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    currentThread.setContextClassLoader(classLoader);

    SecurityManager currentSecurityManager = System.getSecurityManager();

    // Required to prevent premature exit by DBBuilder. See LPS-7524.
    SecurityManager securityManager = new SecurityManager() {

        @Override//from ww  w .  j av  a  2  s  .  c o m
        public void checkPermission(Permission permission) {
        }

        @Override
        public void checkExit(int status) {
            throw new SecurityException();
        }
    };

    System.setSecurityManager(securityManager);

    try {
        System.setProperty("external-properties",
                "com/liferay/portal/tools/dependencies" + "/portal-tools.properties");
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");

        Class<?> clazz = classLoader.loadClass(deployerClassName);

        Method method = clazz.getMethod("main", String[].class);

        method.invoke(null, (Object) args);
    } catch (InvocationTargetException ite) {
        if (!(ite.getCause() instanceof SecurityException)) {
            throw ite;
        }
    } finally {
        currentThread.setContextClassLoader(contextClassLoader);

        System.setSecurityManager(currentSecurityManager);
    }
}