Search in sources :

Example 1 with InternalUser

use of com.google.gerrit.server.InternalUser in project gerrit by GerritCodeReview.

the class AbstractChangeNotesTest method setUpTestEnvironment.

// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Before
public void setUpTestEnvironment() throws Exception {
    setTimeForTesting();
    serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", Date.from(TimeUtil.now()), TZ);
    project = Project.nameKey("test-project");
    repoManager = new InMemoryRepositoryManager();
    repo = repoManager.createRepository(project);
    tr = new TestRepository<>(repo);
    rw = tr.getRevWalk();
    accountCache = new FakeAccountCache();
    Account.Builder co = Account.builder(Account.id(1), TimeUtil.now());
    co.setFullName("Change Owner");
    co.setPreferredEmail("change@owner.com");
    accountCache.put(co.build());
    Account.Builder ou = Account.builder(Account.id(2), TimeUtil.now());
    ou.setFullName("Other Account");
    ou.setPreferredEmail("other@account.com");
    accountCache.put(ou.build());
    assertableFanOutExecutor = new AssertableExecutorService();
    injector = Guice.createInjector(new FactoryModule() {

        @Override
        public void configure() {
            install(new GitModule());
            install(new DefaultUrlFormatterModule());
            install(NoteDbModule.forTest());
            bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
            bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
            bind(GitRepositoryManager.class).toInstance(repoManager);
            bind(ProjectCache.class).to(NullProjectCache.class);
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
            bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
            bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
            bind(Boolean.class).annotatedWith(EnablePeerIPInReflogRecord.class).toInstance(Boolean.FALSE);
            bind(Realm.class).to(FakeRealm.class);
            bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
            bind(AccountCache.class).toInstance(accountCache);
            bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
            bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
            bind(MetricMaker.class).to(DisabledMetricMaker.class);
            bind(ExecutorService.class).annotatedWith(FanOutExecutor.class).toInstance(assertableFanOutExecutor);
            bind(ServiceUserClassifier.class).to(ServiceUserClassifier.NoOp.class);
            bind(InternalChangeQuery.class).toProvider(() -> {
                throw new UnsupportedOperationException();
            });
            bind(PatchSetApprovalUuidGenerator.class).to(TestPatchSetApprovalUuidGenerator.class);
        }
    });
    injector.injectMembers(this);
    repoManager.createRepository(allUsers);
    changeOwner = userFactory.create(co.id());
    otherUser = userFactory.create(ou.id());
    otherUserId = otherUser.getAccountId();
    internalUser = new InternalUser();
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) Account(com.google.gerrit.entities.Account) InMemoryRepositoryManager(com.google.gerrit.testing.InMemoryRepositoryManager) AssertableExecutorService(com.google.gerrit.testing.AssertableExecutorService) InternalUser(com.google.gerrit.server.InternalUser) GerritServerId(com.google.gerrit.server.config.GerritServerId) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) FakeAccountCache(com.google.gerrit.testing.FakeAccountCache) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) EnablePeerIPInReflogRecord(com.google.gerrit.server.config.EnablePeerIPInReflogRecord) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitModule(com.google.gerrit.server.git.GitModule) FanOutExecutor(com.google.gerrit.server.FanOutExecutor) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ServiceUserClassifier(com.google.gerrit.server.account.ServiceUserClassifier) DefaultUrlFormatterModule(com.google.gerrit.server.config.DefaultUrlFormatter.DefaultUrlFormatterModule) PatchSetApprovalUuidGenerator(com.google.gerrit.server.approval.PatchSetApprovalUuidGenerator) TestPatchSetApprovalUuidGenerator(com.google.gerrit.server.approval.testing.TestPatchSetApprovalUuidGenerator) FakeAccountCache(com.google.gerrit.testing.FakeAccountCache) AccountCache(com.google.gerrit.server.account.AccountCache) ProjectCache(com.google.gerrit.server.project.ProjectCache) NullProjectCache(com.google.gerrit.server.project.NullProjectCache) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) AllUsersName(com.google.gerrit.server.config.AllUsersName) Before(org.junit.Before)

Example 2 with InternalUser

use of com.google.gerrit.server.InternalUser in project gerrit by GerritCodeReview.

the class AbstractChangeNotesTest method setUp.

@Before
public void setUp() throws Exception {
    setTimeForTesting();
    serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
    project = new Project.NameKey("test-project");
    repoManager = new InMemoryRepositoryManager();
    repo = repoManager.createRepository(project);
    tr = new TestRepository<>(repo);
    rw = tr.getRevWalk();
    accountCache = new FakeAccountCache();
    Account co = new Account(new Account.Id(1), TimeUtil.nowTs());
    co.setFullName("Change Owner");
    co.setPreferredEmail("change@owner.com");
    accountCache.put(co);
    Account ou = new Account(new Account.Id(2), TimeUtil.nowTs());
    ou.setFullName("Other Account");
    ou.setPreferredEmail("other@account.com");
    accountCache.put(ou);
    injector = Guice.createInjector(new FactoryModule() {

        @Override
        public void configure() {
            install(new GitModule());
            install(NoteDbModule.forTest(testConfig));
            bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
            bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
            bind(NotesMigration.class).toInstance(MIGRATION);
            bind(GitRepositoryManager.class).toInstance(repoManager);
            bind(ProjectCache.class).toProvider(Providers.<ProjectCache>of(null));
            bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
            bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
            bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
            bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
            bind(Realm.class).to(FakeRealm.class);
            bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
            bind(AccountCache.class).toInstance(accountCache);
            bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
            bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
            bind(MetricMaker.class).to(DisabledMetricMaker.class);
            bind(ReviewDb.class).toProvider(Providers.<ReviewDb>of(null));
        }
    });
    injector.injectMembers(this);
    repoManager.createRepository(allUsers);
    changeOwner = userFactory.create(co.getId());
    otherUser = userFactory.create(ou.getId());
    otherUserId = otherUser.getAccountId();
    internalUser = new InternalUser(null);
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) CapabilityControl(com.google.gerrit.server.account.CapabilityControl) InternalUser(com.google.gerrit.server.InternalUser) GerritServerId(com.google.gerrit.server.config.GerritServerId) DisableReverseDnsLookup(com.google.gerrit.server.config.DisableReverseDnsLookup) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) FakeAccountCache(com.google.gerrit.testutil.FakeAccountCache) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitModule(com.google.gerrit.server.git.GitModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) TestNotesMigration(com.google.gerrit.testutil.TestNotesMigration) FakeAccountCache(com.google.gerrit.testutil.FakeAccountCache) AccountCache(com.google.gerrit.server.account.AccountCache) Project(com.google.gerrit.reviewdb.client.Project) ProjectCache(com.google.gerrit.server.project.ProjectCache) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) AllUsersName(com.google.gerrit.server.config.AllUsersName) Before(org.junit.Before)

Example 3 with InternalUser

use of com.google.gerrit.server.InternalUser in project gerrit by GerritCodeReview.

the class ChangeIsVisibleToPredicate method match.

@Override
public boolean match(ChangeData cd) {
    if (cd.fastIsVisibleTo(user)) {
        return true;
    }
    Change change = cd.change();
    if (change == null) {
        return false;
    }
    Optional<ProjectState> projectState = projectCache.get(cd.project());
    if (!projectState.isPresent()) {
        logger.atFine().log("Filter out change %s of non-existing project %s", cd, cd.project());
        return false;
    }
    if (!projectState.get().statePermitsRead()) {
        logger.atFine().log("Filter out change %s of non-reabable project %s", cd, cd.project());
        return false;
    }
    PermissionBackend.WithUser withUser = user.isIdentifiedUser() ? permissionBackend.absentUser(user.getAccountId()) : permissionBackend.user(Optional.of(user).filter(u -> u instanceof GroupBackedUser || u instanceof InternalUser).orElseGet(anonymousUserProvider::get));
    try {
        if (!withUser.change(cd).test(ChangePermission.READ)) {
            logger.atFine().log("Filter out non-visisble change: %s", cd);
            return false;
        }
    } catch (PermissionBackendException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RepositoryNotFoundException) {
            logger.atWarning().withCause(e).log("Filter out change %s because the corresponding repository %s was not found", cd, cd.project());
            return false;
        }
        throw new StorageException("unable to check permissions on change " + cd.getId(), e);
    }
    cd.cacheVisibleTo(user);
    return true;
}
Also used : IsVisibleToPredicate(com.google.gerrit.index.query.IsVisibleToPredicate) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) CurrentUser(com.google.gerrit.server.CurrentUser) IndexUtils(com.google.gerrit.server.index.IndexUtils) ProjectCache(com.google.gerrit.server.project.ProjectCache) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) StorageException(com.google.gerrit.exceptions.StorageException) InternalUser(com.google.gerrit.server.InternalUser) Inject(com.google.inject.Inject) ChangePermission(com.google.gerrit.server.permissions.ChangePermission) ProjectState(com.google.gerrit.server.project.ProjectState) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) Assisted(com.google.inject.assistedinject.Assisted) Provider(com.google.inject.Provider) Optional(java.util.Optional) Change(com.google.gerrit.entities.Change) AnonymousUser(com.google.gerrit.server.AnonymousUser) FluentLogger(com.google.common.flogger.FluentLogger) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Change(com.google.gerrit.entities.Change) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) InternalUser(com.google.gerrit.server.InternalUser) ProjectState(com.google.gerrit.server.project.ProjectState) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

InternalUser (com.google.gerrit.server.InternalUser)3 ProjectCache (com.google.gerrit.server.project.ProjectCache)3 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)2 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)2 MetricMaker (com.google.gerrit.metrics.MetricMaker)2 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)2 AccountCache (com.google.gerrit.server.account.AccountCache)2 FakeRealm (com.google.gerrit.server.account.FakeRealm)2 Realm (com.google.gerrit.server.account.Realm)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)2 CanonicalWebUrl (com.google.gerrit.server.config.CanonicalWebUrl)2 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)2 GerritServerId (com.google.gerrit.server.config.GerritServerId)2 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)2 GitModule (com.google.gerrit.server.git.GitModule)2 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)2 SystemGroupBackend (com.google.gerrit.server.group.SystemGroupBackend)2 FluentLogger (com.google.common.flogger.FluentLogger)1 Account (com.google.gerrit.entities.Account)1