Skip to content

Commit

Permalink
Fix checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Thushani-Jayasekera committed Oct 28, 2024
1 parent 250a598 commit 1df948e
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ private static String getAPIKeyFromRequest(RequestContext requestContext) {
}
}

// If an API Key is not found, check for the API Key in the WebSocket protocol header
// If an API Key is not found, check for the API Key in the WebSocket protocol
// header
if (requestContext.getMatchedAPI().getApiType().equalsIgnoreCase(APIConstants.ApiType.WEB_SOCKET) &&
requestContext.getHeaders().containsKey(HttpConstants.WEBSOCKET_PROTOCOL_HEADER)) {
String apiKey = extractAPIKeyInWSProtocolHeader(requestContext);
if (apiKey != null && !apiKey.isEmpty()) {
String protocols = getProtocolsToSetInRequestHeaders(requestContext);
if (protocols != null) {
requestContext.addOrModifyHeaders(HttpConstants.WEBSOCKET_PROTOCOL_HEADER, protocols);
}
return apiKey.trim();
String apiKey = extractAPIKeyInWSProtocolHeader(requestContext);
if (apiKey != null && !apiKey.isEmpty()) {
String protocols = getProtocolsToSetInRequestHeaders(requestContext);
if (protocols != null) {
requestContext.addOrModifyHeaders(HttpConstants.WEBSOCKET_PROTOCOL_HEADER, protocols);
}
return apiKey.trim();
}
}

return "";
Expand Down Expand Up @@ -484,7 +485,8 @@ public static String extractAPIKeyInWSProtocolHeader(RequestContext requestConte
String[] secProtocolHeaderValues = protocolHeader.split(",");
if (secProtocolHeaderValues.length > 1 && secProtocolHeaderValues[0].equals(
Constants.WS_API_KEY_IDENTIFIER)) {
AuthenticatorUtils.addWSProtocolResponseHeaderIfRequired(requestContext, Constants.WS_API_KEY_IDENTIFIER);
AuthenticatorUtils.addWSProtocolResponseHeaderIfRequired(requestContext,
Constants.WS_API_KEY_IDENTIFIER);
return secProtocolHeaderValues[1].trim();
}
}
Expand All @@ -493,7 +495,7 @@ public static String extractAPIKeyInWSProtocolHeader(RequestContext requestConte

public static String getProtocolsToSetInRequestHeaders(RequestContext requestContext) {
String[] secProtocolHeaderValues = requestContext.getHeaders().get(
HttpConstants.WEBSOCKET_PROTOCOL_HEADER).split(",");
HttpConstants.WEBSOCKET_PROTOCOL_HEADER).split(",");
if (secProtocolHeaderValues.length > 2) {
return Arrays.stream(secProtocolHeaderValues, 2, secProtocolHeaderValues.length)
.collect(Collectors.joining(",")).trim();
Expand Down

0 comments on commit 1df948e

Please sign in to comment.