Fix access to ScmPathInfoStore as Provider to prevent injection errors (#1889)

Fix access to ScmPathInfoStore as Provider to prevent injection errors. Errors might happen, if beans using ScmPathInfoStore (like the BranchLinkProvider) are injected in beans that are singletons or that have be created outside of request scope otherwise. We do so knowing that this might lead to runtime errors (eg. when links shall be build in a thread that has no request scope). We have decided nonetheless that injection errors on startup are worse for plugin developers, that may have no clue how to solve injection problems.
This commit is contained in:
René Pfeuffer
2021-12-09 07:05:12 +01:00
committed by GitHub
parent 49a2a90c0d
commit 65d1e4ffd2
10 changed files with 74 additions and 63 deletions

View File

@@ -46,11 +46,11 @@ public abstract class BranchDetailsMapper extends BaseMapper<BranchDetailsComman
abstract BranchDetailsDto map(@Context Repository repository, String branchName, BranchDetailsCommandResult result);
@ObjectFactory
BranchDetailsDto createDto(@Context Repository repository, String branchName) {
BranchDetailsDto createDto(@Context Repository repository, String branchName, BranchDetailsCommandResult result) {
Links.Builder linksBuilder = createLinks(repository, branchName);
Embedded.Builder embeddedBuilder = Embedded.embeddedBuilder();
applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), repository);
applyEnrichers(new EdisonHalAppender(linksBuilder, embeddedBuilder), result, branchName, repository);
return new BranchDetailsDto(linksBuilder.build(), embeddedBuilder.build());
}

View File

@@ -27,6 +27,7 @@ package sonia.scm.api.v2.resources;
import sonia.scm.security.gpg.UserPublicKeyResource;
import javax.inject.Inject;
import javax.inject.Provider;
import java.net.URI;
import java.net.URISyntaxException;
@@ -34,10 +35,10 @@ import java.net.URISyntaxException;
// string literals should not be duplicated
class ResourceLinks {
private final ScmPathInfoStore scmPathInfoStore;
private final Provider<ScmPathInfoStore> scmPathInfoStore;
@Inject
ResourceLinks(ScmPathInfoStore scmPathInfoStore) {
ResourceLinks(Provider<ScmPathInfoStore> scmPathInfoStore) {
this.scmPathInfoStore = scmPathInfoStore;
}
@@ -51,7 +52,7 @@ class ResourceLinks {
}
GroupLinks group() {
return new GroupLinks(scmPathInfoStore.get());
return new GroupLinks(scmPathInfoStore.get().get());
}
static class GroupLinks {
@@ -75,7 +76,7 @@ class ResourceLinks {
}
GroupCollectionLinks groupCollection() {
return new GroupCollectionLinks(scmPathInfoStore.get());
return new GroupCollectionLinks(scmPathInfoStore.get().get());
}
static class GroupCollectionLinks {
@@ -95,7 +96,7 @@ class ResourceLinks {
}
UserLinks user() {
return new UserLinks(scmPathInfoStore.get());
return new UserLinks(scmPathInfoStore.get().get());
}
static class UserLinks {
@@ -149,7 +150,7 @@ class ResourceLinks {
}
UserPermissionLinks userPermissions() {
return new UserPermissionLinks(scmPathInfoStore.get());
return new UserPermissionLinks(scmPathInfoStore.get().get());
}
static class UserPermissionLinks implements WithPermissionLinks {
@@ -169,7 +170,7 @@ class ResourceLinks {
}
GroupPermissionLinks groupPermissions() {
return new GroupPermissionLinks(scmPathInfoStore.get());
return new GroupPermissionLinks(scmPathInfoStore.get().get());
}
static class GroupPermissionLinks implements WithPermissionLinks {
@@ -189,7 +190,7 @@ class ResourceLinks {
}
MeLinks me() {
return new MeLinks(scmPathInfoStore.get(), this.user());
return new MeLinks(scmPathInfoStore.get().get(), this.user());
}
static class MeLinks {
@@ -225,7 +226,7 @@ class ResourceLinks {
}
public ApiKeyCollectionLinks apiKeyCollection() {
return new ApiKeyCollectionLinks(scmPathInfoStore.get());
return new ApiKeyCollectionLinks(scmPathInfoStore.get().get());
}
static class ApiKeyCollectionLinks {
@@ -245,7 +246,7 @@ class ResourceLinks {
}
public ApiKeyLinks apiKey() {
return new ApiKeyLinks(scmPathInfoStore.get());
return new ApiKeyLinks(scmPathInfoStore.get().get());
}
static class ApiKeyLinks {
@@ -265,7 +266,7 @@ class ResourceLinks {
}
UserCollectionLinks userCollection() {
return new UserCollectionLinks(scmPathInfoStore.get());
return new UserCollectionLinks(scmPathInfoStore.get().get());
}
static class UserCollectionLinks {
@@ -285,7 +286,7 @@ class ResourceLinks {
}
AutoCompleteLinks autoComplete() {
return new AutoCompleteLinks(scmPathInfoStore.get());
return new AutoCompleteLinks(scmPathInfoStore.get().get());
}
static class AutoCompleteLinks {
@@ -305,7 +306,7 @@ class ResourceLinks {
}
ConfigLinks config() {
return new ConfigLinks(scmPathInfoStore.get());
return new ConfigLinks(scmPathInfoStore.get().get());
}
static class ConfigLinks {
@@ -325,7 +326,7 @@ class ResourceLinks {
}
AdminInfoLinks adminInfo() {
return new AdminInfoLinks(scmPathInfoStore.get());
return new AdminInfoLinks(scmPathInfoStore.get().get());
}
static class AdminInfoLinks {
@@ -341,7 +342,7 @@ class ResourceLinks {
}
public RepositoryLinks repository() {
return new RepositoryLinks(scmPathInfoStore.get());
return new RepositoryLinks(scmPathInfoStore.get().get());
}
static class RepositoryLinks {
@@ -423,7 +424,7 @@ class ResourceLinks {
}
RepositoryCollectionLinks repositoryCollection() {
return new RepositoryCollectionLinks(scmPathInfoStore.get());
return new RepositoryCollectionLinks(scmPathInfoStore.get().get());
}
static class RepositoryCollectionLinks {
@@ -447,7 +448,7 @@ class ResourceLinks {
}
public NamespaceStrategiesLinks namespaceStrategies() {
return new NamespaceStrategiesLinks(scmPathInfoStore.get());
return new NamespaceStrategiesLinks(scmPathInfoStore.get().get());
}
static class NamespaceStrategiesLinks {
@@ -464,7 +465,7 @@ class ResourceLinks {
}
public RepositoryTypeLinks repositoryType() {
return new RepositoryTypeLinks(scmPathInfoStore.get());
return new RepositoryTypeLinks(scmPathInfoStore.get().get());
}
static class RepositoryTypeLinks {
@@ -480,7 +481,7 @@ class ResourceLinks {
}
public RepositoryTypeCollectionLinks repositoryTypeCollection() {
return new RepositoryTypeCollectionLinks(scmPathInfoStore.get());
return new RepositoryTypeCollectionLinks(scmPathInfoStore.get().get());
}
static class RepositoryTypeCollectionLinks {
@@ -497,7 +498,7 @@ class ResourceLinks {
public TagCollectionLinks tag() {
return new TagCollectionLinks(scmPathInfoStore.get());
return new TagCollectionLinks(scmPathInfoStore.get().get());
}
static class TagCollectionLinks {
@@ -525,7 +526,7 @@ class ResourceLinks {
}
public DiffLinks diff() {
return new DiffLinks(scmPathInfoStore.get());
return new DiffLinks(scmPathInfoStore.get().get());
}
static class DiffLinks {
@@ -549,7 +550,7 @@ class ResourceLinks {
}
public BranchLinks branch() {
return new BranchLinks(scmPathInfoStore.get());
return new BranchLinks(scmPathInfoStore.get().get());
}
static class BranchLinks {
@@ -577,7 +578,7 @@ class ResourceLinks {
}
public BranchDetailsLinks branchDetails() {
return new BranchDetailsLinks(scmPathInfoStore.get());
return new BranchDetailsLinks(scmPathInfoStore.get().get());
}
static class BranchDetailsLinks {
@@ -593,7 +594,7 @@ class ResourceLinks {
}
public BranchDetailsCollectionLinks branchDetailsCollection() {
return new BranchDetailsCollectionLinks(scmPathInfoStore.get());
return new BranchDetailsCollectionLinks(scmPathInfoStore.get().get());
}
static class BranchDetailsCollectionLinks {
@@ -609,7 +610,7 @@ class ResourceLinks {
}
public IncomingLinks incoming() {
return new IncomingLinks(scmPathInfoStore.get());
return new IncomingLinks(scmPathInfoStore.get().get());
}
static class IncomingLinks {
@@ -655,7 +656,7 @@ class ResourceLinks {
}
public BranchCollectionLinks branchCollection() {
return new BranchCollectionLinks(scmPathInfoStore.get());
return new BranchCollectionLinks(scmPathInfoStore.get().get());
}
static class BranchCollectionLinks {
@@ -671,7 +672,7 @@ class ResourceLinks {
}
public ChangesetLinks changeset() {
return new ChangesetLinks(scmPathInfoStore.get());
return new ChangesetLinks(scmPathInfoStore.get().get());
}
static class ChangesetLinks {
@@ -695,7 +696,7 @@ class ResourceLinks {
}
public ModificationsLinks modifications() {
return new ModificationsLinks(scmPathInfoStore.get());
return new ModificationsLinks(scmPathInfoStore.get().get());
}
static class ModificationsLinks {
@@ -711,7 +712,7 @@ class ResourceLinks {
}
public FileHistoryLinks fileHistory() {
return new FileHistoryLinks(scmPathInfoStore.get());
return new FileHistoryLinks(scmPathInfoStore.get().get());
}
static class FileHistoryLinks {
@@ -728,7 +729,7 @@ class ResourceLinks {
}
public SourceLinks source() {
return new SourceLinks(scmPathInfoStore.get());
return new SourceLinks(scmPathInfoStore.get().get());
}
static class SourceLinks {
@@ -760,7 +761,7 @@ class ResourceLinks {
}
public AnnotateLinks annotate() {
return new AnnotateLinks(scmPathInfoStore.get());
return new AnnotateLinks(scmPathInfoStore.get().get());
}
static class AnnotateLinks {
@@ -776,7 +777,7 @@ class ResourceLinks {
}
RepositoryVerbLinks repositoryVerbs() {
return new RepositoryVerbLinks(scmPathInfoStore.get());
return new RepositoryVerbLinks(scmPathInfoStore.get().get());
}
static class RepositoryVerbLinks {
@@ -792,7 +793,7 @@ class ResourceLinks {
}
RepositoryRoleLinks repositoryRole() {
return new RepositoryRoleLinks(scmPathInfoStore.get());
return new RepositoryRoleLinks(scmPathInfoStore.get().get());
}
static class RepositoryRoleLinks {
@@ -816,7 +817,7 @@ class ResourceLinks {
}
RepositoryRoleCollectionLinks repositoryRoleCollection() {
return new RepositoryRoleCollectionLinks(scmPathInfoStore.get());
return new RepositoryRoleCollectionLinks(scmPathInfoStore.get().get());
}
static class RepositoryRoleCollectionLinks {
@@ -836,7 +837,7 @@ class ResourceLinks {
}
public RepositoryPermissionLinks repositoryPermission() {
return new RepositoryPermissionLinks(scmPathInfoStore.get());
return new RepositoryPermissionLinks(scmPathInfoStore.get().get());
}
static class RepositoryPermissionLinks {
@@ -872,7 +873,7 @@ class ResourceLinks {
}
public UIPluginLinks uiPlugin() {
return new UIPluginLinks(scmPathInfoStore.get());
return new UIPluginLinks(scmPathInfoStore.get().get());
}
static class UIPluginLinks {
@@ -888,7 +889,7 @@ class ResourceLinks {
}
public UIPluginCollectionLinks uiPluginCollection() {
return new UIPluginCollectionLinks(scmPathInfoStore.get());
return new UIPluginCollectionLinks(scmPathInfoStore.get().get());
}
static class UIPluginCollectionLinks {
@@ -904,7 +905,7 @@ class ResourceLinks {
}
public InstalledPluginLinks installedPlugin() {
return new InstalledPluginLinks(scmPathInfoStore.get());
return new InstalledPluginLinks(scmPathInfoStore.get().get());
}
static class InstalledPluginLinks {
@@ -924,7 +925,7 @@ class ResourceLinks {
}
public InstalledPluginCollectionLinks installedPluginCollection() {
return new InstalledPluginCollectionLinks(scmPathInfoStore.get());
return new InstalledPluginCollectionLinks(scmPathInfoStore.get().get());
}
static class InstalledPluginCollectionLinks {
@@ -944,7 +945,7 @@ class ResourceLinks {
}
public AvailablePluginLinks availablePlugin() {
return new AvailablePluginLinks(scmPathInfoStore.get());
return new AvailablePluginLinks(scmPathInfoStore.get().get());
}
static class AvailablePluginLinks {
@@ -964,7 +965,7 @@ class ResourceLinks {
}
public AvailablePluginCollectionLinks availablePluginCollection() {
return new AvailablePluginCollectionLinks(scmPathInfoStore.get());
return new AvailablePluginCollectionLinks(scmPathInfoStore.get().get());
}
static class AvailablePluginCollectionLinks {
@@ -980,7 +981,7 @@ class ResourceLinks {
}
public PendingPluginCollectionLinks pendingPluginCollection() {
return new PendingPluginCollectionLinks(scmPathInfoStore.get());
return new PendingPluginCollectionLinks(scmPathInfoStore.get().get());
}
static class PendingPluginCollectionLinks {
@@ -1004,7 +1005,7 @@ class ResourceLinks {
}
public AuthenticationLinks authentication() {
return new AuthenticationLinks(scmPathInfoStore.get());
return new AuthenticationLinks(scmPathInfoStore.get().get());
}
static class AuthenticationLinks {
@@ -1028,7 +1029,7 @@ class ResourceLinks {
}
public IndexLinks index() {
return new IndexLinks(scmPathInfoStore.get());
return new IndexLinks(scmPathInfoStore.get().get());
}
static class IndexLinks {
@@ -1044,7 +1045,7 @@ class ResourceLinks {
}
public PermissionsLinks permissions() {
return new PermissionsLinks(scmPathInfoStore.get());
return new PermissionsLinks(scmPathInfoStore.get().get());
}
static class PermissionsLinks {
@@ -1060,7 +1061,7 @@ class ResourceLinks {
}
public NamespaceCollectionLinks namespaceCollection() {
return new NamespaceCollectionLinks(scmPathInfoStore.get());
return new NamespaceCollectionLinks(scmPathInfoStore.get().get());
}
static class NamespaceCollectionLinks {
@@ -1076,7 +1077,7 @@ class ResourceLinks {
}
public NamespaceLinks namespace() {
return new NamespaceLinks(scmPathInfoStore.get());
return new NamespaceLinks(scmPathInfoStore.get().get());
}
static class NamespaceLinks {
@@ -1096,7 +1097,7 @@ class ResourceLinks {
}
public NamespacePermissionLinks namespacePermission() {
return new NamespacePermissionLinks(scmPathInfoStore.get());
return new NamespacePermissionLinks(scmPathInfoStore.get().get());
}
static class NamespacePermissionLinks {
@@ -1132,7 +1133,7 @@ class ResourceLinks {
}
public MetricsLinks metrics() {
return new MetricsLinks(new LinkBuilder(scmPathInfoStore.get(), MetricsResource.class));
return new MetricsLinks(new LinkBuilder(scmPathInfoStore.get().get(), MetricsResource.class));
}
public static class MetricsLinks {
@@ -1149,7 +1150,7 @@ class ResourceLinks {
}
public SearchLinks search() {
return new SearchLinks(scmPathInfoStore.get());
return new SearchLinks(scmPathInfoStore.get().get());
}
public static class SearchLinks {
@@ -1170,7 +1171,7 @@ class ResourceLinks {
}
public InitialAdminAccountLinks initialAdminAccount() {
return new InitialAdminAccountLinks(new LinkBuilder(scmPathInfoStore.get(), InitializationResource.class, AdminAccountStartupResource.class));
return new InitialAdminAccountLinks(new LinkBuilder(scmPathInfoStore.get().get(), InitializationResource.class, AdminAccountStartupResource.class));
}
public static class InitialAdminAccountLinks {