Search in sources :

Example 31 with AccessSection

use of com.google.gerrit.common.data.AccessSection in project gerrit by GerritCodeReview.

the class ProjectControlTest method setUpPermissions.

private void setUpPermissions() throws Exception {
    // Remove read permissions for all users besides admin, because by default
    // Anonymous user group has ALLOW READ permission in refs/*.
    // This method is idempotent, so is safe to call on every test setup.
    ProjectConfig pc = projectCache.checkedGet(allProjects).getConfig();
    for (AccessSection sec : pc.getAccessSections()) {
        sec.removePermission(Permission.READ);
    }
    allow(pc, Permission.READ, admins, "refs/*");
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) AccessSection(com.google.gerrit.common.data.AccessSection)

Example 32 with AccessSection

use of com.google.gerrit.common.data.AccessSection in project gerrit by GerritCodeReview.

the class ProjectConfig method loadAccessSections.

private void loadAccessSections(Config rc, Map<String, GroupReference> groupsByName) {
    accessSections = new HashMap<>();
    sectionsWithUnknownPermissions = new HashSet<>();
    for (String refName : rc.getSubsections(ACCESS)) {
        if (RefConfigSection.isValid(refName) && isValidRegex(refName)) {
            AccessSection as = getAccessSection(refName, true);
            for (String varName : rc.getStringList(ACCESS, refName, KEY_GROUP_PERMISSIONS)) {
                for (String n : varName.split("[, \t]{1,}")) {
                    n = convertLegacyPermission(n);
                    if (isPermission(n)) {
                        as.getPermission(n, true).setExclusiveGroup(true);
                    }
                }
            }
            for (String varName : rc.getNames(ACCESS, refName)) {
                String convertedName = convertLegacyPermission(varName);
                if (isPermission(convertedName)) {
                    Permission perm = as.getPermission(convertedName, true);
                    loadPermissionRules(rc, ACCESS, refName, varName, groupsByName, perm, Permission.hasRange(convertedName));
                } else {
                    sectionsWithUnknownPermissions.add(as.getName());
                }
            }
        }
    }
    AccessSection capability = null;
    for (String varName : rc.getNames(CAPABILITY)) {
        if (capability == null) {
            capability = new AccessSection(AccessSection.GLOBAL_CAPABILITIES);
            accessSections.put(AccessSection.GLOBAL_CAPABILITIES, capability);
        }
        Permission perm = capability.getPermission(varName, true);
        loadPermissionRules(rc, CAPABILITY, null, varName, groupsByName, perm, GlobalCapability.hasRange(varName));
    }
}
Also used : Permission(com.google.gerrit.common.data.Permission) Permission.isPermission(com.google.gerrit.common.data.Permission.isPermission) AccessSection(com.google.gerrit.common.data.AccessSection)

Example 33 with AccessSection

use of com.google.gerrit.common.data.AccessSection in project gerrit by GerritCodeReview.

the class ProjectConfig method remove.

public void remove(AccessSection section) {
    if (section != null) {
        String name = section.getName();
        if (sectionsWithUnknownPermissions.contains(name)) {
            AccessSection a = accessSections.get(name);
            a.setPermissions(new ArrayList<Permission>());
        } else {
            accessSections.remove(name);
        }
    }
}
Also used : Permission(com.google.gerrit.common.data.Permission) Permission.isPermission(com.google.gerrit.common.data.Permission.isPermission) AccessSection(com.google.gerrit.common.data.AccessSection)

Aggregations

AccessSection (com.google.gerrit.common.data.AccessSection)33 Permission (com.google.gerrit.common.data.Permission)20 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)16 PermissionRule (com.google.gerrit.common.data.PermissionRule)14 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)14 GroupReference (com.google.gerrit.common.data.GroupReference)6 Project (com.google.gerrit.reviewdb.client.Project)6 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)6 LabelType (com.google.gerrit.common.data.LabelType)4 ProjectPermission (com.google.gerrit.server.permissions.ProjectPermission)4 HashSet (java.util.HashSet)4 GroupDescription (com.google.gerrit.common.data.GroupDescription)3 Permission.isPermission (com.google.gerrit.common.data.Permission.isPermission)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 OrmException (com.google.gwtorm.server.OrmException)3 IOException (java.io.IOException)3 Repository (org.eclipse.jgit.lib.Repository)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3