Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/auth/login/LoginContext/ConfigConstructorNoPerm.java
38862 views
/*1* Copyright (c) 2003, 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 470336126* @summary can not specify Configuration to LoginContext constructor27*28* @run main/othervm/policy=ConfigConstructorNoPerm.policy -Djava.security.auth.login.config=file:${test.src}/ConfigConstructor.config ConfigConstructorNoPerm29*/3031/**32* This test shares the login config with ConfigConstructor.33* This test has no configured permissions34* (ConfigConstructor tests code with perms configured).35*/3637import java.util.Map;38import javax.security.auth.*;39import javax.security.auth.login.*;40import javax.security.auth.spi.*;41import javax.security.auth.callback.*;4243public class ConfigConstructorNoPerm {4445private static Subject s = new Subject();46private static CallbackHandler ch =47new com.sun.security.auth.callback.TextCallbackHandler();48private static Configuration c = new MyConfig();4950public static void main(String[] args) throws Exception {5152// test old constructor with no permission53try {54LoginContext lc1 = new LoginContext55("module1",56s,57ch);58throw new RuntimeException("Test 1 Failed");59} catch (SecurityException se) {60// test passed61}62System.out.println("Test 1 Succeeded");6364// test new constructor (null config) with no permission65try {66LoginContext lc2 = new LoginContext67("module1",68s,69ch,70null);71throw new RuntimeException("Test 2 Failed");72} catch (SecurityException se) {73// test passed74}75System.out.println("Test 2 Succeeded");7677// test new constructor (config) - no permission needed78// (and none configured)79LoginContext lc3 = new LoginContext80("module1",81s,82ch,83c);84System.out.println("Test 3 Succeeded");8586// test old constructor with no permission for other87try {88LoginContext lc4 = new LoginContext89("goToOther",90s,91ch);92throw new RuntimeException("Test 4 Failed");93} catch (SecurityException se) {94// test passed95}96System.out.println("Test 4 Succeeded");9798// test new constructor with no permission for other99try {100LoginContext lc5 = new LoginContext101("goToOther",102s,103ch,104null);105throw new RuntimeException("Test 5 Failed");106} catch (SecurityException se) {107// test passed108}109System.out.println("Test 5 Succeeded");110}111112private static class MyConfig extends Configuration {113public MyConfig() { }114public AppConfigurationEntry[] getAppConfigurationEntry(String name) {115java.util.HashMap map = new java.util.HashMap();116AppConfigurationEntry[] entries = new AppConfigurationEntry[1];117118if (name.equals("module1")) {119AppConfigurationEntry entry = new AppConfigurationEntry120("ConfigConstructor$MyModule1",121AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,122map);123entries[0] = entry;124} else {125entries = null;126}127return entries;128}129public void refresh() { }130}131}132133134