Skip to content

8215916: The failure reason of an optional JAAS LoginModule is not logged #9159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
13a51a6
8215916: Print out more information as a part of failure reason of an…
jhuttana Jun 14, 2022
b91e755
Add test case to verify the patch
jhuttana Jul 15, 2022
3bce8d9
Address review comment to change the test case
jhuttana Aug 2, 2022
e3ab434
Address review comments
jhuttana Aug 8, 2022
a7997f0
Added test case using {Unix,NT}LoginModule
jhuttana Aug 8, 2022
704cfef
Address review comment for test case
jhuttana Aug 16, 2022
a4bf014
Address review comment for cross-platform in the test case
jhuttana Aug 16, 2022
0bcf670
Address review comment to revert back the previous changes in the tes…
jhuttana Aug 16, 2022
94c5c8d
Address review comment to add call stacktrace changes to OPTIONAL log…
jhuttana Aug 17, 2022
c0f5aa3
Address whitespace error by jcheck
jhuttana Aug 17, 2022
0079740
Address whitespace error by jcheck
jhuttana Aug 17, 2022
36f5b44
Address review comment
jhuttana Aug 18, 2022
8610f43
Address errors by bot to the previous commit
jhuttana Aug 18, 2022
93a22f7
Merge branch 'master' into JDK-8215916
jhuttana Aug 18, 2022
70563d7
Address review comments
jhuttana Aug 18, 2022
eceebab
Address review comments
jhuttana Aug 19, 2022
a0fc0e4
Address review comments
jhuttana Aug 22, 2022
477aef0
Address review comments
jhuttana Aug 22, 2022
5c38a3b
Address review comments
jhuttana Aug 22, 2022
2964c8f
Address jcheck space errors
jhuttana Aug 22, 2022
1d04a32
Address jcheck space errors and review comment
jhuttana Aug 22, 2022
09fcde1
Address review comment to update copyright
jhuttana Aug 22, 2022
6d83391
Address review comment for import statements
jhuttana Aug 23, 2022
df47b57
Address review comment
jhuttana Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,10 @@ private void invoke(String methodName) throws LoginException {
firstRequiredError = le;

} else {

if (debug != null)
if (debug != null) {
debug.println(name + " " + methodName + " OPTIONAL failure");
le.printStackTrace();
}

// mark down that an OPTIONAL module failed
if (firstError == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2022, Red Hat, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8215916
* @summary This test case attempts to verify whether call stack trace is
* printed when JAAS optional login fails when debug is true.
* @run main/othervm -Djava.security.debug=logincontext UnixNTPlatform
*/
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class UnixNTPlatform {

public static void main(String[] args) throws Exception {
System.out.println("Testing cross-platform");

String config = """
hello {
com.sun.security.auth.module.UnixLoginModule optional debug=true;
com.sun.security.auth.module.NTLoginModule optional debug=true;
};
""";

System.out.println("config is : \n"+config);
Files.writeString(Path.of("cross-platform"), config.toString());

System.setProperty("java.security.auth.login.config", "cross-platform");

ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintStream ps = System.err;
System.setErr(new PrintStream(new PrintStream(stream)));

try {
LoginContext lc = new LoginContext("hello");
lc.login();
System.out.println(lc.getSubject());
lc.logout();
} catch (LoginException e) {
System.out.println("Retrieving exception information");
} finally {
System.setErr(ps);
}

byte[] byes = stream.toByteArray();
String s = new String(byes);
System.out.printf("-- call stack is -- %n%s%n", s);
if (!s.contains("Failed in attempt to import the underlying")) {
throw new RuntimeException();
}
}
}