Path: blob/master/test/jdk/javax/security/auth/login/Configuration/GetInstanceSecurity.java
51695 views
/*1* Copyright (c) 2005, 2017, 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* @modules jdk.security.auth27* @summary Configuration should be provider-based28* @build GetInstanceConfigSpi GetInstanceProvider29* @run main/othervm/policy=GetInstanceSecurity.policy GetInstanceSecurity30*/3132import java.io.File;33import java.net.URI;34import java.security.Policy;35import java.security.Security;36import java.security.URIParameter;37import javax.security.auth.login.Configuration;3839public class GetInstanceSecurity {4041private static final String JAVA_CONFIG = "JavaLoginConfig";4243public static void main(String[] args) throws Exception {44try {45Configuration c = Configuration.getInstance(JAVA_CONFIG, null);46throw new RuntimeException("did not catch security exception");47} catch (SecurityException se) {48// good49}5051try {52Configuration c = Configuration.getInstance53(JAVA_CONFIG, null, "SUN");54throw new RuntimeException("did not catch security exception");55} catch (SecurityException se) {56// good57}5859try {60Configuration c = Configuration.getInstance61(JAVA_CONFIG, null, Security.getProvider("SUN"));62throw new RuntimeException("did not catch security exception");63} catch (SecurityException se) {64// good65}6667// set a new policy that grants the perms, and then re-check perms6869File file = new File(System.getProperty("test.src", "."),70"GetInstanceSecurity.grantedPolicy");71URI uri = file.toURI();72URIParameter param = new URIParameter(uri);73Policy p = Policy.getInstance("JavaPolicy", param, "SUN");74Policy.setPolicy(p);7576// retry operations7778file = new File(System.getProperty("test.src", "."),79"GetInstance.config");80URIParameter uriParam = new URIParameter(file.toURI());8182try {83Configuration c = Configuration.getInstance(JAVA_CONFIG, uriParam);84} catch (SecurityException se) {85throw new RuntimeException("unexpected SecurityException");86}8788try {89Configuration c = Configuration.getInstance90(JAVA_CONFIG, uriParam, "SUN");91// good92} catch (SecurityException se) {93throw new RuntimeException("unexpected SecurityException");94}9596try {97Configuration c = Configuration.getInstance98(JAVA_CONFIG, uriParam, Security.getProvider("SUN"));99// good100} catch (SecurityException se) {101throw new RuntimeException("unexpected SecurityException");102}103104System.out.println("test passed");105}106}107108109