diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 7fc7d08..22e9105 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "ldap" -version = "1.0.2" +version = "1.1.0" authors = ["Ballerina"] export=["ldap"] keywords = ["ldap"] @@ -15,8 +15,8 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.lib" artifactId = "ldap-native" -version = "1.0.2-SNAPSHOT" -path = "../native/build/libs/ldap-native-1.0.2-SNAPSHOT.jar" +version = "1.1.0-SNAPSHOT" +path = "../native/build/libs/ldap-native-1.1.0-SNAPSHOT.jar" [[platform.java17.dependency]] groupId = "com.unboundid" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 8a69f31..80b73fd 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.9.0" [[package]] org = "ballerina" @@ -65,7 +65,7 @@ scope = "testOnly" [[package]] org = "ballerina" name = "ldap" -version = "1.0.2" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, diff --git a/gradle.properties b/gradle.properties index d3abbad..0f0ce4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib -version=1.0.2-SNAPSHOT -ballerinaLangVersion=2201.10.0 +version=1.1.0-SNAPSHOT +ballerinaLangVersion=2201.9.0 checkstylePluginVersion=10.12.0 spotbugsPluginVersion=5.0.14 diff --git a/native/src/main/java/io/ballerina/lib/ldap/Client.java b/native/src/main/java/io/ballerina/lib/ldap/Client.java index 4df9bdf..341999f 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/Client.java +++ b/native/src/main/java/io/ballerina/lib/ldap/Client.java @@ -102,6 +102,13 @@ public final class Client { private static final BString SECURE_SOCKET_CONFIG_TRUSTSTORE_FILE_PATH = StringUtils.fromString("path"); private static final BString SECURE_SOCKET_CONFIG_TRUSTSTORE_PASSWORD = StringUtils.fromString("password"); private static final BString SECURE_SOCKET_CONFIG_CERT = StringUtils.fromString("cert"); + public static final String PKCS_12 = "PKCS12"; + public static final String PEM = "PEM"; + public static final String TRUST_STORE_INITIALIZATION_ERROR = "Error occurred while initializing trust store"; + public static final String UNSUPPORTED_TRUST_STORE_TYPE_ERROR = "Unsupported trust store type"; + public static final String EMPTY_TRUST_STORE_FILE_PATH_ERROR = "Truststore file path cannot be empty"; + public static final String EMPTY_TRUST_STORE_PASSWORD_ERROR = "Truststore password cannot be empty"; + public static final String EMPTY_CERTIFICATE_FILE_PATH_ERROR = "Certificate file path cannot be empty"; private Client() { } @@ -174,26 +181,26 @@ private static void evaluateCertField(Object cert, SSLConfig sslConfiguration) { String trustStoreFile = trustStore.getStringValue(SECURE_SOCKET_CONFIG_TRUSTSTORE_FILE_PATH).getValue(); String trustStorePassword = trustStore.getStringValue(SECURE_SOCKET_CONFIG_TRUSTSTORE_PASSWORD).getValue(); if (trustStoreFile.isBlank()) { - throw new IllegalArgumentException("Truststore file path cannot be empty"); + throw new IllegalArgumentException(EMPTY_TRUST_STORE_FILE_PATH_ERROR); } if (trustStorePassword.isBlank()) { - throw new IllegalArgumentException("Truststore password cannot be empty"); + throw new IllegalArgumentException(EMPTY_TRUST_STORE_PASSWORD_ERROR); } sslConfiguration.setTrustStoreFile(trustStoreFile); sslConfiguration.setTrustStorePass(trustStorePassword); - sslConfiguration.setTLSStoreType("PKCS12"); + sslConfiguration.setTLSStoreType(PKCS_12); } else { String certFile = ((BString) cert).getValue(); if (certFile.isBlank()) { - throw new IllegalArgumentException("Certificate file path cannot be empty"); + throw new IllegalArgumentException(EMPTY_CERTIFICATE_FILE_PATH_ERROR); } sslConfiguration.setTrustStoreFile(certFile); - sslConfiguration.setTLSStoreType("PEM"); + sslConfiguration.setTLSStoreType(PEM); } } private static AggregateTrustManager buildAggregatedTrustManager(SSLConfig sslConfiguration) { - if (sslConfiguration.getTLSStoreType().equals("PEM")) { + if (sslConfiguration.getTLSStoreType().equals(PEM)) { try { PEMFileTrustManager pemFileTrustManager = new PEMFileTrustManager( sslConfiguration.getTrustStore()); @@ -201,10 +208,9 @@ private static AggregateTrustManager buildAggregatedTrustManager(SSLConfig sslCo JVMDefaultTrustManager.getInstance(), pemFileTrustManager); } catch (KeyStoreException e) { - throw new IllegalArgumentException("Error occurred while initializing trust store" - + e.getMessage()); + throw new IllegalArgumentException(TRUST_STORE_INITIALIZATION_ERROR + e.getMessage()); } - } else if (sslConfiguration.getTLSStoreType().equals("PKCS12")) { + } else if (sslConfiguration.getTLSStoreType().equals(PKCS_12)) { TrustStoreTrustManager trustStoreManager = new TrustStoreTrustManager(sslConfiguration.getTrustStore(), sslConfiguration.getTrustStorePass().toCharArray(), sslConfiguration.getTLSStoreType(), true); @@ -212,7 +218,7 @@ private static AggregateTrustManager buildAggregatedTrustManager(SSLConfig sslCo JVMDefaultTrustManager.getInstance(), trustStoreManager); } else { - throw new IllegalArgumentException("Unsupported trust store type"); + throw new IllegalArgumentException(UNSUPPORTED_TRUST_STORE_TYPE_ERROR); } }