Allow running without gerrit.canonicalWebUrl

Gerrit's CanonicalWebUrl class is already responsible of getting
the full URL from either gerrit.config or the incoming HTTP request.

However, over time, other parts of Gerrit injected directly the
configured string through @CanonicalWebUrl annotation and did not
manage correctly the situation where the configuration is absent.

The only situation where gerrit.canonicalWebUrl is mandatory is
OAuth authentication, because the OAuth provider needs to have
a fixed callback URL with a single hostname.

Change-Id: Idee1d36eb08c53a0d06604b9a737695322e124d1
This commit is contained in:
Luca Milanesio
2017-07-14 17:21:04 +01:00
parent 4aef830108
commit 53eab1080b
3 changed files with 15 additions and 4 deletions

View File

@@ -38,7 +38,7 @@ class GetOAuthToken implements RestReadView<AccountResource> {
private final Provider<CurrentUser> self;
private final OAuthTokenCache tokenCache;
private final String hostName;
private final Provider<String> canonicalWebUrlProvider;
@Inject
GetOAuthToken(
@@ -47,7 +47,7 @@ class GetOAuthToken implements RestReadView<AccountResource> {
@CanonicalWebUrl Provider<String> urlProvider) {
this.self = self;
this.tokenCache = tokenCache;
this.hostName = getHostName(urlProvider.get());
this.canonicalWebUrlProvider = urlProvider;
}
@Override
@@ -63,7 +63,7 @@ class GetOAuthToken implements RestReadView<AccountResource> {
}
OAuthTokenInfo accessTokenInfo = new OAuthTokenInfo();
accessTokenInfo.username = a.getUserName();
accessTokenInfo.resourceHost = hostName;
accessTokenInfo.resourceHost = getHostName(canonicalWebUrlProvider.get());
accessTokenInfo.accessToken = accessToken.getToken();
accessTokenInfo.providerId = accessToken.getProviderId();
accessTokenInfo.expiresAt = Long.toString(accessToken.getExpiresAt());