diff --git a/ballerina/modules/common/configs.bal b/ballerina/configs.bal similarity index 100% rename from ballerina/modules/common/configs.bal rename to ballerina/configs.bal diff --git a/ballerina/modules/common/constants.bal b/ballerina/constants.bal similarity index 100% rename from ballerina/modules/common/constants.bal rename to ballerina/constants.bal diff --git a/ballerina/modules/common/error.bal b/ballerina/error.bal similarity index 100% rename from ballerina/modules/common/error.bal rename to ballerina/error.bal diff --git a/ballerina/modules/soap11/soap11.bal b/ballerina/modules/soap11/soap11.bal index a06bfc5..4a31e66 100644 --- a/ballerina/modules/soap11/soap11.bal +++ b/ballerina/modules/soap11/soap11.bal @@ -13,14 +13,12 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -import soap.common; +import soap; import soap.wssec; import ballerina/http; import ballerina/mime; -xmlns "http://schemas.xmlsoap.org/soap/envelope/" as soap; - # Object for the basic SOAP client endpoint. public client class Client { private final http:Client soapClient; @@ -32,10 +30,10 @@ public client class Client { # + url - URL endpoint # + config - Configurations for SOAP client # + return - `error` in case of errors or `()` otherwise - public function init(string url, *common:ClientConfig config) returns Error? { + public function init(string url, *soap:ClientConfig config) returns Error? { do { - check common:validateTransportBindingPolicy(config); - self.soapClient = check new (url, common:retrieveHttpClientConfig(config)); + check soap:validateTransportBindingPolicy(config); + self.soapClient = check new (url, soap:retrieveHttpClientConfig(config)); self.inboundSecurity = config.inboundSecurity; self.outboundSecurity = config.outboundSecurity; } on fail var err { @@ -57,16 +55,16 @@ public client class Client { do { xml securedBody; if body is xml { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, body); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, body); } else { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); } - xml response = check common:sendReceive(securedBody, self.soapClient, + xml response = check soap:sendReceive(securedBody, self.soapClient, action, headers, false); wssec:OutboundSecurityConfig? outboundSecurity = self.outboundSecurity; do { if outboundSecurity !is () { - return check common:applyOutboundConfig(outboundSecurity, response); + return check soap:applyOutboundConfig(outboundSecurity, response); } } on fail var e { return error Error(INVALID_OUTBOUND_SECURITY_ERROR, e.cause()); @@ -91,11 +89,11 @@ public client class Client { do { xml securedBody; if body is xml { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, body); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, body); } else { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); } - return check common:sendOnly(securedBody, self.soapClient, action, headers, false); + return check soap:sendOnly(securedBody, self.soapClient, action, headers, false); } on fail var e { return error Error(e.message()); } diff --git a/ballerina/modules/soap11/tests/soap11_client_test.bal b/ballerina/modules/soap11/tests/soap11_client_test.bal index 88d5da7..23fa5f4 100644 --- a/ballerina/modules/soap11/tests/soap11_client_test.bal +++ b/ballerina/modules/soap11/tests/soap11_client_test.bal @@ -13,11 +13,12 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -import soap.wssec; +import soap; import ballerina/crypto; import ballerina/mime; import ballerina/test; +import soap.wssec; const string KEY_ALIAS = "wss40"; const string KEY_PASSWORD = "security"; @@ -180,7 +181,7 @@ function testSendReceiveWithUsernameTokenSecurity() returns error? { inboundSecurity: { username: "user", password: "password", - passwordType: wssec:TEXT + passwordType: soap:TEXT }, outboundSecurity: {} } @@ -224,8 +225,8 @@ function testSendReceiveWithAsymmetricBindingSecurity() returns error? { Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", { inboundSecurity: { - signatureAlgorithm: wssec:RSA_SHA256, - encryptionAlgorithm: wssec:RSA_ECB, + signatureAlgorithm: soap:RSA_SHA256, + encryptionAlgorithm: soap:RSA_ECB, signatureKey: clientPrivateKey, encryptionKey: serverPublicKey } @@ -269,8 +270,8 @@ function testSendReceiveWithSymmetricBindingSecurity() returns error? { Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", { inboundSecurity: { - signatureAlgorithm: wssec:RSA_SHA256, - encryptionAlgorithm: wssec:RSA_ECB, + signatureAlgorithm: soap:RSA_SHA256, + encryptionAlgorithm: soap:RSA_ECB, symmetricKey: symmetricKey, servicePublicKey: serverPublicKey } diff --git a/ballerina/modules/soap12/soap12.bal b/ballerina/modules/soap12/soap12.bal index 0b98783..d5214ba 100644 --- a/ballerina/modules/soap12/soap12.bal +++ b/ballerina/modules/soap12/soap12.bal @@ -13,14 +13,12 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -import soap.common; +import soap; import soap.wssec; import ballerina/http; import ballerina/mime; -xmlns "http://www.w3.org/2003/05/soap-envelope" as soap; - # Object for the basic SOAP client endpoint. public client class Client { private final http:Client soapClient; @@ -32,10 +30,10 @@ public client class Client { # + url - URL endpoint # + config - Configurations for SOAP client # + return - `error` in case of errors or `()` otherwise - public function init(string url, *common:ClientConfig config) returns Error? { + public function init(string url, *soap:ClientConfig config) returns Error? { do { - check common:validateTransportBindingPolicy(config); - self.soapClient = check new (url, common:retrieveHttpClientConfig(config)); + check soap:validateTransportBindingPolicy(config); + self.soapClient = check new (url, soap:retrieveHttpClientConfig(config)); self.inboundSecurity = config.inboundSecurity; self.outboundSecurity = config.outboundSecurity; } on fail var err { @@ -57,15 +55,15 @@ public client class Client { do { xml securedBody; if body is xml { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, body); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, body); } else { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); } - xml response = check common:sendReceive(securedBody, self.soapClient, action, headers); + xml response = check soap:sendReceive(securedBody, self.soapClient, action, headers); wssec:OutboundSecurityConfig? outboundSecurity = self.outboundSecurity; do { if outboundSecurity !is () { - return check common:applyOutboundConfig(outboundSecurity, response); + return check soap:applyOutboundConfig(outboundSecurity, response); } } on fail var e { return error Error(INVALID_OUTBOUND_SECURITY_ERROR, e.cause()); @@ -91,11 +89,11 @@ public client class Client { do { xml securedBody; if body is xml { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, body); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, body); } else { - securedBody = check common:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); + securedBody = check soap:applySecurityPolicies(self.inboundSecurity, check body[0].getXml()); } - return check common:sendOnly(securedBody, self.soapClient, action, headers); + return check soap:sendOnly(securedBody, self.soapClient, action, headers); } on fail var e { return error Error(e.message()); } diff --git a/ballerina/modules/soap12/tests/soap12_client_test.bal b/ballerina/modules/soap12/tests/soap12_client_test.bal index ccb90ea..df7c512 100644 --- a/ballerina/modules/soap12/tests/soap12_client_test.bal +++ b/ballerina/modules/soap12/tests/soap12_client_test.bal @@ -13,11 +13,12 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -import soap.wssec; +import soap; import ballerina/mime; import ballerina/test; import ballerina/crypto; +import soap.wssec; const string KEY_ALIAS = "wss40"; const string KEY_PASSWORD = "security"; @@ -243,7 +244,7 @@ function testSendReceiveWithUsernameTokenSecurity() returns error? { inboundSecurity: { username: "user", password: "password", - passwordType: wssec:TEXT + passwordType: soap:TEXT }, outboundSecurity: {} } @@ -288,8 +289,8 @@ function testSendReceiveWithAsymmetricBindingSecurity() returns error? { Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", { inboundSecurity: { - signatureAlgorithm: wssec:RSA_SHA256, - encryptionAlgorithm: wssec:RSA_ECB, + signatureAlgorithm: soap:RSA_SHA256, + encryptionAlgorithm: soap:RSA_ECB, signatureKey: clientPrivateKey, encryptionKey: serverPublicKey } @@ -334,8 +335,8 @@ function testSendReceiveWithSymmetricBindingSecurity() returns error? { Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL", { inboundSecurity: { - signatureAlgorithm: wssec:RSA_SHA256, - encryptionAlgorithm: wssec:RSA_ECB, + signatureAlgorithm: soap:RSA_SHA256, + encryptionAlgorithm: soap:RSA_ECB, symmetricKey: symmetricKey, servicePublicKey: serverPublicKey } diff --git a/ballerina/modules/common/soap_utils.bal b/ballerina/soap_utils.bal similarity index 100% rename from ballerina/modules/common/soap_utils.bal rename to ballerina/soap_utils.bal diff --git a/ballerina/types.bal b/ballerina/types.bal new file mode 100644 index 0000000..a7eb41f --- /dev/null +++ b/ballerina/types.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public enum PasswordType { + TEXT, + DIGEST, + DERIVED_KEY_TEXT, + DERIVED_KEY_DIGEST +} + +public enum SignatureAlgorithm { + RSA_SHA1 = "http://www.w3.org/2000/09/xmldsig#rsa-sha1", + RSA_SHA256 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", + RSA_SHA384 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384", + RSA_SHA512 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" +} + +public enum EncryptionAlgorithm { + RSA_ECB = "http://www.w3.org/2001/04/xmlenc#rsa-1_5" +}