Merge "Define user scope when parsing server config"
This commit is contained in:
@@ -16,6 +16,8 @@ package com.google.gerrit.server.config;
|
|||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
|
import com.google.gerrit.server.util.ServerRequestContext;
|
||||||
|
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
@@ -25,8 +27,10 @@ import java.util.Collections;
|
|||||||
public class GitReceivePackGroupsProvider extends GroupSetProvider {
|
public class GitReceivePackGroupsProvider extends GroupSetProvider {
|
||||||
@Inject
|
@Inject
|
||||||
public GitReceivePackGroupsProvider(GroupBackend gb,
|
public GitReceivePackGroupsProvider(GroupBackend gb,
|
||||||
@GerritServerConfig Config config) {
|
@GerritServerConfig Config config,
|
||||||
super(gb, config, "receive", null, "allowGroup");
|
ThreadLocalRequestContext threadContext,
|
||||||
|
ServerRequestContext serverCtx) {
|
||||||
|
super(gb, config, threadContext, serverCtx, "receive", null, "allowGroup");
|
||||||
|
|
||||||
// If no group was set, default to "registered users"
|
// If no group was set, default to "registered users"
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ package com.google.gerrit.server.config;
|
|||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
|
import com.google.gerrit.server.util.ServerRequestContext;
|
||||||
|
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
@@ -26,8 +28,10 @@ import java.util.HashSet;
|
|||||||
public class GitUploadPackGroupsProvider extends GroupSetProvider {
|
public class GitUploadPackGroupsProvider extends GroupSetProvider {
|
||||||
@Inject
|
@Inject
|
||||||
public GitUploadPackGroupsProvider(GroupBackend gb,
|
public GitUploadPackGroupsProvider(GroupBackend gb,
|
||||||
@GerritServerConfig Config config) {
|
@GerritServerConfig Config config,
|
||||||
super(gb, config, "upload", null, "allowGroup");
|
ThreadLocalRequestContext threadContext,
|
||||||
|
ServerRequestContext serverCtx) {
|
||||||
|
super(gb, config, threadContext, serverCtx, "upload", null, "allowGroup");
|
||||||
|
|
||||||
// If no group was set, default to "registered users" and "anonymous"
|
// If no group was set, default to "registered users" and "anonymous"
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ import com.google.gerrit.common.data.GroupReference;
|
|||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
import com.google.gerrit.server.account.GroupBackends;
|
import com.google.gerrit.server.account.GroupBackends;
|
||||||
|
import com.google.gerrit.server.util.RequestContext;
|
||||||
|
import com.google.gerrit.server.util.ServerRequestContext;
|
||||||
|
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
@@ -37,19 +40,26 @@ public abstract class GroupSetProvider implements
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected GroupSetProvider(GroupBackend groupBackend,
|
protected GroupSetProvider(GroupBackend groupBackend,
|
||||||
@GerritServerConfig Config config, String section,
|
@GerritServerConfig Config config,
|
||||||
|
ThreadLocalRequestContext threadContext,
|
||||||
|
ServerRequestContext serverCtx, String section,
|
||||||
String subsection, String name) {
|
String subsection, String name) {
|
||||||
String[] groupNames = config.getStringList(section, subsection, name);
|
RequestContext ctx = threadContext.setContext(serverCtx);
|
||||||
ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
|
try {
|
||||||
for (String n : groupNames) {
|
String[] groupNames = config.getStringList(section, subsection, name);
|
||||||
GroupReference g = GroupBackends.findBestSuggestion(groupBackend, n);
|
ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
|
||||||
if (g == null) {
|
for (String n : groupNames) {
|
||||||
log.warn("Group \"{0}\" not in database, skipping.", n);
|
GroupReference g = GroupBackends.findBestSuggestion(groupBackend, n);
|
||||||
} else {
|
if (g == null) {
|
||||||
builder.add(g.getUUID());
|
log.warn("Group \"{}\" not in database, skipping.", n);
|
||||||
|
} else {
|
||||||
|
builder.add(g.getUUID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
groupIds = builder.build();
|
||||||
|
} finally {
|
||||||
|
threadContext.setContext(ctx);
|
||||||
}
|
}
|
||||||
groupIds = builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
package com.google.gerrit.server.config;
|
package com.google.gerrit.server.config;
|
||||||
|
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
|
import com.google.gerrit.server.util.ServerRequestContext;
|
||||||
|
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
@@ -33,7 +35,9 @@ import org.eclipse.jgit.lib.Config;
|
|||||||
public class ProjectOwnerGroupsProvider extends GroupSetProvider {
|
public class ProjectOwnerGroupsProvider extends GroupSetProvider {
|
||||||
@Inject
|
@Inject
|
||||||
public ProjectOwnerGroupsProvider(GroupBackend gb,
|
public ProjectOwnerGroupsProvider(GroupBackend gb,
|
||||||
@GerritServerConfig final Config config) {
|
@GerritServerConfig final Config config,
|
||||||
super(gb, config, "repository", "*", "ownerGroup");
|
ThreadLocalRequestContext context,
|
||||||
|
ServerRequestContext serverCtx) {
|
||||||
|
super(gb, config, context, serverCtx, "repository", "*", "ownerGroup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright (C) 2013 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.server.util;
|
||||||
|
|
||||||
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.InternalUser;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
import com.google.inject.ProvisionException;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/** RequestContext with an InternalUser making the internals visible. */
|
||||||
|
public class ServerRequestContext implements RequestContext {
|
||||||
|
private final InternalUser user;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ServerRequestContext(InternalUser.Factory userFactory) {
|
||||||
|
this.user = userFactory.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CurrentUser getCurrentUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Provider<ReviewDb> getReviewDbProvider() {
|
||||||
|
return new Provider<ReviewDb>() {
|
||||||
|
@Override
|
||||||
|
public ReviewDb get() {
|
||||||
|
throw new ProvisionException(
|
||||||
|
"Automatic ReviewDb only available in request scope");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user