Skip to content

Commit

Permalink
Migrate soap:common module into the soap module
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Oct 5, 2023
1 parent b9ee921 commit 9ebde88
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 38 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 11 additions & 13 deletions ballerina/modules/soap11/soap11.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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());
Expand All @@ -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());
}
Expand Down
13 changes: 7 additions & 6 deletions ballerina/modules/soap11/tests/soap11_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -180,7 +181,7 @@ function testSendReceiveWithUsernameTokenSecurity() returns error? {
inboundSecurity: {
username: "user",
password: "password",
passwordType: wssec:TEXT
passwordType: soap:TEXT
},
outboundSecurity: {}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 11 additions & 13 deletions ballerina/modules/soap12/soap12.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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());
Expand All @@ -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());
}
Expand Down
13 changes: 7 additions & 6 deletions ballerina/modules/soap12/tests/soap12_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -243,7 +244,7 @@ function testSendReceiveWithUsernameTokenSecurity() returns error? {
inboundSecurity: {
username: "user",
password: "password",
passwordType: wssec:TEXT
passwordType: soap:TEXT
},
outboundSecurity: {}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 9ebde88

Please sign in to comment.