diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/AllowedFormats.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/AllowedFormats.java new file mode 100644 index 0000000000..3a1e0f4e06 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/AllowedFormats.java @@ -0,0 +1,63 @@ +// Copyright (C) 2016 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.change; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import com.google.gerrit.server.config.DownloadConfig; +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +@Singleton +public class AllowedFormats { + final ImmutableMap extensions; + final Set allowed; + + @Inject + AllowedFormats(DownloadConfig cfg) { + Map exts = new HashMap<>(); + for (ArchiveFormat format : cfg.getArchiveFormats()) { + for (String ext : format.getSuffixes()) { + exts.put(ext, format); + } + exts.put(format.name().toLowerCase(), format); + } + extensions = ImmutableMap.copyOf(exts); + + // Zip is not supported because it may be interpreted by a Java plugin as a + // valid JAR file, whose code would have access to cookies on the domain. + allowed = Sets.filter( + cfg.getArchiveFormats(), + new Predicate() { + @Override + public boolean apply(ArchiveFormat format) { + return (format != ArchiveFormat.ZIP); + } + }); + } + + public Set getAllowed() { + return allowed; + } + + public ImmutableMap getExtensions() { + return extensions; + } +} \ No newline at end of file diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java index a2fd004c24..e99eb872ad 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetArchive.java @@ -14,18 +14,13 @@ package com.google.gerrit.server.change; -import com.google.common.base.Predicate; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.BinaryResult; import com.google.gerrit.extensions.restapi.MethodNotAllowedException; import com.google.gerrit.extensions.restapi.RestReadView; -import com.google.gerrit.server.config.DownloadConfig; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.inject.Inject; -import com.google.inject.Singleton; import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.errors.GitAPIException; @@ -37,48 +32,8 @@ import org.kohsuke.args4j.Option; import java.io.IOException; import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; public class GetArchive implements RestReadView { - @Singleton - public static class AllowedFormats { - final ImmutableMap extensions; - final Set allowed; - - @Inject - AllowedFormats(DownloadConfig cfg) { - Map exts = new HashMap<>(); - for (ArchiveFormat format : cfg.getArchiveFormats()) { - for (String ext : format.getSuffixes()) { - exts.put(ext, format); - } - exts.put(format.name().toLowerCase(), format); - } - extensions = ImmutableMap.copyOf(exts); - - // Zip is not supported because it may be interpreted by a Java plugin as a - // valid JAR file, whose code would have access to cookies on the domain. - allowed = Sets.filter( - cfg.getArchiveFormats(), - new Predicate() { - @Override - public boolean apply(ArchiveFormat format) { - return (format != ArchiveFormat.ZIP); - } - }); - } - - public Set getAllowed() { - return allowed; - } - - public ImmutableMap getExtensions() { - return extensions; - } - } - private final GitRepositoryManager repoManager; private final AllowedFormats allowedFormats; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java index 9e2ad7711c..14c6da7f3c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GetServerInfo.java @@ -43,8 +43,8 @@ import com.google.gerrit.extensions.webui.WebUiPlugin; import com.google.gerrit.server.EnableSignedPush; import com.google.gerrit.server.account.Realm; import com.google.gerrit.server.avatar.AvatarProvider; +import com.google.gerrit.server.change.AllowedFormats; import com.google.gerrit.server.change.ArchiveFormat; -import com.google.gerrit.server.change.GetArchive; import com.google.gerrit.server.change.Submit; import com.google.gerrit.server.documentation.QueryDocumentationExecutor; import com.google.gerrit.server.notedb.NotesMigration; @@ -72,7 +72,7 @@ public class GetServerInfo implements RestReadView { private final DynamicMap downloadCommands; private final DynamicMap cloneCommands; private final DynamicSet plugins; - private final GetArchive.AllowedFormats archiveFormats; + private final AllowedFormats archiveFormats; private final AllProjectsName allProjectsName; private final AllUsersName allUsersName; private final String anonymousCowardName; @@ -92,7 +92,7 @@ public class GetServerInfo implements RestReadView { DynamicMap downloadCommands, DynamicMap cloneCommands, DynamicSet webUiPlugins, - GetArchive.AllowedFormats archiveFormats, + AllowedFormats archiveFormats, AllProjectsName allProjectsName, AllUsersName allUsersName, @AnonymousCowardName String anonymousCowardName, @@ -215,7 +215,7 @@ public class GetServerInfo implements RestReadView { DynamicMap downloadSchemes, DynamicMap downloadCommands, DynamicMap cloneCommands, - GetArchive.AllowedFormats archiveFormats) { + AllowedFormats archiveFormats) { DownloadInfo info = new DownloadInfo(); info.schemes = new HashMap<>(); for (DynamicMap.Entry e : downloadSchemes) { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/UploadArchive.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/UploadArchive.java index 0edba4f6c6..99ced68277 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/UploadArchive.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/UploadArchive.java @@ -18,8 +18,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableMap; import com.google.gerrit.reviewdb.server.ReviewDb; +import com.google.gerrit.server.change.AllowedFormats; import com.google.gerrit.server.change.ArchiveFormat; -import com.google.gerrit.server.change.GetArchive; import com.google.gerrit.sshd.AbstractGitCommand; import com.google.inject.Inject; @@ -101,7 +101,7 @@ public class UploadArchive extends AbstractGitCommand { } @Inject - private GetArchive.AllowedFormats allowedFormats; + private AllowedFormats allowedFormats; @Inject private ReviewDb db; private Options options = new Options();