Merge "Trace canonicalWebUrl-related issues explicitly with OAuth"

This commit is contained in:
David Ostrovsky
2017-08-09 06:42:23 +00:00
committed by Gerrit Code Review

View File

@@ -27,11 +27,14 @@ import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton @Singleton
class GetOAuthToken implements RestReadView<AccountResource> { class GetOAuthToken implements RestReadView<AccountResource> {
private static final String BEARER_TYPE = "bearer"; private static final String BEARER_TYPE = "bearer";
private static final Logger log = LoggerFactory.getLogger(GetOAuthToken.class);
private final Provider<CurrentUser> self; private final Provider<CurrentUser> self;
private final OAuthTokenCache tokenCache; private final OAuthTokenCache tokenCache;
@@ -69,9 +72,15 @@ class GetOAuthToken implements RestReadView<AccountResource> {
} }
private static String getHostName(String canonicalWebUrl) { private static String getHostName(String canonicalWebUrl) {
if (canonicalWebUrl == null) {
log.error("No canonicalWebUrl defined in gerrit.config, OAuth may not work properly");
return null;
}
try { try {
return new URI(canonicalWebUrl).getHost(); return new URI(canonicalWebUrl).getHost();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
log.error("Invalid canonicalWebUrl '" + canonicalWebUrl + "'", e);
return null; return null;
} }
} }