Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/auth/login/LoginContext/ResetConfigModule.java
38860 views
/*1* Copyright (c) 2002, 2011, 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 463362226* @summary bug in LoginContext when Configuration is subclassed27* @build ResetConfigModule ResetModule28* @run main ResetConfigModule29*/3031import javax.security.auth.*;32import javax.security.auth.login.*;33import javax.security.auth.spi.*;34import javax.security.auth.callback.*;35import java.util.*;3637public class ResetConfigModule {3839public static void main(String[] args) throws Exception {4041Configuration previousConf = Configuration.getConfiguration();42ClassLoader previousCL = Thread.currentThread().getContextClassLoader();4344try {45Thread.currentThread().setContextClassLoader(46ResetConfigModule.class.getClassLoader());47Configuration.setConfiguration(new MyConfig());4849LoginContext lc = new LoginContext("test");50try {51lc.login();52throw new SecurityException("test 1 failed");53} catch (LoginException le) {54if (le.getCause() != null &&55le.getCause() instanceof SecurityException) {56System.out.println("good so far");57} else {58throw le;59}60}6162LoginContext lc2 = new LoginContext("test2");63try {64lc2.login();65throw new SecurityException("test 2 failed");66} catch (LoginException le) {67if (le.getCause() != null &&68le.getCause() instanceof SecurityException) {69System.out.println("test succeeded");70} else {71throw le;72}73}74} finally {75Configuration.setConfiguration(previousConf);76Thread.currentThread().setContextClassLoader(previousCL);77}78}79}8081class MyConfig extends Configuration {82private AppConfigurationEntry[] entries = {83new AppConfigurationEntry("ResetModule",84AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,85new HashMap()) };86public AppConfigurationEntry[] getAppConfigurationEntry(String name) {87return entries;88}89public void refresh() { }90}919293