]> source.dussan.org Git - gitblit.git/commitdiff
Fixed regression on certificate authentication of servlets
authorJames Moger <james.moger@gitblit.com>
Fri, 30 Nov 2012 21:15:14 +0000 (16:15 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 30 Nov 2012 21:15:14 +0000 (16:15 -0500)
src/com/gitblit/GitBlit.java

index 870e22fbc26d9c10a5081e735aaa49c788271f97..69135c495db31dec1f40c5fbe1e810f11532444a 100644 (file)
@@ -58,6 +58,7 @@ import javax.servlet.ServletContextListener;
 import javax.servlet.http.Cookie;\r
 import javax.servlet.http.HttpServletRequest;\r
 \r
+import org.apache.wicket.RequestCycle;\r
 import org.apache.wicket.protocol.http.WebResponse;\r
 import org.apache.wicket.resource.ContextRelativeResource;\r
 import org.apache.wicket.util.resource.ResourceStreamNotFoundException;\r
@@ -574,8 +575,12 @@ public class GitBlit implements ServletContextListener {
                        // grab real user model and preserve certificate serial number\r
                        UserModel user = getUserModel(model.username);\r
                        if (user != null) {\r
-                               GitBlitWebSession session = GitBlitWebSession.get();\r
-                               session.authenticationType = AuthenticationType.CERTIFICATE;\r
+                               RequestCycle requestCycle = RequestCycle.get();\r
+                               if (requestCycle != null) {\r
+                                       // flag the Wicket session, if this is a Wicket request\r
+                                       GitBlitWebSession session = GitBlitWebSession.get();\r
+                                       session.authenticationType = AuthenticationType.CERTIFICATE;\r
+                               }\r
                                X509Metadata metadata = HttpUtils.getCertificateMetadata(httpRequest);\r
                                logger.info(MessageFormat.format("{0} authenticated by client certificate {1} from {2}",\r
                                                user.username, metadata.serialNumber, httpRequest.getRemoteAddr()));\r
@@ -589,8 +594,12 @@ public class GitBlit implements ServletContextListener {
                        // Grab cookie from Browser Session\r
                        UserModel user = authenticate(cookies);\r
                        if (user != null) {\r
-                               GitBlitWebSession session = GitBlitWebSession.get();\r
-                               session.authenticationType = AuthenticationType.COOKIE;\r
+                               RequestCycle requestCycle = RequestCycle.get();\r
+                               if (requestCycle != null) {\r
+                                       // flag the Wicket session, if this is a Wicket request\r
+                                       GitBlitWebSession session = GitBlitWebSession.get();\r
+                                       session.authenticationType = AuthenticationType.COOKIE;\r
+                               }\r
                                logger.info(MessageFormat.format("{0} authenticated by cookie from {1}",\r
                                                user.username, httpRequest.getRemoteAddr()));\r
                                return user;\r