Skip to content

Commit

Permalink
Change inbound and outbound security configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Oct 11, 2024
1 parent a243770 commit 850e22a
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 107 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ The SOAP client module introduces a robust framework for configuring security me

There are two primary security configurations available for SOAP clients:

- `inboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.
- `outboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.

- `outboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.
- `inboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.

### Policies

Expand Down Expand Up @@ -133,7 +133,7 @@ These policies empower SOAP clients to enhance the security of their web service

#### Outbound Security Configurations

- `OutboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- `InboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- Fields:
- `crypto:PublicKey` verificationKey : The public key to verify the signature of the SOAP envelope
- `crypto:PrivateKey`|`crypto:PublicKey` decryptionKey : The private key to decrypt the SOAP envelope
Expand All @@ -153,7 +153,7 @@ import ballerina/soap.soap11;
public function main() returns error? {
soap11:Client soapClient = check new ("https://www.secured-soap-endpoint.com",
{
inboundSecurity: [
outboundSecurity: [
{
username: "username",
password: "password",
Expand Down Expand Up @@ -190,13 +190,13 @@ public function main() returns error? {
soap12:Client soapClient = check new ("https://www.secured-soap-endpoint.com",
{
inboundSecurity: {
outboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: clientPrivateKey,
encryptionKey: serverPublicKey,
},
outboundSecurity: {
inboundSecurity: {
verificationKey: serverPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionKey: clientPrivateKey,
Expand Down
12 changes: 6 additions & 6 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ The SOAP client module introduces a robust framework for configuring security me

There are two primary security configurations available for SOAP clients:

- `inboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.
- `outboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.

- `outboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.
- `inboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.

### Policies

Expand Down Expand Up @@ -125,7 +125,7 @@ These policies empower SOAP clients to enhance the security of their web service

#### Outbound Security Configurations

- `OutboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- `InboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- Fields:
- `crypto:PublicKey` verificationKey : The public key to verify the signature of the SOAP envelope
- `crypto:PrivateKey`|`crypto:PublicKey` decryptionKey : The private key to decrypt the SOAP envelope
Expand All @@ -145,7 +145,7 @@ import ballerina/soap.soap11;
public function main() returns error? {
soap11:Client soapClient = check new ("https://www.secured-soap-endpoint.com",
{
inboundSecurity: [
outboundSecurity: [
{
username: "username",
password: "password",
Expand Down Expand Up @@ -182,13 +182,13 @@ public function main() returns error? {
soap12:Client soapClient = check new ("https://www.secured-soap-endpoint.com",
{
inboundSecurity: {
outboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: clientPrivateKey,
encryptionKey: serverPublicKey,
},
outboundSecurity: {
inboundSecurity: {
verificationKey: serverPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionKey: clientPrivateKey,
Expand Down
12 changes: 6 additions & 6 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ The SOAP client module introduces a robust framework for configuring security me

There are two primary security configurations available for SOAP clients:

- `inboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.
- `outboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.

- `outboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.
- `inboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.

### Policies

Expand Down Expand Up @@ -125,7 +125,7 @@ These policies empower SOAP clients to enhance the security of their web service

#### Outbound Security Configurations

- `OutboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- `InboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- Fields:
- `crypto:PublicKey` verificationKey : The public key to verify the signature of the SOAP envelope
- `crypto:PrivateKey`|`crypto:PublicKey` decryptionKey : The private key to decrypt the SOAP envelope
Expand All @@ -145,7 +145,7 @@ import ballerina/soap.soap11;
public function main() returns error? {
soap11:Client soapClient = check new ("https://www.secured-soap-endpoint.com",
{
inboundSecurity: [
outboundSecurity: [
{
username: "username",
password: "password",
Expand Down Expand Up @@ -182,13 +182,13 @@ public function main() returns error? {
soap12:Client soapClient = check new ("https://www.secured-soap-endpoint.com",
{
inboundSecurity: {
outboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: clientPrivateKey,
encryptionKey: serverPublicKey,
},
outboundSecurity: {
inboundSecurity: {
verificationKey: serverPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionKey: clientPrivateKey,
Expand Down
8 changes: 4 additions & 4 deletions ballerina/configs.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import ballerina/http;
# SOAP client configurations.
#
# + httpConfig - HTTP Configuration
# + inboundSecurity - Web service security configurations for SOAP requests
# + outboundSecurity - Web service security configurations to decrypt and verify SOAP responses
# + outboundSecurity - Web service security configurations for SOAP requests
# + inboundSecurity - Web service security configurations to decrypt and verify SOAP responses
public type ClientConfig record {|
http:ClientConfiguration httpConfig = {};
InboundSecurityConfig|InboundSecurityConfig[] inboundSecurity = NO_POLICY;
OutboundSecurityConfig outboundSecurity = {};
OutboundSecurityConfig|OutboundSecurityConfig[] outboundSecurity = NO_POLICY;
InboundSecurityConfig inboundSecurity = {};
|};
10 changes: 5 additions & 5 deletions ballerina/modules/soap11/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ The SOAP client module introduces a robust framework for configuring security me

There are two primary security configurations available for SOAP clients:

- `inboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.
- `outboundSecurity`: This configuration is applied to the SOAP envelope when a request is made. It includes various ws security policies such as Username Token, Timestamp Token, X509 Token, Symmetric Binding, Asymmetric Binding, and Transport Binding, either individually or in combination with each other.

- `outboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.
- `inboundSecurity`: This configuration is applied to the SOAP envelope when a response is received. Its purpose is to decrypt the data within the envelope and verify the digital signature for security validation.

### Policies

Expand Down Expand Up @@ -117,7 +117,7 @@ These policies empower SOAP clients to enhance the security of their web service

#### Outbound Security Configurations

- `OutboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- `InboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- Fields:
- `crypto:PublicKey` verificationKey : The public key to verify the signature of the SOAP envelope
- `crypto:PrivateKey`|`crypto:PublicKey` decryptionKey : The private key to decrypt the SOAP envelope
Expand All @@ -141,13 +141,13 @@ public function main() returns error? {
soap11:Client soapClient = check new ("http://www.secured-soap-endpoint.com",
{
inboundSecurity: {
outboundSecurity: {
signatureAlgorithm: soap:RSA_SHA256,
encryptionAlgorithm: soap:RSA_ECB,
signatureKey: clientPrivateKey,
encryptionKey: serverPublicKey,
},
outboundSecurity: {
inboundSecurity: {
verificationKey: serverPublicKey,
signatureAlgorithm: soap:RSA_SHA256,
decryptionKey: clientPrivateKey,
Expand Down
18 changes: 9 additions & 9 deletions ballerina/modules/soap11/soap11.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import ballerina/jballerina.java;
# Object for the basic SOAP 1.1 client endpoint.
public isolated client class Client {
private final http:Client soapClient;
private final readonly & soap:InboundSecurityConfig|soap:InboundSecurityConfig[] inboundSecurity;
private final readonly & soap:OutboundSecurityConfig outboundSecurity;
private final readonly & soap:OutboundSecurityConfig|soap:OutboundSecurityConfig[] outboundSecurity;
private final readonly & soap:InboundSecurityConfig inboundSecurity;

# Gets invoked during object initialization.
#
Expand All @@ -36,8 +36,8 @@ public isolated client class Client {
check soap:validateTransportBindingPolicy(config);
self.soapClient = check new (url, config.httpConfig);
readonly & soap:ClientConfig readonlyConfig = soap:getReadOnlyClientConfig(config);
self.inboundSecurity = readonlyConfig.inboundSecurity;
self.outboundSecurity = readonlyConfig.outboundSecurity;
self.inboundSecurity = readonlyConfig.inboundSecurity;
} on fail var err {
return error Error(SOAP_CLIENT_ERROR, err);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public isolated client class Client {
xml mimeEntity = body is xml ? body : check body[0].getXml();
lock {
xml envelope = body is xml ? body.clone() : mimeEntity.clone();
securedBody = check soap:applySecurityPolicies(self.inboundSecurity.clone(), envelope.clone(), false);
securedBody = check soap:applySecurityPolicies(self.outboundSecurity.clone(), envelope.clone(), false);
}
xml|mime:Entity[] response;
if body is mime:Entity[] {
Expand All @@ -81,13 +81,13 @@ public isolated client class Client {
response = check soap:sendReceive(securedBody, self.soapClient, action, headers, path, false);
}
lock {
soap:OutboundSecurityConfig? outboundSecurity = self.outboundSecurity.clone();
soap:InboundSecurityConfig? inboundSecurity = self.inboundSecurity.clone();
do {
if outboundSecurity is soap:OutboundSecurityConfig && outboundSecurity != {} {
if inboundSecurity is soap:InboundSecurityConfig && inboundSecurity != {} {
if response is xml {
return check soap:applyOutboundConfig(outboundSecurity.clone(), response.clone(), false);
return check soap:applyOutboundConfig(inboundSecurity.clone(), response.clone(), false);
} else {
return check soap:applyOutboundConfig(outboundSecurity.clone(),
return check soap:applyOutboundConfig(inboundSecurity.clone(),
check response[0].getXml().clone(), false);
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public isolated client class Client {
xml mimeEntity = body is xml ? body : check body[0].getXml();
lock {
xml envelope = body is xml ? body.clone() : mimeEntity.clone();
securedBody = check soap:applySecurityPolicies(self.inboundSecurity.clone(), envelope.clone(), false);
securedBody = check soap:applySecurityPolicies(self.outboundSecurity.clone(), envelope.clone(), false);
}
return check soap:sendOnly(securedBody, self.soapClient, action, headers, path, false);
} on fail error soapError {
Expand Down
Loading

0 comments on commit 850e22a

Please sign in to comment.