]> source.dussan.org Git - gitblit.git/commitdiff
Try regex permission matching if exact permission is not found (issue 36)
authorJames Moger <james.moger@gitblit.com>
Wed, 10 Oct 2012 20:47:11 +0000 (16:47 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 10 Oct 2012 20:47:11 +0000 (16:47 -0400)
docs/01_setup.mkd
docs/04_releases.mkd
src/com/gitblit/models/TeamModel.java
src/com/gitblit/models/UserModel.java
tests/com/gitblit/tests/PermissionsTest.java

index 1cebb3b78105744feae30350a6255932f8492311..3123aa1ff17561a9486a3db5bbfe7ba9bb5cd4a7 100644 (file)
@@ -234,7 +234,7 @@ All repository settings are stored within the repository `.git/config` file unde
            federationSets = \r
 \r
 #### Repository Names\r
-Repository names must be unique and are CASE-SENSITIVE ON CASE-SENSITIVE FILESYSTEMS.  The name must be composed of letters, digits, or `/ _ - .`<br/>\r
+Repository names must be unique and are CASE-SENSITIVE ON CASE-SENSITIVE FILESYSTEMS.  The name must be composed of letters, digits, or `/ _ - . ~`<br/>\r
 Whitespace is illegal.\r
 \r
 Repositories can be grouped within subfolders.  e.g. *libraries/mycoollib.git* and *libraries/myotherlib.git*\r
@@ -258,6 +258,16 @@ Since v1.2.0, Gitblit supports more discrete permissions.  While Gitblit does no
 - **RWD** (clone and push with ref creation, deletion)\r
 - **RW+** (clone and push with ref creation, deletion, rewind)\r
 \r
+These permission codes are combined with the repository path to create a user permission:\r
+\r
+    RW:mygroup/myrepo.git\r
+\r
+#### Discrete Permissions with Regex Matching (Gitblit v1.2.0+)\r
+\r
+Gitblit also supports regex matching for repository permissions.  The following permission grants push privileges to all repositories in the *mygroup* folder.\r
+\r
+    RW:mygroup/[A-Za-z0-9-~_\\./]+\r
+\r
 #### No-So-Discrete Permissions (Gitblit <= v1.1.0)\r
 \r
 Prior to v1.2.0, Gitblit had two main access permission groupings:  \r
@@ -282,6 +292,7 @@ The `users.conf` file uses a Git-style configuration format:
        [user "hannibal"]\r
                password = bossman\r
                repository = RWD:topsecret.git\r
+               repository = RW+:ateam/[A-Za-z0-9-~_\\./]+\r
 \r
        [user "faceman"]\r
                password = vanity\r
index 9795601cdfe9be13ab6b45cece292158634f0f55..416aebedc3f59dd6ae736ad7dd3ddbe16c7ab88f 100644 (file)
@@ -28,6 +28,8 @@ If you are updating from an earlier release AND you have indexed branches with t
     - RWD (clone and push with ref creation, deletion)\r
     - RW+ (clone and push with ref creation, deletion, rewind)  \r
 While not as sophisticated as Gitolite, this does give finer access controls.  These permissions fit in cleanly with the existing users.conf and users.properties files.  In Gitblit <= 1.1.0, all your existing user accounts have RW+ access.   If you are upgrading to 1.2.0, the RW+ access is *preserved* and you will have to lower/adjust accordingly.\r
+- Implemented regex repository permission matching (issue 36)  \r
+This allows you to specify a permission like `RW:mygroup/[A-Za-z0-9-~_\\./]+` to grant push privileges to all repositories within the *mygroup* project/folder.\r
 - Added DELETE, CREATE, and NON-FAST-FORWARD ref change logging\r
 - Added support for personal repositories.  \r
 Personal repositories can be created by accounts with the *create* permission and are stored in *git.repositoriesFolder/~username*.  Each user with personal repositories will have a user page, something like the GitHub profile page.  Personal repositories have all the same features as common repositories, except personal repositories can be renamed by their owner.\r
index d185b9d6cbf452fa56b3d9d40bd057beae160eb5..0b9c5069a3c94e4f081f882aac4691273a0650ca 100644 (file)
@@ -132,10 +132,21 @@ public class TeamModel implements Serializable, Comparable<TeamModel> {
        public AccessPermission getRepositoryPermission(RepositoryModel repository) {\r
                AccessPermission permission = AccessPermission.NONE;\r
                if (permissions.containsKey(repository.name.toLowerCase())) {\r
+                       // exact repository permission specified\r
                        AccessPermission p = permissions.get(repository.name.toLowerCase());\r
                        if (p != null) {\r
                                permission = p;\r
                        }\r
+               } else {\r
+                       // search for regex permission match\r
+                       for (String key : permissions.keySet()) {\r
+                               if (repository.name.matches(key)) {\r
+                                       AccessPermission p = permissions.get(key);\r
+                                       if (p != null) {\r
+                                               permission = p;\r
+                                       }\r
+                               }\r
+                       }\r
                }\r
                return permission;\r
        }\r
index ee73025792e5858a99b8e80f8042dade94cfe306..a4a402454e32188c4fe2ac91b1ceb9db6079620e 100644 (file)
@@ -175,10 +175,21 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
                // and the permissions of teams of which the user belongs\r
                AccessPermission permission = AccessPermission.NONE;\r
                if (permissions.containsKey(repository.name.toLowerCase())) {\r
+                       // exact repository permission specified\r
                        AccessPermission p = permissions.get(repository.name.toLowerCase());\r
                        if (p != null) {\r
                                permission = p;\r
                        }\r
+               } else {\r
+                       // search for regex permission match\r
+                       for (String key : permissions.keySet()) {\r
+                               if (repository.name.matches(key)) {\r
+                                       AccessPermission p = permissions.get(key);\r
+                                       if (p != null) {\r
+                                               permission = p;\r
+                                       }\r
+                               }\r
+                       }\r
                }\r
                \r
                for (TeamModel team : teams) {\r
index cb9925e81a8140469e198c20c4da53bbb4dff946..83ab11e14db3eca23f2cf91845c382979cc15d06 100644 (file)
@@ -2388,4 +2388,28 @@ public class PermissionsTest extends Assert {
                assertFalse("user CAN delete!", user.canDelete(repository));
                assertFalse("user CAN edit!", user.canEdit(repository));
        }
+       
+       @Test
+       public void testWildcardMatching() throws Exception {
+               RepositoryModel repository = new RepositoryModel("ubercool/_my-r/e~po.git", null, null, new Date());
+               repository.authorizationControl = AuthorizationControl.NAMED;
+               repository.accessRestriction = AccessRestrictionType.VIEW;
+
+               UserModel user = new UserModel("test");
+               user.setRepositoryPermission("ubercool/[A-Za-z0-9-~_\\./]+", AccessPermission.CLONE);
+
+               assertTrue("user CAN NOT view!", user.canView(repository));
+               assertTrue("user CAN NOT clone!", user.canClone(repository));
+               assertFalse("user CAN push!", user.canPush(repository));
+               
+               assertFalse("user CAN create ref!", user.canCreateRef(repository));
+               assertFalse("user CAN delete ref!", user.canDeleteRef(repository));
+               assertFalse("user CAN rewind ref!", user.canRewindRef(repository));
+
+               assertFalse("user CAN fork!", user.canFork(repository));
+               
+               assertFalse("user CAN delete!", user.canDelete(repository));
+               assertFalse("user CAN edit!", user.canEdit(repository));
+
+       }
 }