Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting NoSuchElement exception when applying security policies #142

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "soap"
version = "2.0.0"
version = "2.0.1"
authors = ["Ballerina"]
export=["soap", "soap.soap11", "soap.soap12"]
keywords = ["soap"]
Expand All @@ -19,8 +19,8 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "soap-native"
version = "2.0.0"
path = "../native/build/libs/soap-native-2.0.0.jar"
version = "2.0.1"
path = "../native/build/libs/soap-native-2.0.1-SNAPSHOT.jar"

[[platform.java17.dependency]]
groupId = "org.apache.wss4j"
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.12.0"
version = "2.12.1"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -227,7 +227,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -271,7 +271,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "soap"
version = "2.0.0"
version = "2.0.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "http"},
Expand Down
5 changes: 4 additions & 1 deletion ballerina/modules/soap11/tests/soap11_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function testSoapReceiveWithAsymmetricBindingAndInboundConfig() returns error? {
xmlns "http://schemas.xmlsoap.org/soap/envelope/" as soap11;
Client soapClient = check new ("http://localhost:9090",
{
outboundSecurity: {
outboundSecurity: [{
signatureConfig: {
keystore: {
path: KEY_STORE_PATH_2,
Expand All @@ -408,6 +408,9 @@ function testSoapReceiveWithAsymmetricBindingAndInboundConfig() returns error? {
encryptionAlgorithm: wssec:AES_128
}
},
{
timeToLive: 1
}],
inboundSecurity: {
decryptKeystore: {
path: KEY_STORE_PATH_2,
Expand Down
67 changes: 62 additions & 5 deletions ballerina/modules/soap12/tests/soap12_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,13 @@ function testSoapEndpoint() returns error? {
}

@test:Config {
groups: ["soap12", "send_receive", "new2"]
groups: ["soap12", "send_receive"]
}
function testSoapReceiveWithAsymmetricBindingAndInboundConfig() returns error? {
xmlns "http://www.w3.org/2003/05/soap-envelope" as soap11;
xmlns "http://www.w3.org/2003/05/soap-envelope" as soap12;
Client soapClient = check new ("http://localhost:9091",
{
outboundSecurity: {
outboundSecurity: [{
signatureConfig: {
keystore: {
path: KEY_STORE_PATH_2,
Expand All @@ -440,7 +440,58 @@ function testSoapReceiveWithAsymmetricBindingAndInboundConfig() returns error? {
publicKeyAlias: ALIAS,
encryptionAlgorithm: wssec:AES_128
}
},
}],
inboundSecurity: {
decryptKeystore: {
path: KEY_STORE_PATH_2,
password: PASSWORD
},
signatureKeystore: {
path: KEY_STORE_PATH_2,
password: PASSWORD
}
}
}
);
xml body = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding/"><soap:Body xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-9fc31395-d908-4efa-96e5-754b03963236"><quer:Add xmlns:quer="http://tempuri.org/"><quer:intA>2</quer:intA><quer:intB>3</quer:intB></quer:Add></soap:Body></soap:Envelope>`;
xml response = check soapClient->sendReceive(body, "http://tempuri.org/Add");
test:assertEquals((response/<soap12:Body>).toString(), (body/<soap12:Body>).toString());
}

@test:Config {
groups: ["soap12", "send_receive"]
}
function testSoapReceiveWithArrayOfOutboundConfigAndInboundConfig() returns error? {
xmlns "http://www.w3.org/2003/05/soap-envelope" as soap12;
Client soapClient = check new ("http://localhost:9091",
{
outboundSecurity: [{
signatureConfig: {
keystore: {
path: KEY_STORE_PATH_2,
password: PASSWORD
},
privateKeyAlias: ALIAS,
privateKeyPassword: PASSWORD,
signatureAlgorithm: soap:RSA_SHA512,
canonicalizationAlgorithm: soap:C14N_EXCL_OMIT_COMMENTS,
digestAlgorithm: soap:SHA512
},
encryptionConfig: {
keystore: {
path: KEY_STORE_PATH_2,
password: PASSWORD
},
publicKeyAlias: ALIAS,
encryptionAlgorithm: wssec:AES_128
}
}, {
timeToLive: 1
}, {
username: "user",
password: "password",
passwordType: wssec:TEXT
}],
inboundSecurity: {
decryptKeystore: {
path: KEY_STORE_PATH_2,
Expand All @@ -455,5 +506,11 @@ function testSoapReceiveWithAsymmetricBindingAndInboundConfig() returns error? {
);
xml body = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding/"><soap:Body xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-9fc31395-d908-4efa-96e5-754b03963236"><quer:Add xmlns:quer="http://tempuri.org/"><quer:intA>2</quer:intA><quer:intB>3</quer:intB></quer:Add></soap:Body></soap:Envelope>`;
xml response = check soapClient->sendReceive(body, "http://tempuri.org/Add");
test:assertEquals((response/<soap11:Body>).toString(), (body/<soap11:Body>).toString());
string:RegExp usernameTokenTag = re `<wsse:UsernameToken .*>.*</wsse:UsernameToken>`;
string:RegExp usernameTag = re `<wsse:Username>user</wsse:Username>`;
test:assertTrue(response.toString().includesMatch(usernameTokenTag));
test:assertTrue(response.toString().includesMatch(usernameTag));
string:RegExp passwordTag = re `<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>`;
test:assertTrue(response.toString().includesMatch(passwordTag));
test:assertEquals((response/<soap12:Body>).toString(), (body/<soap12:Body>).toString());
}
2 changes: 1 addition & 1 deletion ballerina/soap_utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public isolated function applySecurityPolicies(wssec:OutboundSecurityConfig|wsse
} else {
xml securedEnvelope = envelope.clone();
foreach wssec:OutboundSecurityConfig policy in security {
securedEnvelope = check applySecurityPolicies(policy, securedEnvelope);
securedEnvelope = check applySecurityPolicies(policy, securedEnvelope, soap12);
}
return securedEnvelope;
}
Expand Down
Loading