]> source.dussan.org Git - gitblit.git/commitdiff
Added setting to globally disable anonymous pushes in the receive pack
authorJames Moger <james.moger@gitblit.com>
Fri, 27 Sep 2013 17:44:28 +0000 (13:44 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 28 Sep 2013 01:31:39 +0000 (21:31 -0400)
Change-Id: I3460c9c0eeb32503d58325fd09793a0cd40aa2c4

releases.moxie
src/main/distrib/data/gitblit.properties
src/main/java/com/gitblit/Constants.java
src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java

index f9e21d4bcb5c77d93d266e90028403f6414a06b6..3418a051a9299713a73259867f2c751a11212723 100644 (file)
@@ -23,9 +23,11 @@ r20: {
        - Added branch graph image servlet based on EGit's branch graph renderer (issue-194)
        - Added option to render Markdown commit messages (issue-203)
        - Added setting to control creating a repository as --shared on Unix servers (issue-263)
+       - Added setting to globally disable anonymous pushes in the receive pack
     dependencyChanges: ~
     settings:
     - { name: 'git.createRepositoriesShared', defaultValue: 'false' }
+    - { name: 'git.allowAnonymousPushes', defaultValue: 'true' }
        - { name: 'web.commitMessageRenderer', defaultValue: 'plain' }
        - { name: 'web.showBranchGraph', defaultValue: 'true' }
     contributors:
index ab7b99924e06bf44bda1af548432a15c72ee5e03..9a02e2313cea57bd46bd543a9f24480f4dc07a98 100644 (file)
@@ -145,6 +145,18 @@ git.onlyAccessBareRepositories = false
 # SINCE 1.2.0\r
 git.allowCreateOnPush = true\r
 \r
+# Global setting to control anonymous pushes.\r
+#\r
+# This setting allows/rejects anonymous pushes at the level of the receive pack.\r
+# This trumps all repository config settings.  While anonymous pushes are convenient\r
+# on your own box when you are a lone developer,  they are not recommended for\r
+# any multi-user installation where accountability is required.  Since Gitblit\r
+# tracks pushes and user accounts, allowing anonymous pushes compromises that\r
+# information.\r
+#\r
+# SINCE 1.4.0\r
+git.allowAnonymousPushes = true\r
+\r
 # The default access restriction for new repositories.\r
 # Valid values are NONE, PUSH, CLONE, VIEW\r
 #  NONE = anonymous view, clone, & push\r
index bd04128eddc623982992562ad7fd7f412387750a..3ac7082edaefe43b4fd8754636866123c15804a5 100644 (file)
@@ -19,6 +19,8 @@ import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;\r
 import java.lang.annotation.RetentionPolicy;\r
 import java.net.URL;\r
+import java.util.Arrays;\r
+import java.util.List;\r
 import java.util.jar.Attributes;\r
 import java.util.jar.Manifest;\r
 \r
@@ -148,6 +150,8 @@ public class Constants {
         */\r
        public static enum AccessRestrictionType {\r
                NONE, PUSH, CLONE, VIEW;\r
+               \r
+               private static final AccessRestrictionType [] AUTH_TYPES = { PUSH, CLONE, VIEW };\r
 \r
                public static AccessRestrictionType fromName(String name) {\r
                        for (AccessRestrictionType type : values()) {\r
@@ -157,6 +161,13 @@ public class Constants {
                        }\r
                        return NONE;\r
                }\r
+               \r
+               public static List<AccessRestrictionType> choices(boolean allowAnonymousPush) {\r
+                       if (allowAnonymousPush) {\r
+                               return Arrays.asList(values());\r
+                       }\r
+                       return Arrays.asList(AUTH_TYPES);\r
+               }\r
 \r
                public boolean exceeds(AccessRestrictionType type) {\r
                        return this.ordinal() > type.ordinal();\r
index b9eb8a6252ae47070cbc9fb3cb1f90f342363003..feb33e92638b037ea1dd858be348c0aa505ab718 100644 (file)
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.gitblit.GitBlit;
+import com.gitblit.Keys;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;
 import com.gitblit.utils.HttpUtils;
@@ -80,8 +81,7 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
                        timeout = client.getDaemon().getTimeout();
                }
 
-               // TODO make this a setting
-               boolean allowAnonymousPushes = true;
+               boolean allowAnonymousPushes = GitBlit.getBoolean(Keys.git.allowAnonymousPushes, true);
                if (!allowAnonymousPushes && UserModel.ANONYMOUS.equals(user)) {
                        // prohibit anonymous pushes
                        throw new ServiceNotEnabledException();
index a25797ff592f58623716a9fc47990b2bbc23dce0..568c3123a41c96573d69379e879e12386e407452 100644 (file)
@@ -417,8 +417,8 @@ public class EditRepositoryPage extends RootSubPage {
                form.add(new TextField<String>("description"));\r
                form.add(ownersPalette);\r
                form.add(new CheckBox("allowForks").setEnabled(GitBlit.getBoolean(Keys.web.allowForking, true)));\r
-               DropDownChoice<AccessRestrictionType> accessRestriction = new DropDownChoice<AccessRestrictionType>("accessRestriction", Arrays\r
-                               .asList(AccessRestrictionType.values()), new AccessRestrictionRenderer());\r
+               DropDownChoice<AccessRestrictionType> accessRestriction = new DropDownChoice<AccessRestrictionType>("accessRestriction",\r
+                               AccessRestrictionType.choices(GitBlit.getBoolean(Keys.git.allowAnonymousPushes, true)), new AccessRestrictionRenderer());\r
                form.add(accessRestriction);\r
                form.add(new CheckBox("isFrozen"));\r
                // TODO enable origin definition\r