Path: blob/master/test/jdk/java/lang/System/SecurityManagerWarnings.java
41149 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 826645926* @summary check various warnings27* @library /test/lib28*/2930import jdk.test.lib.process.OutputAnalyzer;31import jdk.test.lib.process.ProcessTools;3233import java.security.Permission;3435public class SecurityManagerWarnings {36public static void main(String args[]) throws Exception {37if (args.length == 0) {38run(null)39.shouldHaveExitValue(0)40.shouldContain("SM is enabled: false")41.shouldNotContain("Security Manager is deprecated")42.shouldContain("setSecurityManager is deprecated");43run("allow")44.shouldHaveExitValue(0)45.shouldContain("SM is enabled: false")46.shouldNotContain("Security Manager is deprecated")47.shouldContain("setSecurityManager is deprecated");48run("disallow")49.shouldNotHaveExitValue(0)50.shouldContain("SM is enabled: false")51.shouldNotContain("Security Manager is deprecated")52.shouldContain("UnsupportedOperationException");53run("SecurityManagerWarnings$MySM")54.shouldHaveExitValue(0)55.shouldContain("SM is enabled: true")56.shouldContain("Security Manager is deprecated")57.shouldContain("setSecurityManager is deprecated");58run("")59.shouldNotHaveExitValue(0)60.shouldContain("SM is enabled: true")61.shouldContain("Security Manager is deprecated")62.shouldContain("AccessControlException");63run("default")64.shouldNotHaveExitValue(0)65.shouldContain("SM is enabled: true")66.shouldContain("Security Manager is deprecated")67.shouldContain("AccessControlException");68} else {69System.out.println("SM is enabled: " + (System.getSecurityManager() != null));70System.setSecurityManager(new SecurityManager());71}72}7374static OutputAnalyzer run(String prop) throws Exception {75if (prop == null) {76return ProcessTools.executeTestJvm(77"SecurityManagerWarnings", "run");78} else {79return ProcessTools.executeTestJvm(80"-Djava.security.manager=" + prop,81"SecurityManagerWarnings", "run");82}83}8485// This SecurityManager allows everything!86public static class MySM extends SecurityManager {87@Override88public void checkPermission(Permission perm) {89}90}91}929394