Skip to content

Commit

Permalink
warn on missing auth header, tolerate whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed May 10, 2022
1 parent 9b88456 commit d2a04ed
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ public TokenAuthentication (AnalysisDB database) {

@Override
public UserPermissions authenticate(Request request) {
String authHeader = request.headers("authorization").strip();
String authHeader = request.headers("authorization");
if (authHeader == null) {
throw new AnalysisServerException(UNAUTHORIZED, "Authorization header mising.", 401);
}
if ("sesame".equalsIgnoreCase(authHeader)) {
return new UserPermissions("local", true, "local");
}
String[] authHeaderParts = authHeader.split(" ");
String[] authHeaderParts = authHeader.split(" +");
if (authHeaderParts.length != 2 || !authHeaderParts[0].contains("@")) {
throw new AnalysisServerException(UNAUTHORIZED, "Authorization header should be '[email] [token]", 401);
throw new AnalysisServerException(UNAUTHORIZED, "Authorization header should be '[email] [token]'.", 401);
}
String email = authHeaderParts[0];
String token = authHeaderParts[1];
Expand Down

0 comments on commit d2a04ed

Please sign in to comment.