Skip to content

Commit

Permalink
fix zosmf mock to support Bearer auth header
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Salac <[email protected]>
  • Loading branch information
richard-salac committed Feb 21, 2025
1 parent 5c38127 commit bd70161
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.zowe.apiml.client.model.LoginBody;
import org.zowe.apiml.client.services.JwtTokenService;

Expand Down Expand Up @@ -218,6 +219,19 @@ protected boolean isValidJwtCookie(Map<String, String> headers) {

}

protected boolean isValidAuthHeader(String authHeader) {
if (!StringUtils.hasText(authHeader)) {
return false;
}

if (authHeader.startsWith("Bearer")) {
var jwtToken = authHeader.length() > 8 ? authHeader.substring(7) : "";
return jwtTokenService.validateJwtToken(jwtToken);
}

return true;
}

private String getAuthCookie(Map<String, String> headers) {
return headers.get(COOKIE_HEADER) != null ? headers.get(COOKIE_HEADER) : headers.get(HttpHeaders.COOKIE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected ResponseEntity<?> handleFiles(Map<String, String> headers) {
String authorization = headers.get(AUTHORIZATION_HEADER);

if (authorization != null) {
if (authorization.startsWith("Bearer")) {
if (!isValidAuthHeader(authorization)) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
} else {
Expand Down

0 comments on commit bd70161

Please sign in to comment.