From 20a4fb7b01959bb251ef3c768c42923afaf95ed6 Mon Sep 17 00:00:00 2001 From: Milan Perera Date: Tue, 9 Apr 2019 13:25:46 +0530 Subject: [PATCH 1/2] Fix Authentication Handler Issue Replaced the invalid value in the AuthenticationHandler file to support mutual SSL. --- .../org/wso2/carbon/apimgt/handlers/AuthenticationHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandler.java index b851ee4f8c..6c95b40dee 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/main/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandler.java @@ -209,7 +209,7 @@ public class AuthenticationHandler extends AbstractHandler { private String getDeviceType(String url) { StringTokenizer parts = new StringTokenizer(url, "/"); while (parts.hasMoreElements()) { - if (parts.nextElement().equals("api")) { + if (parts.nextElement().equals("device-mgt")) { return (String) parts.nextElement(); } } From a7e40db75bae8b316c6d7356b9b968249f6509a6 Mon Sep 17 00:00:00 2001 From: Milan Perera Date: Tue, 9 Apr 2019 13:54:05 +0530 Subject: [PATCH 2/2] Fix AuthenticationHandler Test Failure --- .../handlers/AuthenticationHandlerTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/test/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandlerTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/test/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandlerTest.java index f42505409a..b3b8cdac78 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/test/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandlerTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/src/test/java/org/wso2/carbon/apimgt/handlers/AuthenticationHandlerTest.java @@ -96,7 +96,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getValidationResponse()); boolean response = this.handler.handleRequest(createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice")); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice")); Assert.assertTrue(response); this.mockClient.reset(); } @@ -110,7 +110,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getValidationResponse()); boolean response = this.handler.handleRequest(createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice")); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice")); Assert.assertTrue(response); this.mockClient.reset(); } @@ -124,7 +124,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getValidationResponse()); MessageContext messageContext = createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice"); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice"); org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); String certStr = getContent(TestUtils.getAbsolutePathOfConfig("ra_cert.pem")); X509Certificate cert = X509Certificate.getInstance(new ByteArrayInputStream(certStr. @@ -144,7 +144,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getValidationResponse()); MessageContext messageContext = createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice"); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice"); boolean response = this.handler.handleRequest(messageContext); Assert.assertTrue(response); this.mockClient.reset(); @@ -159,7 +159,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getInvalidResponse()); MessageContext messageContext = createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice"); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice"); boolean response = this.handler.handleRequest(messageContext); Assert.assertFalse(response); this.mockClient.reset(); @@ -173,7 +173,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { setMockClient(); this.mockClient.setResponse(null); MessageContext messageContext = createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice"); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice"); boolean response = this.handler.handleRequest(messageContext); Assert.assertFalse(response); this.mockClient.reset(); @@ -188,7 +188,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(null); MessageContext messageContext = createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice"); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice"); boolean response = this.handler.handleRequest(messageContext); Assert.assertFalse(response); this.mockClient.reset(); @@ -202,7 +202,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest { transportHeaders.put(AuthConstants.MDM_SIGNATURE, "some cert"); AuthenticationHandler handler = new AuthenticationHandler(); boolean response = handler.handleRequest(createSynapseMessageContext("", this.synapseConfiguration, - transportHeaders, "https://test.com/testservice/api/testdevice")); + transportHeaders, "https://test.com/testservice/device-mgt/testdevice")); Assert.assertFalse(response); TestUtils.setSystemProperties(); }