Skip to content

Commit

Permalink
Merge branch 'ws-security-policies' of https://github.com/Nuvindu/mod…
Browse files Browse the repository at this point in the history
…ule-ballerina-soap into ws-security-policies
  • Loading branch information
Nuvindu committed Oct 13, 2023
2 parents 5970f3c + 6f98be1 commit 0d9c804
Show file tree
Hide file tree
Showing 40 changed files with 114 additions and 126 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
}
```

Expand Down
17 changes: 4 additions & 13 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ version = "0.0.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "lang.regexp", moduleName = "lang.regexp"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -264,18 +267,6 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "regex"
version = "1.4.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.string"}
]
modules = [
{org = "ballerina", packageName = "regex", moduleName = "regex"}
]

[[package]]
org = "ballerina"
name = "soap"
Expand All @@ -285,8 +276,8 @@ dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.regexp"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "regex"},
{org = "ballerina", name = "test"},
{org = "ballerinai", name = "observe"}
]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
}
```
## Security
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
}
```
## Security
Expand Down
2 changes: 1 addition & 1 deletion ballerina/configs.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/constants.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/error.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap11/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
}
```
## Security
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap11/error.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap11/soap11.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap11/tests/soap11_client_test.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap12/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function main() returns error? {
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|mime:Entity[] response = check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
check soapClient->sendOnly(envelope, "http://tempuri.org/Add");
}
```
## Security
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap12/error.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/soap12/soap12.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand Down
16 changes: 8 additions & 8 deletions ballerina/modules/soap12/tests/soap12_client_test.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand All @@ -20,11 +20,11 @@ import ballerina/test;
import ballerina/crypto;
import soap.wssec;

const string KEY_ALIAS = "wss40";
const string KEY_PASSWORD = "security";
const string KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12";
const string X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12";
const string X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12";
const KEY_ALIAS = "wss40";
const KEY_PASSWORD = "security";
const KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12";
const X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12";
const X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12";
const wssec:TransportBindingConfig TRANSPORT_BINDING = "TransportBinding";
const wssec:NoPolicy NO_POLICY = "NoPolicy";

Expand All @@ -45,7 +45,7 @@ function testSendOnly12() returns error? {

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");

_ = check soapClient->sendOnly(body, "http://tempuri.org/Add");
check soapClient->sendOnly(body, "http://tempuri.org/Add");
}

@test:Config {
Expand Down Expand Up @@ -134,7 +134,7 @@ function testSendOnly12WithoutSoapAction() returns error? {

Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");

_ = check soapClient->sendOnly(body);
check soapClient->sendOnly(body);
}

@test:Config {
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/document.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/encryption.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/error.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/init.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/records.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/sec_header.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/signature.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
24 changes: 12 additions & 12 deletions ballerina/modules/wssec/tests/test_utils.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand All @@ -15,19 +15,19 @@
// under the License.
import ballerina/test;

const string USERNAME = "username";
const string PASSWORD = "password";
const USERNAME = "username";
const PASSWORD = "password";

const string KEY_ALIAS = "wss40";
const string KEY_PASSWORD = "security";
const KEY_ALIAS = "wss40";
const KEY_PASSWORD = "security";

const string PUBLIC_KEY_PATH = "modules/wssec/tests/resources/public_key.cer";
const string PRIVATE_KEY_PATH = "modules/wssec/tests/resources/private_key.pem";
const string KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12";
const string X509_PUBLIC_CERT_PATH = "modules/wssec/tests/resources/x509_certificate.crt";
const string X509_PUBLIC_CERT_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.crt";
const string X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12";
const string X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12";
const PUBLIC_KEY_PATH = "modules/wssec/tests/resources/public_key.cer";
const PRIVATE_KEY_PATH = "modules/wssec/tests/resources/private_key.pem";
const KEY_STORE_PATH = "modules/wssec/tests/resources/wss40.p12";
const X509_PUBLIC_CERT_PATH = "modules/wssec/tests/resources/x509_certificate.crt";
const X509_PUBLIC_CERT_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.crt";
const X509_KEY_STORE_PATH = "modules/wssec/tests/resources/x509_certificate.p12";
const X509_KEY_STORE_PATH_2 = "modules/wssec/tests/resources/x509_certificate_2.p12";

function assertTimestampToken(string envelopeString) {
string:RegExp ts_token = re `<wsu:Timestamp wsu:Id=".*">`;
Expand Down
14 changes: 7 additions & 7 deletions ballerina/modules/wssec/tests/ws_security_tests.bal
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ballerina/crypto;
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
Expand All @@ -14,8 +13,9 @@ import ballerina/crypto;
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import ballerina/crypto;
import ballerina/test;
import ballerina/regex;
import ballerina/lang.regexp;

@test:Config {
groups: ["timestamp_token"]
Expand Down Expand Up @@ -522,11 +522,11 @@ function testSymmetricBindingWithOutboundConfig() returns error? {
};

crypto:PrivateKey|crypto:PublicKey? privateKey = outboundConfig.decryptionKey;
if privateKey !is () {
if privateKey is crypto:PrivateKey|crypto:PublicKey {
byte[] encData = check getEncryptedData(securedEnvelope);
byte[] decryptDataResult = check decryptData(encData, RSA_ECB, privateKey);
string decryptedBody = "<soap:Body >" + check string:fromBytes(decryptDataResult) + "</soap:Body>";
envelopeString = regex:replace(envelopeString, string`<soap:Body .*>.*</soap:Body>`, decryptedBody);
envelopeString = regexp:replace(re `<soap:Body .*>.*</soap:Body>`, envelopeString, decryptedBody);
securedEnvelope = check xml:fromString(envelopeString);
}
byte[] signedData = check getSignatureData(securedEnvelope);
Expand Down Expand Up @@ -893,11 +893,11 @@ function testAsymmetricBindingWithOutboundConfig() returns error? {
xml securedEnvelope = check applyAsymmetricBinding(envelope, asymmetricBinding);
string envelopeString = securedEnvelope.toString();
crypto:PrivateKey|crypto:PublicKey? privateKey = outboundConfig.decryptionKey;
if privateKey !is () {
if privateKey is crypto:PrivateKey|crypto:PublicKey {
byte[] encData = check getEncryptedData(securedEnvelope);
byte[] decryptDataResult = check decryptData(encData, RSA_ECB, privateKey);
string decryptedBody = "<soap:Body >" + check string:fromBytes(decryptDataResult) + "</soap:Body>";
envelopeString = regex:replace(envelopeString, string`<soap:Body .*>.*</soap:Body>`, decryptedBody);
envelopeString = regexp:replace(re `<soap:Body .*>.*</soap:Body>`, envelopeString, decryptedBody);
securedEnvelope = check xml:fromString(envelopeString);
}
byte[] signedData = check getSignatureData(securedEnvelope);
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/types.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
2 changes: 1 addition & 1 deletion ballerina/modules/wssec/ws_security.bal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) 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
Expand Down
Loading

0 comments on commit 0d9c804

Please sign in to comment.