]> source.dussan.org Git - gitblit.git/commitdiff
Track the authentication type in the session
authorJames Moger <james.moger@gitblit.com>
Thu, 29 Nov 2012 23:21:30 +0000 (18:21 -0500)
committerJames Moger <james.moger@gitblit.com>
Thu, 29 Nov 2012 23:21:30 +0000 (18:21 -0500)
src/com/gitblit/Constants.java
src/com/gitblit/GitBlit.java
src/com/gitblit/wicket/GitBlitWebSession.java

index cd6b07096a34cb5f5d21f96b87469b04020d9397..4669c4c9111296f551a0f69ea8454ab59bebb9ff 100644 (file)
@@ -397,7 +397,15 @@ public class Constants {
                        return ordinal() > s.ordinal();\r
                }\r
        }\r
-       \r
+\r
+       public static enum AuthenticationType {\r
+               CREDENTIALS, COOKIE, CERTIFICATE;\r
+               \r
+               public boolean isStandard() {\r
+                       return ordinal() <= COOKIE.ordinal();\r
+               }\r
+       }\r
+\r
        @Documented\r
        @Retention(RetentionPolicy.RUNTIME)\r
        public @interface Unused {\r
index c8deee1286a2622ec5f41028cbbc64665075fbb3..6a3f98b6b831b0b83819cc87dbac68a311187630 100644 (file)
@@ -75,6 +75,7 @@ import org.slf4j.LoggerFactory;
 \r
 import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.Constants.AuthenticationType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
 import com.gitblit.Constants.FederationRequest;\r
 import com.gitblit.Constants.FederationStrategy;\r
@@ -107,6 +108,7 @@ import com.gitblit.utils.MetricUtils;
 import com.gitblit.utils.ObjectCache;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.utils.TimeUtils;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
 /**\r
@@ -569,6 +571,8 @@ public class GitBlit implements ServletContextListener {
                UserModel model = HttpUtils.getUserModelFromCertificate(httpRequest, checkValidity, oids);\r
                if (model != null) {\r
                        // grab real user model and preserve certificate serial number\r
+                       GitBlitWebSession session = GitBlitWebSession.get();\r
+                       session.authenticationType = AuthenticationType.CERTIFICATE;\r
                        UserModel user = getUserModel(model.username);\r
                        logger.info(MessageFormat.format("{0} authenticated by client certificate from {1}",\r
                                        user.username, httpRequest.getRemoteAddr()));\r
@@ -580,7 +584,11 @@ public class GitBlit implements ServletContextListener {
                if (allowCookieAuthentication() && cookies != null && cookies.length > 0) {\r
                        // Grab cookie from Browser Session\r
                        UserModel user = authenticate(cookies);\r
-                       return user;\r
+                       if (user != null) {\r
+                               GitBlitWebSession session = GitBlitWebSession.get();\r
+                               session.authenticationType = AuthenticationType.COOKIE;\r
+                               return user;\r
+                       }\r
                }\r
                return null;\r
        }\r
index 015d97ad9ac6258d0fc2e480c60530577c3ef792..5195a1fd921d1db2d8a9a13da20c1a2e0537c68a 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.wicket.protocol.http.WebRequestCycle;
 import org.apache.wicket.protocol.http.WebSession;\r
 import org.apache.wicket.protocol.http.request.WebClientInfo;\r
 \r
+import com.gitblit.Constants.AuthenticationType;\r
 import com.gitblit.models.UserModel;\r
 \r
 public final class GitBlitWebSession extends WebSession {\r
@@ -45,9 +46,12 @@ public final class GitBlitWebSession extends WebSession {
        \r
        private AtomicBoolean isForking;\r
        \r
+       public AuthenticationType authenticationType;\r
+       \r
        public GitBlitWebSession(Request request) {\r
                super(request);\r
                isForking = new AtomicBoolean();\r
+               authenticationType = AuthenticationType.CREDENTIALS;\r
        }\r
 \r
        public void invalidate() {\r