Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Oct 15, 2024
1 parent 9ae8629 commit 89aec51
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ These policies empower SOAP clients to enhance the security of their web service

#### Inbound Security Configurations

- `InboundSecurityConfig`: Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
- `InboundSecurityConfig`: Represents the record for inbound 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 Down
10 changes: 5 additions & 5 deletions ballerina/modules/soap11/soap11.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,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.outboundSecurity = readonlyConfig.outboundSecurity;
self.inboundSecurity = readonlyConfig.inboundSecurity;
self.outboundSecurity = readonlyConfig.outboundSecurity;
} on fail var err {
return error Error(SOAP_CLIENT_ERROR, err);
}
Expand Down Expand Up @@ -82,13 +82,13 @@ public isolated client class Client {
response = check soap:sendReceive(securedBody, self.soapClient, action, headers, path, false);
}
lock {
soap:InboundSecurityConfig? inboundSecurity = self.inboundSecurity.clone();
wssec:InboundConfig? inboundSecurity = self.inboundSecurity.clone();
do {
if inboundSecurity is soap:InboundSecurityConfig && inboundSecurity != {} {
if inboundSecurity is wssec:InboundConfig && inboundSecurity != {} {
if response is xml {
return check soap:applyOutboundConfig(<wssec:InboundConfig>inboundSecurity.clone(), response.clone(), false);
return check soap:applyOutboundConfig(inboundSecurity.clone(), response.clone(), false);
} else {
return check soap:applyOutboundConfig(<wssec:InboundConfig>inboundSecurity.clone(),
return check soap:applyOutboundConfig(inboundSecurity.clone(),
check response[0].getXml().clone(), false);
}
}
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 @@ -398,7 +398,10 @@ function testSoapReceiveWithAsymmetricBindingAndInboundConfig() returns error? {
}
},
inboundSecurity: {
keystore: {path: KEY_STORE_PATH_2, password: PASSWORD},
keystore: {
path: KEY_STORE_PATH_2,
password: PASSWORD
},
verificationKey: publicKey,
signatureAlgorithm: wssec:RSA_SHA256,
decryptionAlgorithm: wssec:AES_128
Expand Down
3 changes: 2 additions & 1 deletion ballerina/modules/wssec/records.bal
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ public type NoPolicy "NoPolicy";

# Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
#
# + keystore - The keystore to store the private key
# + verificationKey - The public key to verify the signature of the SOAP envelope
# + decryptionKey - The private key to decrypt the SOAP envelope
# + signatureAlgorithm - The algorithm to verify the SOAP envelope
# + decryptionKey - The private key to decrypt the SOAP envelope
# + decryptionAlgorithm - The algorithm to decrypt the SOAP body
public type InboundConfig record {|
crypto:KeyStore keystore?;
Expand Down
14 changes: 7 additions & 7 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public enum EncryptionAlgorithm {
RSA_ECB = "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
}

# Represents the record for outbound security configurations to verify and decrypt SOAP envelopes.
#
# Represents the record for inbound security configurations to verify and decrypt SOAP envelopes.
#
# + keystore - The keystore to store the private key
# + verificationKey - The public key to verify the signature of the SOAP envelope
# + decryptionKey - The private key to decrypt the SOAP envelope
# + signatureAlgorithm - The algorithm to verify the SOAP envelope
# + decryptionKey - The private key to decrypt the SOAP envelope
# + decryptionAlgorithm - The algorithm to decrypt the SOAP body
public type InboundSecurityConfig record {
*wssec:InboundConfig;
};
public type InboundSecurityConfig wssec:InboundConfig;

# Union type of all the inbound web service security configurations.
# Union type of all the outbound web service security configurations.
public type OutboundSecurityConfig wssec:OutboundSecurityConfig;

2 changes: 1 addition & 1 deletion native/src/main/java/org/wssec/WsSecurity.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static Crypto getCryptoInstance(String path, String password) throws WSS

private static void validateSoapHeader(Boolean soap12, Document document) {
Init.init();
String namespace = (soap12) ? WSConstants.URI_SOAP12_ENV : WSConstants.URI_SOAP11_ENV;
String namespace = soap12 ? WSConstants.URI_SOAP12_ENV : WSConstants.URI_SOAP11_ENV;
Element header = (Element) document.getElementsByTagNameNS(namespace, ELEM_HEADER).item(0);
if (header == null) {
throw new IllegalStateException("SOAP Envelope must have a Header");
Expand Down

0 comments on commit 89aec51

Please sign in to comment.