From d0c4d2e5792c9148f57b18a021695f8b73fdec28 Mon Sep 17 00:00:00 2001 From: Thushani Jayasekera Date: Fri, 25 Oct 2024 14:50:31 +0530 Subject: [PATCH] Change keyword used in auth --- .../wso2/choreo/connect/enforcer/constants/Constants.java | 4 ++-- .../enforcer/security/jwt/UnsecuredAPIAuthenticator.java | 2 +- .../security/jwt/InternalAPIKeyAuthenticatorTest.java | 8 ++++---- .../enforcer/security/jwt/JWTAuthenticatorTest.java | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/Constants.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/Constants.java index b72df0a1b7..726b4d790d 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/Constants.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/Constants.java @@ -73,8 +73,8 @@ public class Constants { public static final String DEFAULT_CON_FACTORY_JNDI_NAME = "TopicConnectionFactory"; // keyword to identify API-Key sent in sec-websocket-protocol header - public static final String WS_API_KEY_IDENTIFIER = "choreo-internal-API-Key"; - public static final String WS_OAUTH2_KEY_IDENTIFIED = "choreo-oauth2-key"; + public static final String WS_API_KEY_IDENTIFIER = "choreo-api-key"; + public static final String WS_OAUTH2_KEY_IDENTIFIED = "choreo-oauth2-token"; // Modes for the temporary console test headers. public static final String TEMP_CONSOLE_TEST_HEADERS_MONITOR_MODE = "monitor"; diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/UnsecuredAPIAuthenticator.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/UnsecuredAPIAuthenticator.java index 652db3a1d5..4ea9b6a9ef 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/UnsecuredAPIAuthenticator.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/UnsecuredAPIAuthenticator.java @@ -81,7 +81,7 @@ public AuthenticationContext authenticate(RequestContext requestContext) throws // Since the Choreo console/ Devportal sends the token in the // sec-websocket-protocol header, regardless of security enabled or not, we need - // to add the "choreo-internal-API-Key" to the sec-websocket-protocol response + // to add the "choreo-api-key" to the sec-websocket-protocol response // header. if (requestContext.getMatchedAPI().getApiType().equalsIgnoreCase(APIConstants.ApiType.WEB_SOCKET)) { String secProtocolHeader = requestContext.getHeaders().get(HttpConstants.WEBSOCKET_PROTOCOL_HEADER); diff --git a/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticatorTest.java b/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticatorTest.java index 78af33aade..a16accfd1f 100644 --- a/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticatorTest.java +++ b/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticatorTest.java @@ -66,8 +66,8 @@ public void extractInternalKeyInWSProtocolHeaderTest() { String secWebsocketProtocolHeader = "sec-websocket-protocol"; // Test case to test for an Upgrade request sent from the choreo console - // The token will be set to the sec-websocket-protocol header with choreo-internal-API-Key keyword - // the value after choreo-internal-API-Key will be the token + // The token will be set to the sec-websocket-protocol header with choreo-api-key keyword + // the value after choreo-api-key will be the token RequestContext.Builder builder = new RequestContext.Builder("/pets"); builder.matchedAPI(new APIConfig.Builder("Petstore") .basePath("/choreo") @@ -76,7 +76,7 @@ public void extractInternalKeyInWSProtocolHeaderTest() { Map headersMap = new HashMap<>(); headersMap.put( secWebsocketProtocolHeader, - "choreo-internal-API-Key," + mockToken); + "choreo-api-key," + mockToken); builder.headers(headersMap); RequestContext requestContext = builder.build(); InternalAPIKeyAuthenticator internalAPIKeyAuthenticator = new InternalAPIKeyAuthenticator(securityParam); @@ -128,7 +128,7 @@ public void getProtocolsToSetInRequestHeadersTest() { Map headersMap = new HashMap<>(); headersMap.put( secWebsocketProtocolHeader, - "choreo-internal-API-Key, " + mockToken + ", " + "chat, bar"); + "choreo-api-key, " + mockToken + ", " + "chat, bar"); builder.headers(headersMap); RequestContext requestContext = builder.build(); InternalAPIKeyAuthenticator internalAPIKeyAuthenticator = new InternalAPIKeyAuthenticator(securityParam); diff --git a/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticatorTest.java b/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticatorTest.java index 00a1ea0f68..ce215928bf 100644 --- a/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticatorTest.java +++ b/enforcer-parent/enforcer/src/test/java/org/wso2/choreo/connect/enforcer/security/jwt/JWTAuthenticatorTest.java @@ -119,8 +119,8 @@ public void extractJWTInWSProtocolHeaderTest() { // Test case to test for an Upgrade request sent from the choreo console // The token will be set to the sec-websocket-protocol header with - // choreo-oauth2-key keyword - // the value after choreo-oauth2-key will be the token + // choreo-oauth2-token keyword + // the value after choreo-oauth2-token will be the token RequestContext.Builder builder = new RequestContext.Builder("/pets"); builder.matchedAPI(new APIConfig.Builder("Petstore") .basePath("/choreo") @@ -129,7 +129,7 @@ public void extractJWTInWSProtocolHeaderTest() { Map headersMap = new HashMap<>(); headersMap.put( secWebsocketProtocolHeader, - "choreo-oauth2-key," + mockToken); + "choreo-oauth2-token," + mockToken); builder.headers(headersMap); RequestContext requestContext = builder.build(); JWTAuthenticator jwtAuthenticator = new JWTAuthenticator();