Fix NPE in LoginContext when authentication method information has not yet been set...
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 3 Aug 2010 10:14:17 +0000 (10:14 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 3 Aug 2010 10:14:17 +0000 (10:14 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@2936 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

doc/RELEASE-NOTES.txt
src/main/java/edu/internet2/middleware/shibboleth/idp/authn/LoginContext.java

index cd4a8f6..04586c0 100644 (file)
@@ -1,6 +1,7 @@
 Changes in Release 2.2.0
 =============================================
 [SIDP-397] - Remove any unit test that won't be fixed in the 2.X branch, fix the rest
+[SIDP-392] - NullPointerException in LoginContext when authentication method information is null
 [SIDP-388] - Add eduPersonAssurance attribute to attribute-resolver.xml config example
 [SIDP-386] - Session indexes not cleared when session is destroyed
 [SIDP-384] - Incorrect error message set for expired request in Shibboleth SSO Profile Handler
index a1078d5..715aef3 100644 (file)
@@ -17,6 +17,7 @@
 package edu.internet2.middleware.shibboleth.idp.authn;
 
 import java.io.Serializable;
+import java.security.Principal;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -137,6 +138,10 @@ public class LoginContext implements Serializable {
      * @return The duration of authentication, or zero if none was set.
      */
     public synchronized long getAuthenticationDuration() {
+        if(authenticationMethodInformation == null){
+            return 0;
+        }
+
         return authenticationMethodInformation.getAuthenticationDuration();
     }
 
@@ -164,6 +169,10 @@ public class LoginContext implements Serializable {
      * @return The instant of authentication, or <code>null</code> if none was set.
      */
     public synchronized DateTime getAuthenticationInstant() {
+        if(authenticationMethodInformation == null){
+            return null;
+        }
+
         return authenticationMethodInformation.getAuthenticationInstant();
     }
 
@@ -173,6 +182,9 @@ public class LoginContext implements Serializable {
      * @return The method used to authenticate the user.
      */
     public synchronized String getAuthenticationMethod() {
+        if(authenticationMethodInformation == null){
+            return null;
+        }
         return authenticationMethodInformation.getAuthenticationMethod();
     }
 
@@ -200,7 +212,16 @@ public class LoginContext implements Serializable {
      * @return the ID of the user, or <code>null</code> if authentication failed.
      */
     public synchronized String getPrincipalName() {
-        return authenticationMethodInformation.getAuthenticationPrincipal().getName();
+        if(authenticationMethodInformation == null){
+            return null;
+        }
+
+        Principal principal = authenticationMethodInformation.getAuthenticationPrincipal();
+        if(principal == null){
+            return null;
+        }
+        
+        return principal.getName();
     }
 
     /**