From 629806c4c04d3bfc058056069c3123fd91782639 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 27 Sep 2013 13:44:28 -0400 Subject: Added setting to globally disable anonymous pushes in the receive pack Change-Id: I3460c9c0eeb32503d58325fd09793a0cd40aa2c4 --- src/main/java/com/gitblit/Constants.java | 11 +++++++++++ src/main/java/com/gitblit/git/GitblitReceivePackFactory.java | 4 ++-- .../java/com/gitblit/wicket/pages/EditRepositoryPage.java | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/Constants.java b/src/main/java/com/gitblit/Constants.java index bd04128e..3ac7082e 100644 --- a/src/main/java/com/gitblit/Constants.java +++ b/src/main/java/com/gitblit/Constants.java @@ -19,6 +19,8 @@ import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.net.URL; +import java.util.Arrays; +import java.util.List; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -148,6 +150,8 @@ public class Constants { */ public static enum AccessRestrictionType { NONE, PUSH, CLONE, VIEW; + + private static final AccessRestrictionType [] AUTH_TYPES = { PUSH, CLONE, VIEW }; public static AccessRestrictionType fromName(String name) { for (AccessRestrictionType type : values()) { @@ -157,6 +161,13 @@ public class Constants { } return NONE; } + + public static List choices(boolean allowAnonymousPush) { + if (allowAnonymousPush) { + return Arrays.asList(values()); + } + return Arrays.asList(AUTH_TYPES); + } public boolean exceeds(AccessRestrictionType type) { return this.ordinal() > type.ordinal(); diff --git a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java index b9eb8a62..feb33e92 100644 --- a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java +++ b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java @@ -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 implements ReceivePackFactory { 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(); diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index a25797ff..568c3123 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -417,8 +417,8 @@ public class EditRepositoryPage extends RootSubPage { form.add(new TextField("description")); form.add(ownersPalette); form.add(new CheckBox("allowForks").setEnabled(GitBlit.getBoolean(Keys.web.allowForking, true))); - DropDownChoice accessRestriction = new DropDownChoice("accessRestriction", Arrays - .asList(AccessRestrictionType.values()), new AccessRestrictionRenderer()); + DropDownChoice accessRestriction = new DropDownChoice("accessRestriction", + AccessRestrictionType.choices(GitBlit.getBoolean(Keys.git.allowAnonymousPushes, true)), new AccessRestrictionRenderer()); form.add(accessRestriction); form.add(new CheckBox("isFrozen")); // TODO enable origin definition -- cgit v1.2.3