Skip to content

Commit

Permalink
added more debug info to all auth filters, explaining why an auth req…
Browse files Browse the repository at this point in the history
…uest had failed
  • Loading branch information
albogdano committed Jan 9, 2021
1 parent 6d045fc commit 55e8ddd
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
if (token != null && token.containsKey("access_token")) {
userAuth = getOrCreateUser(app, (String) token.get("access_token"));
} else {
logger.info("Authentication request failed with status '" +
resp1.getStatusLine().getReasonPhrase() + "' - " + token);
}
EntityUtils.consumeQuietly(resp1.getEntity());
} else {
logger.info("Authentication request failed with status '"
+ (resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null")
+ "' and empty response body.");
}
}
}
Expand Down Expand Up @@ -181,6 +188,8 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
}
return SecurityUtils.checkIfActive(userAuth, user, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
String accessToken = parseAccessToken(token);
if (accessToken != null) {
userAuth = getOrCreateUser(app, accessToken);
} else {
logger.info("Authentication request failed with status '"
+ resp1.getStatusLine().getReasonPhrase() + "' - " + token);
}
} catch (Exception e) {
logger.warn("Facebook auth request failed: GET " + url, e);
Expand Down Expand Up @@ -170,7 +173,11 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
} else {
logger.info("Authentication request failed because response was missing or contained invalid JSON.");
}
} catch (Exception e) {
logger.warn("Facebook auth request failed: GET " + PROFILE_URL + accessToken, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
userAuth = getOrCreateUser(app, token.get("access_token") +
Config.SEPARATOR + token.get("refresh_token"));
} else {
LOG.error("OAuth 2.0 token request failed with response " + token);
LOG.info("OAuth 2.0 token request failed with response " + token);
}
}
}
Expand Down Expand Up @@ -359,6 +359,10 @@ private Map<String, Object> tokenRequest(App app, String authCodeOrRefreshToken,
if (resp1 != null && resp1.getEntity() != null) {
tokens = jreader.readValue(resp1.getEntity().getContent());
EntityUtils.consumeQuietly(resp1.getEntity());
} else {
LOG.info("Authentication request failed with status '"
+ (resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null")
+ "' and empty response body.");
}
}
return tokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
if (token != null && token.containsKey("access_token")) {
userAuth = getOrCreateUser(app, (String) token.get("access_token"));
} else {
logger.info("Authentication request failed with status '" +
resp1.getStatusLine().getReasonPhrase() + "' - " + token);
}
EntityUtils.consumeQuietly(resp1.getEntity());
} else {
logger.info("Authentication request failed with status '" +
(resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null") +
"' and empty response body.");
}
}
}
Expand Down Expand Up @@ -184,6 +191,8 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
}
return SecurityUtils.checkIfActive(userAuth, user, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
if (token != null && token.containsKey("access_token")) {
userAuth = getOrCreateUser(app, (String) token.get("access_token"));
} else {
logger.info("Authentication request failed with status '" +
resp1.getStatusLine().getReasonPhrase() + "' - " + token);
}
EntityUtils.consumeQuietly(resp1.getEntity());
} else {
logger.info("Authentication request failed with status '" +
(resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null") +
"' and empty response body.");
}
}
}
Expand Down Expand Up @@ -177,6 +184,8 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
}
return SecurityUtils.checkIfActive(userAuth, user, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
if (token != null && token.containsKey("access_token")) {
userAuth = getOrCreateUser(app, (String) token.get("access_token"));
} else {
logger.info("Authentication request failed with status '" +
resp1.getStatusLine().getReasonPhrase() + "' - " + token);
}
EntityUtils.consumeQuietly(resp1.getEntity());
} else {
logger.info("Authentication request failed with status '" +
(resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null") +
"' and empty response body.");
}
}
}
Expand Down Expand Up @@ -202,6 +209,8 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
}
return SecurityUtils.checkIfActive(userAuth, user, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) {
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because the provided JWT token is invalid. appid: '" +
(app != null ? app.getAppIdentifier() : "null") + "'");
}
} catch (ParseException e) {
logger.warn("Invalid token: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public SlackAuthFilter(final String defaultFilterProcessesUrl) {
* @throws IOException ex
*/
@Override
@SuppressWarnings("unchecked")
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws IOException {
final String requestURI = request.getRequestURI();
Expand All @@ -114,13 +115,20 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
tokenPost.setEntity(new StringEntity(entity, "UTF-8"));
try (CloseableHttpResponse resp1 = httpclient.execute(tokenPost)) {
if (resp1 != null && resp1.getEntity() != null) {
Map<String, Object> data = jreader.readValue(resp1.getEntity().getContent());
if (data != null && data.containsKey("authed_user")) {
Map<String, Object> authedUser = (Map<String, Object>) data.
Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
if (token != null && token.containsKey("authed_user")) {
Map<String, Object> authedUser = (Map<String, Object>) token.
getOrDefault("authed_user", Collections.emptyMap());
userAuth = getOrCreateUser(app, (String) authedUser.get("access_token"));
} else {
logger.info("Authentication request failed with status '" +
resp1.getStatusLine().getReasonPhrase() + "' - " + token);
}
EntityUtils.consumeQuietly(resp1.getEntity());
} else {
logger.info("Authentication request failed with status '" +
(resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null") +
"' and empty response body.");
}
}
}
Expand Down Expand Up @@ -195,6 +203,8 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
}
return SecurityUtils.checkIfActive(userAuth, user, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ private boolean stepOne(HttpServletResponse response, String redirectURI, String
if (pair.startsWith("oauth_token")) {
response.sendRedirect(FLOW_URL2 + pair);
return true;
} else {
logger.info("Authentication request failed, token not found in response - " + decoded);
}
}
} else {
logger.info("Authentication request failed with status '"
+ (resp1 != null ? resp1.getStatusLine().getReasonPhrase() : "null")
+ "' and empty response body.");
}
}
return false;
Expand Down Expand Up @@ -238,6 +244,8 @@ public UserAuthentication getOrCreateUser(App app, String accessToken) throws IO
}
}
userAuth = new UserAuthentication(new AuthenticatedUserDetails(user));
} else {
logger.info("Authentication request failed because user profile doesn't contain the expected attributes");
}
}
return SecurityUtils.checkIfActive(userAuth, user, false);
Expand Down

0 comments on commit 55e8ddd

Please sign in to comment.