Gracefully handle unknown host exceptions during OpenID discovery We don't need these errors in our application server log. If the client has given us a hostname we can't resolve, trap the error and return an invalid discovery JSON payload to them instead. The user will see a message explaining its an unsupported/invalid URL and can try again. Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/appjar/src/main/java/com/google/gerrit/server/OpenIdLoginServlet.java b/appjar/src/main/java/com/google/gerrit/server/OpenIdLoginServlet.java index 91f1bd2..d8088d8 100644 --- a/appjar/src/main/java/com/google/gerrit/server/OpenIdLoginServlet.java +++ b/appjar/src/main/java/com/google/gerrit/server/OpenIdLoginServlet.java
@@ -50,6 +50,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; @@ -152,7 +153,16 @@ return; } - final OpenIdUser user = relyingParty.discover(req); + final OpenIdUser user; + try { + user = relyingParty.discover(req); + } catch (UnknownHostException u) { + // The remote host described in the OpenID doesn't exist, so we + // can't try to perform discovery against it. + // + callback(req, rsp, SignInResult.CANCEL); + return; + } if (user == null) { // User isn't known, no provider is known. //