Search in sources :

Example 26 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)

Example 27 with AccessSection

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

the class ProjectState method getLocalAccessSections.

/** Get the sections that pertain only to this project. */
List<SectionMatcher> getLocalAccessSections() {
    List<SectionMatcher> sm = localAccessSections;
    if (sm == null) {
        Collection<AccessSection> fromConfig = config.getAccessSections();
        sm = new ArrayList<>(fromConfig.size());
        for (AccessSection section : fromConfig) {
            if (isAllProjects) {
                List<Permission> copy = Lists.newArrayListWithCapacity(section.getPermissions().size());
                for (Permission p : section.getPermissions()) {
                    if (Permission.canBeOnAllProjects(section.getName(), p.getName())) {
                        copy.add(p);
                    }
                }
                section = new AccessSection(section.getName());
                section.setPermissions(copy);
            }
            SectionMatcher matcher = SectionMatcher.wrap(getProject().getNameKey(), section);
            if (matcher != null) {
                sm.add(matcher);
            }
        }
        localAccessSections = sm;
    }
    return sm;
}
Also used : Permission(com.google.gerrit.common.data.Permission) AccessSection(com.google.gerrit.common.data.AccessSection)

Example 28 with AccessSection

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

the class SetAccess method getAccessSections.

private List<AccessSection> getAccessSections(Map<String, AccessSectionInfo> sectionInfos) throws UnprocessableEntityException {
    if (sectionInfos == null) {
        return Collections.emptyList();
    }
    List<AccessSection> sections = new ArrayList<>(sectionInfos.size());
    for (Map.Entry<String, AccessSectionInfo> entry : sectionInfos.entrySet()) {
        AccessSection accessSection = new AccessSection(entry.getKey());
        if (entry.getValue().permissions == null) {
            continue;
        }
        for (Map.Entry<String, PermissionInfo> permissionEntry : entry.getValue().permissions.entrySet()) {
            Permission p = new Permission(permissionEntry.getKey());
            if (permissionEntry.getValue().exclusive != null) {
                p.setExclusiveGroup(permissionEntry.getValue().exclusive);
            }
            if (permissionEntry.getValue().rules == null) {
                continue;
            }
            for (Map.Entry<String, PermissionRuleInfo> permissionRuleInfoEntry : permissionEntry.getValue().rules.entrySet()) {
                PermissionRuleInfo pri = permissionRuleInfoEntry.getValue();
                GroupDescription.Basic group = groupsCollection.parseId(permissionRuleInfoEntry.getKey());
                if (group == null) {
                    throw new UnprocessableEntityException(permissionRuleInfoEntry.getKey() + " is not a valid group ID");
                }
                PermissionRule r = new PermissionRule(GroupReference.forGroup(group));
                if (pri != null) {
                    if (pri.max != null) {
                        r.setMax(pri.max);
                    }
                    if (pri.min != null) {
                        r.setMin(pri.min);
                    }
                    r.setAction(GetAccess.ACTION_TYPE.inverse().get(pri.action));
                    if (pri.force != null) {
                        r.setForce(pri.force);
                    }
                }
                p.add(r);
            }
            accessSection.getPermissions().add(p);
        }
        sections.add(accessSection);
    }
    return sections;
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) PermissionRule(com.google.gerrit.common.data.PermissionRule) ArrayList(java.util.ArrayList) AccessSection(com.google.gerrit.common.data.AccessSection) GroupDescription(com.google.gerrit.common.data.GroupDescription) PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) Permission(com.google.gerrit.common.data.Permission) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) Map(java.util.Map)

Example 29 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 30 with AccessSection

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

the class Schema_125 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    try (Repository git = repoManager.openRepository(allUsersName);
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git)) {
        ProjectConfig config = ProjectConfig.read(md);
        config.getAccessSection(RefNames.REFS_USERS + "*", true).remove(new Permission(Permission.READ));
        GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
        AccessSection users = config.getAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", true);
        grant(config, users, Permission.READ, true, registered);
        grant(config, users, Permission.PUSH, true, registered);
        grant(config, users, Permission.SUBMIT, true, registered);
        for (LabelType lt : getLabelTypes(config)) {
            if ("Code-Review".equals(lt.getName()) || "Verified".equals(lt.getName())) {
                grant(config, users, lt, lt.getMin().getValue(), lt.getMax().getValue(), registered);
            }
        }
        md.getCommitBuilder().setAuthor(serverUser);
        md.getCommitBuilder().setCommitter(serverUser);
        md.setMessage(COMMIT_MSG);
        config.commit(md);
    } catch (ConfigInvalidException | IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) LabelType(com.google.gerrit.common.data.LabelType) Permission(com.google.gerrit.common.data.Permission) GroupReference(com.google.gerrit.common.data.GroupReference) IOException(java.io.IOException) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

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