Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #196 from davco01a/securityExceptionHandlingEnhanc…
Browse files Browse the repository at this point in the history
…ement

Security exception handling enhancement
  • Loading branch information
s1cyan authored May 12, 2020
2 parents 408bee2 + 3410ff7 commit 7d7366a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/kabasec/GitHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ JsonObject getUserData() throws KabaneroSecurityException {
jsonResponse.add("teams", getUserTeams());
return jsonResponse.build();
} catch (KabaneroSecurityException e) {
throw new KabaneroSecurityException("Encountered an error requesting, parsing, or processing GitHub data for user [" + userId + "]: " + e.getMessage(), e);
throw new KabaneroSecurityException("Encountered an error requesting, parsing, or processing GitHub data for user" + e.getMessage(), e);
}
}

Expand Down
21 changes: 17 additions & 4 deletions src/main/java/kabasec/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,27 @@ public Properties login(Properties args) {
checkTeamsAndGithubURL(auth);
jwt = auth.getJwt(creds); // check id, password/PAT, and team membership here.
} catch (KabaneroSecurityException e) {
return returnError(e.getStatusCode(), "An error occurred during authentication for user ", e);
} catch (Exception e) {
if (e.getMessage().contains("could not parse exception response")) {
// Encountered an error requesting, parsing, or processing GitHub data for user
if (e.getMessage().contains("Encountered an error requesting, parsing, or processing GitHub data for user") || e.getMessage().contains("An error occurred during authentication for user Unexpected char")) {
msg = "login failed, you may want to check your authorization configuration. Double check the apiUrl: in your github: configuraton in the Kabanero CR Instance to make sure it's correct";
System.out.println(returnError(500, "An error occurred during authentication for user, double check the apiUrl: in your github: configuraton in the Kabanero CR Instance to make sure it's correct", e));
System.out.println("An error occurred during authentication for user, double check the apiUrl: in your github: configuraton in the Kabanero CR Instance to make sure it's correct, exception message: "+ e.getMessage());
Properties p = new Properties();
p.put("message", msg);
return p;
} else {
System.out.println(returnError(500, "An error occurred during authentication for user", e));
}
return returnError(e.getStatusCode(), "An error occurred during authentication for user ", e);
} catch (Exception e) {
if (e.getMessage().contains("could not parse exception response") || e.getMessage().contains("An error occurred during authentication for user Unexpected char") || e.getMessage().contains("Unexpected char 60 at (line no=1, column no=1, offset=0")) {
msg = "login failed, you may want to check your authorization configuration. Double check the apiUrl: in your github: configuraton in the Kabanero CR Instance to make sure it's correct";
System.out.println("An error occurred during authentication for user, double check the apiUrl: in your github: configuraton in the Kabanero CR Instance to make sure it's correct, exception message: "+e.getMessage());
Properties p = new Properties();
p.put("message", msg);
return p;
} else {
System.out.println("An error occurred during authentication for user, exception message: "+e.getMessage());
}
Properties p = new Properties();
p.put("message", msg);
return p;
Expand Down

0 comments on commit 7d7366a

Please sign in to comment.