Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/auth/login/Configuration/GetInstanceSecurity.java
38860 views
/*1* Copyright (c) 2005, 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 626831526* @summary Configuration should be provider-based27* @build GetInstanceConfigSpi GetInstanceProvider28* @run main/othervm/policy=GetInstanceSecurity.policy GetInstanceSecurity29*/3031import java.io.File;32import java.net.URI;33import java.security.*;34import javax.security.auth.login.*;3536import sun.net.www.ParseUtil;3738public class GetInstanceSecurity {3940private static final String JAVA_CONFIG = "JavaLoginConfig";4142public static void main(String[] args) throws Exception {43try {44Configuration c = Configuration.getInstance(JAVA_CONFIG, null);45throw new RuntimeException("did not catch security exception");46} catch (SecurityException se) {47// good48}4950try {51Configuration c = Configuration.getInstance52(JAVA_CONFIG, null, "SUN");53throw new RuntimeException("did not catch security exception");54} catch (SecurityException se) {55// good56}5758try {59Configuration c = Configuration.getInstance60(JAVA_CONFIG, null, Security.getProvider("SUN"));61throw new RuntimeException("did not catch security exception");62} catch (SecurityException se) {63// good64}6566// set a new policy that grants the perms, and then re-check perms6768File file = new File(System.getProperty("test.src", "."),69"GetInstanceSecurity.grantedPolicy");70URI uri = file.toURI();71URIParameter param = new URIParameter(uri);72Policy p = Policy.getInstance("JavaPolicy", param, "SUN");73Policy.setPolicy(p);7475// retry operations7677file = new File(System.getProperty("test.src", "."),78"GetInstance.config");79URIParameter uriParam = new URIParameter(file.toURI());8081try {82Configuration c = Configuration.getInstance(JAVA_CONFIG, uriParam);83} catch (SecurityException se) {84throw new RuntimeException("unexpected SecurityException");85}8687try {88Configuration c = Configuration.getInstance89(JAVA_CONFIG, uriParam, "SUN");90// good91} catch (SecurityException se) {92throw new RuntimeException("unexpected SecurityException");93}9495try {96Configuration c = Configuration.getInstance97(JAVA_CONFIG, uriParam, Security.getProvider("SUN"));98// good99} catch (SecurityException se) {100throw new RuntimeException("unexpected SecurityException");101}102103System.out.println("test passed");104}105}106107108