Skip to content

Commit

Permalink
fixed stream not closed properly in github auth filter
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed May 4, 2020
1 parent c3e37c7 commit 18cba8f
Showing 1 changed file with 13 additions and 10 deletions.
Expand Up @@ -29,6 +29,7 @@
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -226,19 +227,21 @@ private String fetchUserEmail(Integer githubId, String accessToken) {
try (CloseableHttpResponse resp = httpclient.execute(emailsGet)) {
HttpEntity respEntity = resp.getEntity();
if (respEntity != null) {
MappingIterator<Map<String, Object>> emails = jreader.readValues(respEntity.getContent());
EntityUtils.consumeQuietly(respEntity);
if (emails != null) {
String email = null;
while (emails.hasNext()) {
Map<String, Object> next = emails.next();
email = (String) next.get("email");
if (next.containsKey("primary") && (Boolean) next.get("primary")) {
break;
try (InputStream is = respEntity.getContent()) {
MappingIterator<Map<String, Object>> emails = jreader.readValues(is);
if (emails != null) {
String email = null;
while (emails.hasNext()) {
Map<String, Object> next = emails.next();
email = (String) next.get("email");
if (next.containsKey("primary") && (Boolean) next.get("primary")) {
break;
}
}
return email;
}
return email;
}
EntityUtils.consumeQuietly(respEntity);
}
} catch (IOException e) {
logger.warn("Failed to fetch user email from GitHub, using default: " + defaultEmail);
Expand Down

0 comments on commit 18cba8f

Please sign in to comment.