|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Red Hat, Inc. |
| 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8215916 |
| 27 | + * @summary This test case attempts to verify whether call stack trace is |
| 28 | + * printed when JAAS optional login fails when debug is true. |
| 29 | + * @run main/othervm -Djava.security.debug=logincontext UnixNTPlatform |
| 30 | + */ |
| 31 | +import javax.security.auth.login.LoginContext; |
| 32 | +import javax.security.auth.login.LoginException; |
| 33 | +import java.nio.file.Files; |
| 34 | +import java.nio.file.Path; |
| 35 | +import java.io.ByteArrayOutputStream; |
| 36 | +import java.io.PrintStream; |
| 37 | + |
| 38 | +public class UnixNTPlatform { |
| 39 | + |
| 40 | + public static void main(String[] args) throws Exception { |
| 41 | + System.out.println("Testing cross-platform"); |
| 42 | + |
| 43 | + String config = """ |
| 44 | + hello { |
| 45 | + com.sun.security.auth.module.UnixLoginModule optional debug=true; |
| 46 | + com.sun.security.auth.module.NTLoginModule optional debug=true; |
| 47 | + }; |
| 48 | + """; |
| 49 | + |
| 50 | + System.out.println("config is : \n"+config); |
| 51 | + Files.writeString(Path.of("cross-platform"), config.toString()); |
| 52 | + |
| 53 | + System.setProperty("java.security.auth.login.config", "cross-platform"); |
| 54 | + |
| 55 | + ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| 56 | + PrintStream ps = System.err; |
| 57 | + System.setErr(new PrintStream(new PrintStream(stream))); |
| 58 | + |
| 59 | + try { |
| 60 | + LoginContext lc = new LoginContext("hello"); |
| 61 | + lc.login(); |
| 62 | + System.out.println(lc.getSubject()); |
| 63 | + lc.logout(); |
| 64 | + } catch (LoginException e) { |
| 65 | + System.out.println("Retrieving exception information"); |
| 66 | + } finally { |
| 67 | + System.setErr(ps); |
| 68 | + } |
| 69 | + |
| 70 | + byte[] byes = stream.toByteArray(); |
| 71 | + String s = new String(byes); |
| 72 | + System.out.printf("-- call stack is -- %n%s%n", s); |
| 73 | + if (!s.contains("Failed in attempt to import the underlying")) { |
| 74 | + throw new RuntimeException(); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments