public static enum AccessRestrictionType {\r
NONE, PUSH, CLONE, VIEW;\r
\r
- public static AccessRestrictionType fromString(String name) {\r
+ public static AccessRestrictionType fromName(String name) {\r
for (AccessRestrictionType type : values()) {\r
- if (type.toString().equalsIgnoreCase(name)) {\r
+ if (type.name().equalsIgnoreCase(name)) {\r
return type;\r
}\r
}\r
public String toString() {\r
switch (this) {\r
case NONE:\r
- return "none";\r
+ return "Anonymous View, Clone, & Push";\r
case PUSH:\r
- return "push";\r
+ return "Anonymous View & Clone, Authenticated Push";\r
case CLONE:\r
- return "clone";\r
+ return "Anonymous View, Authenticated Clone & Push";\r
case VIEW:\r
- return "view";\r
+ return "Authenticated View, Clone, & Push";\r
}\r
return "none";\r
}\r
public RepositoryModel getRepositoryModel(UserModel user, String repositoryName) {\r
RepositoryModel model = getRepositoryModel(repositoryName);\r
if (model.accessRestriction.atLeast(AccessRestrictionType.VIEW)) {\r
- if (user != null && user.canView(model)) {\r
+ if (user != null && user.canAccessRepository(model.name)) {\r
return model;\r
}\r
return null;\r
model.owner = config.getString("gitblit", null, "owner");\r
model.useTickets = config.getBoolean("gitblit", "useTickets", false);\r
model.useDocs = config.getBoolean("gitblit", "useDocs", false);\r
- model.accessRestriction = AccessRestrictionType.fromString(config.getString("gitblit", null, "accessRestriction"));\r
+ model.accessRestriction = AccessRestrictionType.fromName(config.getString("gitblit", null, "accessRestriction"));\r
model.showRemoteBranches = config.getBoolean("gitblit", "showRemoteBranches", false);\r
}\r
r.close();\r
config.setString("gitblit", null, "owner", repository.owner);\r
config.setBoolean("gitblit", null, "useTickets", repository.useTickets);\r
config.setBoolean("gitblit", null, "useDocs", repository.useDocs);\r
- config.setString("gitblit", null, "accessRestriction", repository.accessRestriction.toString());\r
+ config.setString("gitblit", null, "accessRestriction", repository.accessRestriction.name());\r
config.setBoolean("gitblit", null, "showRemoteBranches", repository.showRemoteBranches);\r
try {\r
config.save();\r
boolean authorizedUser = req.isUserInRole(repository);\r
if (function.startsWith("git-receive-pack") || (query.indexOf("service=git-receive-pack") > -1)) {\r
// Push request\r
- boolean pushRestricted = model.accessRestriction.atLeast(AccessRestrictionType.PUSH);\r
- if (!pushRestricted || (pushRestricted && authorizedUser)) {\r
- // push-unrestricted or push-authorized\r
+ if (authorizedUser) {\r
+ // clone-restricted or push-authorized\r
super.service(req, rsp);\r
return;\r
} else {\r
// Clone request\r
boolean cloneRestricted = model.accessRestriction.atLeast(AccessRestrictionType.CLONE);\r
if (!cloneRestricted || (cloneRestricted && authorizedUser)) {\r
- // clone-unrestricted or clone-authorized\r
+ // push-restricted or clone-authorized\r
super.service(req, rsp);\r
return;\r
} else {\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
-import com.gitblit.Constants.AccessRestrictionType;\r
-\r
public class UserModel implements Serializable {\r
\r
private static final long serialVersionUID = 1L;\r
public boolean canAdmin() {\r
return canAdmin;\r
}\r
- \r
- public boolean canClone(RepositoryModel repository) {\r
- return canAccess(repository, AccessRestrictionType.CLONE);\r
- }\r
\r
- public boolean canPush(RepositoryModel repository) {\r
- return canAccess(repository, AccessRestrictionType.PUSH);\r
- }\r
- \r
- public boolean canView(RepositoryModel repository) {\r
- return canAccess(repository, AccessRestrictionType.VIEW);\r
- }\r
- \r
- private boolean canAccess(RepositoryModel repository, AccessRestrictionType minimum) {\r
- if (repository.accessRestriction.atLeast(minimum)) {\r
- // repository is restricted, must check roles\r
- return canAdmin || repositories.contains(repository.name);\r
- } else {\r
- // repository is not restricted\r
- return true;\r
- }\r
+ public boolean canAccessRepository(String repositoryName) {\r
+ return canAdmin || repositories.contains(repositoryName);\r
}\r
\r
public void setCookie(String cookie) {\r