Bug 26302 - Null Poiner Exception in LoginContext.Login() method.
Summary: Null Poiner Exception in LoginContext.Login() method.
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P3 major
Target Milestone: ---
Assignee: Raif S. Naffah
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-15 13:29 UTC by Radhika
Modified: 2006-07-19 09:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-07-17 13:28:30


Attachments
Attached Zip contains the Program source files, auth.login file and the log files of the program generated on both Java and Dotnet. (10.60 KB, application/x-zip-compressed)
2006-02-15 13:48 UTC, Radhika
Details
Set login context's local fields before initialising login modules (428 bytes, patch)
2006-07-18 21:08 UTC, Raif S. Naffah
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Radhika 2006-02-15 13:29:50 UTC
This mail is with respect to the bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25202 marked as resolved fixed. I have downloaded the latest gnu classpath source which includes 
Added files:
        gnu/javax/security/auth/login: GnuConfiguration.java 
                                       ConfigFileTokenizer.java 
                                       ConfigFileParser.java  
and Modified files:
        javax/security/auth/login: AppConfigurationEntry.java 
                                   Configuration.java  
from CVS and built the IKVM.GNU.Classpath dll out of it. When I execute the attached Java program on .NET after generating an exe using IKVMC I get a Null Pointer Exception saying.

Exception in thread "main" java.lang.NullPointerException
        at security.BaseLoginModule.login (BaseLoginModule.java:70)
        at javax.security.auth.login.LoginContext.login (LoginContext.java:141)
        at security.TestSecurity.<init> (TestSecurity.java:19)
        at security.TestSecurity.main (TestSecurity.java:29)

On Java environment the program executes fine with out any errors. Now on .NET it is able to parse the given auth.login file and finding the configured module for the application. But, the callbackhandler object in the DBLoginModuleTest(LoginModule)->initialize is coming as NULL resulting in the above said Null Pointer Exception. I am attaching the source files and the logs generated on Java and .NET environment and below are the files/commands i have used. Please let me know if i am missing anything.

---auth.login -----------

DBLogin {
        security.DBLoginModuleTest required;
};

----------------usage ----------------------------

D:\R& D>ikvmc LoginSecurity.jar
Note: found main method in class "security.TestSecurity"
Note: output file is "LoginSecurity.exe"
Note: automatically adding reference to "D:\R& D\IKVM.GNU.Classpath.DLL"


D:\R& D>LoginSecurity
DEBUG: java.security.auth.login.config = auth.login
 WARN: Failed opening as URL: auth.login. Will try as File
 INFO: Using login configuration defined by System property
DEBUG: java.security.auth.login.config = auth.login
 WARN: Failed opening as URL: auth.login. Will try as File
 INFO: Using login configuration defined by System property
DEBUG: DBLogin -> 1 entry(ies)
Exception in thread "main" java.lang.NullPointerException
        at security.BaseLoginModule.login (BaseLoginModule.java:70)
        at javax.security.auth.login.LoginContext.login (LoginContext.java:141)
        at security.TestSecurity.<init> (TestSecurity.java:19)
        at security.TestSecurity.main (TestSecurity.java:29)


Thanks in advance for your help.
Comment 1 Radhika 2006-02-15 13:48:37 UTC
Created attachment 10854 [details]
Attached Zip contains the  Program source files, auth.login file and the log files of the program generated on both Java and Dotnet.

Attachment contains the program source files, login file used for parsing and the logs generated by the program on Java and dotnet environments.
Comment 2 Raif S. Naffah 2006-07-18 10:48:21 UTC
Rahdika,

you have to work with me to solve this one!  i don't have a windoors platform, and wasn't able to run ikvm[c] with wine.  but first...

did you try asking on the IKVM list if this is a known problem?

one more point; the line:

   at security.BaseLoginModule.login (BaseLoginModule.java:70)

claims the exception is caused by a statement on line 70 in BaseLoginModule.  looking in that file, line #70 is a blank one!  is this normal or could it be that the source incl. in the attachment does not match the one you tried this with?

cheers;
rsn
Comment 3 Jeroen Frijters 2006-07-18 11:29:20 UTC
There is at least one IKVM specific bug. In ikvm/classpath/classpath.security, the following line is missing:

security.provider.5=gnu.javax.security.auth.callback.GnuCallbacks

I will modify the IKVM.GNU.Classpath.dll build script to use the GNU Classpath version of classpath.security (I don't remember why it doesn't use that at the moment).

However, after fixing this, I still get:

C:\j\LoginSecurity>\ikvm\bin\ikvm security.TestSecurity
Jul 18, 2006 1:17:55 PM security.DBLoginModuleTest initialize
INFO: Starting initialize DbLoginModuleTest
Jul 18, 2006 1:17:55 PM security.DBLoginModuleTest initialize
INFO: callbackhandler is null - initialize - DBLoginModuleTest
Jul 18, 2006 1:17:55 PM security.BaseLoginModule initialize
INFO: Starting initialize BaseLoginModule
Jul 18, 2006 1:17:55 PM security.BaseLoginModule initialize
INFO: CallbackHandler is Null - initialize() - BaseLoginModule
Jul 18, 2006 1:17:55 PM security.BaseLoginModule initialize
INFO: End of initialize BaseLoginModule
Jul 18, 2006 1:17:55 PM security.DBLoginModuleTest initialize
INFO: End of initialize DbLoginModuleTest
Jul 18, 2006 1:17:55 PM security.BaseLoginModule login
INFO: Starting login() of BaseLoginModule
Exception in thread "main" java.lang.NullPointerException
        at security.BaseLoginModule.login(BaseLoginModule.java:48)
        at javax.security.auth.login.LoginContext.login(LoginContext.java:141)
        at security.TestSecurity.<init>(TestSecurity.java:19)
        at security.TestSecurity.main(TestSecurity.java:30)

Note that callback is null and this causes the NPE. By my (limited) understanding callback is allowed to be null (as I don't see anybody setting the auth.login.defaultCallbackHandler security property), so I'm not sure whether this is a bug in IKVM/Classpath or in the Radhika's code.
Comment 4 Raif S. Naffah 2006-07-18 21:08:16 UTC
Created attachment 11911 [details]
Set login context's local fields before initialising login modules
Comment 5 Raif S. Naffah 2006-07-18 21:09:16 UTC
Jeroen,

pls. try the attached patch and let me know if this solves the problem.


TIA + cheers;
Comment 6 Jeroen Frijters 2006-07-19 06:52:54 UTC
That fixed it!

Thanks,
Jeroen
Comment 7 cvs-commit@developer.classpath.org 2006-07-19 09:13:51 UTC
Subject: Bug 26302

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Changes by:	Raif S. Naffah <raif>	06/07/19 09:11:59

Modified files:
	resource/java/security: classpath.security 
	javax/security/auth/login: LoginContext.java 
	.              : ChangeLog 

Log message:
	2006-07-19  Raif S. Naffah  <raif@swiftdsl.com.au>
	
		PR Classpath/26302
		* resource/java/security/classpath.security: Updated copyright year.
		(auth.login.defaultCallbackHandler): New property; set to our default
		callback handler. This is needed by the LoginContext when no callback
		handler was specified.
		* javax/security/auth/login/LoginContext.java: Updated copyright year.
		(LoginContext(4)): Assign passed parameters to local fields before invoking
		lookup method.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/resource/java/security/classpath.security?cvsroot=classpath&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/security/auth/login/LoginContext.java?cvsroot=classpath&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.8162&r2=1.8163



Comment 8 Raif S. Naffah 2006-07-19 09:15:38 UTC
fixed as per (last) patch.