J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 4633622 |
| 27 | * @summary bug in LoginContext when Configuration is subclassed |
| 28 | * |
| 29 | * @build ResetConfigModule ResetModule |
| 30 | * @run main ResetConfigModule |
| 31 | */ |
| 32 | |
| 33 | import javax.security.auth.*; |
| 34 | import javax.security.auth.login.*; |
| 35 | import javax.security.auth.spi.*; |
| 36 | import javax.security.auth.callback.*; |
| 37 | import java.util.*; |
| 38 | |
| 39 | public class ResetConfigModule { |
| 40 | |
| 41 | public static void main(String[] args) throws Exception { |
| 42 | |
| 43 | Configuration.setConfiguration(new MyConfig()); |
| 44 | |
| 45 | LoginContext lc = new LoginContext("test"); |
| 46 | try { |
| 47 | lc.login(); |
| 48 | throw new SecurityException("test 1 failed"); |
| 49 | } catch (LoginException le) { |
| 50 | if (le.getCause() != null && |
| 51 | le.getCause() instanceof SecurityException) { |
| 52 | System.out.println("good so far"); |
| 53 | } else { |
| 54 | throw le; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | LoginContext lc2 = new LoginContext("test2"); |
| 59 | try { |
| 60 | lc2.login(); |
| 61 | throw new SecurityException("test 2 failed"); |
| 62 | } catch (LoginException le) { |
| 63 | if (le.getCause() != null && |
| 64 | le.getCause() instanceof SecurityException) { |
| 65 | System.out.println("test succeeded"); |
| 66 | } else { |
| 67 | throw le; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | class MyConfig extends Configuration { |
| 74 | private AppConfigurationEntry[] entries = { |
| 75 | new AppConfigurationEntry("ResetModule", |
| 76 | AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, |
| 77 | new HashMap()) }; |
| 78 | public AppConfigurationEntry[] getAppConfigurationEntry(String name) { |
| 79 | return entries; |
| 80 | } |
| 81 | public void refresh() { } |
| 82 | } |