Search in sources :

Example 16 with AccessControlException

use of java.security.AccessControlException in project jdk8u_jdk by JetBrains.

the class FilterWithSecurityManagerTest method testGlobalFilter.

/**
     * Test that setting process-wide filter is checked by security manager.
     */
@Test
public void testGlobalFilter() throws Exception {
    if (ObjectInputFilter.Config.getSerialFilter() == null) {
        return;
    }
    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais)) {
        ObjectInputFilter.Config.setSerialFilter(filter);
        assertFalse(setSecurityManager, "When SecurityManager exists, without " + "java.security.SerializablePermission(serialFilter) Exception should be thrown");
        Object o = ois.readObject();
    } catch (AccessControlException ex) {
        assertTrue(setSecurityManager);
        assertTrue(ex.getMessage().contains("java.io.SerializablePermission"));
        assertTrue(ex.getMessage().contains("serialFilter"));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AccessControlException(java.security.AccessControlException) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Example 17 with AccessControlException

use of java.security.AccessControlException in project jdk8u_jdk by JetBrains.

the class ExecCommand method main.

public static void main(String[] _args) throws Exception {
    if (!System.getProperty("os.name").startsWith("Windows")) {
        return;
    }
    // tear up
    try {
        new File(".\\Program Files").mkdirs();
        for (int i = 0; i < doCmdCopy.length; ++i) {
            try (BufferedWriter outCmd = new BufferedWriter(new FileWriter(doCmdCopy[i]))) {
                outCmd.write("@echo %1");
            }
        }
    } catch (IOException e) {
        throw new Error(e.getMessage());
    }
    // action
    for (int k = 0; k < 4; ++k) {
        switch(k) {
            case 0:
                // "true" by default with the legacy verification procedure
                break;
            case 1:
                System.setProperty("jdk.lang.Process.allowAmbiguousCommands", "false");
                break;
            case 2:
                System.setProperty("jdk.lang.Process.allowAmbiguousCommands", "");
                break;
            case 3:
                System.setSecurityManager(new SecurityMan());
                break;
        }
        for (int i = 0; i < TEST_RTE_ARG.length; ++i) {
            String outRes;
            try {
                // tear up
                switch(i) {
                    case 0:
                        // [cmd /C dir > dirOut.txt]
                        deleteOut(".\\dirOut.txt");
                        break;
                    case 1:
                        // [cmd /C dir > ".\Program Files\dirOut.txt"]
                        deleteOut(".\\Program Files\\dirOut.txt");
                        break;
                }
                Process exec = Runtime.getRuntime().exec(TEST_RTE_ARG[i]);
                exec.waitFor();
                //exteded check
                switch(i) {
                    case 0:
                        // [cmd /C dir > dirOut.txt]
                        checkOut(".\\dirOut.txt");
                        break;
                    case 1:
                        // [cmd /C dir > ".\Program Files\dirOut.txt"]
                        checkOut(".\\Program Files\\dirOut.txt");
                        break;
                }
                outRes = "Success";
            } catch (IOException ioe) {
                outRes = "IOException: " + ioe.getMessage();
            } catch (IllegalArgumentException iae) {
                outRes = "IllegalArgumentException: " + iae.getMessage();
            } catch (AccessControlException se) {
                outRes = "AccessControlException: " + se.getMessage();
            }
            if (!outRes.startsWith(TEST_RTE_GI[i][k])) {
                throw new Error("Unexpected output! Step" + k + ":" + i + "\nArgument: " + TEST_RTE_ARG[i] + "\nExpected: " + TEST_RTE_GI[i][k] + "\n  Output: " + outRes);
            } else {
                System.out.println("RTE OK:" + TEST_RTE_ARG[i]);
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 18 with AccessControlException

use of java.security.AccessControlException in project jdk8u_jdk by JetBrains.

the class bug6484091 method main.

public static void main(String[] args) {
    File dir = FileSystemView.getFileSystemView().getDefaultDirectory();
    printDirContent(dir);
    System.setSecurityManager(new SecurityManager());
    try {
        printDirContent(dir);
        throw new RuntimeException("Dir content was derived bypass SecurityManager");
    } catch (AccessControlException e) {
    // It's a successful situation
    }
}
Also used : AccessControlException(java.security.AccessControlException) File(java.io.File)

Example 19 with AccessControlException

use of java.security.AccessControlException in project lwjgl by LWJGL.

the class AppletLoader method run.

/**
	 * 9 steps
	 *
	 * 1) check jre version meets minimum requirements
	 * 2) check applet cache and decide which jars to download
	 * 3) download the jars
	 * 4) extract native files
	 * 5) validate jars for any corruption
	 * 6) save applet cache information
	 * 7) add jars to class path
	 * 8) set any lwjgl properties
	 * 9) switch to loaded applet
	 */
public void run() {
    percentage = 5;
    try {
        debug_sleep(2000);
        // check JRE version meets minimum requirements
        if (!isMinJREVersionAvailable()) {
            minimumJreNotFound = true;
            fatalErrorOccured("Java " + getStringParameter("al_min_jre", "1.5") + " or greater is required.", null);
            return;
        }
        // parse the urls for the jars into the url list
        loadJarURLs();
        // get path where applet files will be stored
        String path = getCacheDirectory();
        File dir = new File(path);
        // create directory
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File versionFile = new File(dir, "version");
        // if specified applet version already available don't download anything
        boolean versionAvailable = false;
        // version string of applet
        String version = getParameter("al_version");
        // if applet version specifed, compare with version in the cache
        if (version != null) {
            versionAvailable = compareVersion(versionFile, version.toLowerCase());
        }
        // if jars not available or need updating download them
        if (!versionAvailable) {
            // get jars file sizes and check cache
            // 5-15%
            getJarInfo(dir);
            // downloads jars from the server
            // 15-55%
            downloadJars(path);
            // Extract Pack and LZMA files
            // 55-65%
            extractJars(path);
            // Extracts Native Files
            // 65-80%
            extractNatives(path);
            // Validate Jars		// 80-90%
            validateJars(path);
            // save version information once jars downloaded successfully
            if (version != null) {
                percentage = 90;
                writeObjectFile(versionFile, version.toLowerCase());
            }
            // save file names with last modified info once downloaded successfully
            writeObjectFile(new File(dir, "timestamps"), filesLastModified);
        }
        // add the downloaded jars and natives to classpath
        updateClassPath(path);
        // set lwjgl properties
        setLWJGLProperties();
        // if headless mode then sleep, until told to continue
        if (headless) {
            while (headlessWaiting) {
                Thread.sleep(100);
            }
        }
        // make applet switch on the EDT as an AWT/Swing permission dialog could be called
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                try {
                    switchApplet();
                } catch (Exception e) {
                    fatalErrorOccured("This occurred while '" + getDescriptionForState() + "'", e);
                }
                setState(STATE_DONE);
                repaint();
            }
        });
    } catch (Exception e) {
        certificateRefused = e instanceof AccessControlException;
        fatalErrorOccured("This occurred while '" + getDescriptionForState() + "'", e);
    } finally {
        loaderThread = null;
    }
}
Also used : AccessControlException(java.security.AccessControlException) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException)

Example 20 with AccessControlException

use of java.security.AccessControlException in project ORCID-Source by ORCID.

the class DefaultPermissionChecker method checkScopes.

private void checkScopes(OAuth2Authentication oAuth2Authentication, ScopePathType requiredScope) {
    OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
    Set<String> requestedScopes = authorizationRequest.getScope();
    if (requiredScope.isUserGrantWriteScope()) {
        OrcidOAuth2Authentication orcidOauth2Authentication = (OrcidOAuth2Authentication) oAuth2Authentication;
        String activeToken = orcidOauth2Authentication.getActiveToken();
        if (activeToken != null) {
            OrcidOauth2TokenDetail tokenDetail = orcidOauthTokenDetailService.findNonDisabledByTokenValue(activeToken);
            if (removeUserGrantWriteScopePastValitity(tokenDetail)) {
                throw new AccessControlException("Write scopes for this token have expired ");
            }
        }
    }
    if (!hasRequiredScope(requestedScopes, requiredScope)) {
        throw new AccessControlException("Insufficient or wrong scope " + requestedScopes);
    }
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) AccessControlException(java.security.AccessControlException) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)

Aggregations

AccessControlException (java.security.AccessControlException)62 IOException (java.io.IOException)23 Test (org.junit.Test)12 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)8 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)7 File (java.io.File)6 InputStream (java.io.InputStream)6 Permission (java.security.Permission)6 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 HashSet (java.util.HashSet)4 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)4 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 UnsafeCharArrayWriter (jetbrick.template.utils.UnsafeCharArrayWriter)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2