Skip to content

Commit

Permalink
Merge pull request #71 from warunalakshitha/syncJava21
Browse files Browse the repository at this point in the history
Migrate to Java 21
  • Loading branch information
warunalakshitha authored Nov 18, 2024
2 parents 38bf71f + 50e9bde commit 83b683c
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 120 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ This repository only contains the source code for the package.

### Prerequisites

1. Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
1. Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources:

- [Oracle JDK](https://www.oracle.com/java/technologies/downloads/)
- [OpenJDK](https://adoptium.net/)
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ repository = "https://github.com/ballerina-platform/module-ballerina-ldap"
license = ["Apache-2.0"]
distribution = "2201.9.0"

[platform.java17]
[platform.java21]
graalvmCompatible = true

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.lib"
artifactId = "ldap-native"
version = "1.1.0-SNAPSHOT"
path = "../native/build/libs/ldap-native-1.1.0-SNAPSHOT.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "com.unboundid"
artifactId = "unboundid-ldapsdk"
version = "7.0.0"
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.11.0-20241112-214900-6b80ab87"

[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.2"
version = "2.7.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand Down Expand Up @@ -92,7 +92,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.5.0"
version = "2.6.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ballerina {
module = packageName
testCoverageParam = "--code-coverage --coverage-format=xml"
langVersion = ballerinaLangVersion
platform = "java17"
platform = "java21"
}

configurations {
Expand Down
6 changes: 3 additions & 3 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ repository = "https://github.com/ballerina-platform/module-ballerina-ldap"
license = ["Apache-2.0"]
distribution = "2201.9.0"

[platform.java17]
[platform.java21]
graalvmCompatible = true

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.lib"
artifactId = "ldap-native"
version = "@project.version@"
path = "../native/build/libs/[email protected]@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "com.unboundid"
artifactId = "unboundid-ldapsdk"
version = "@unboundIdLdap.version@"
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ subprojects {
}

/* Standard libraries */
ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}"
ballerinaStdLibs "io.ballerina.stdlib:crypto-ballerina:${stdlibCryptoVersion}"
ballerinaStdLibs "io.ballerina.stdlib:time-ballerina:${stdlibTimeVersion}"
}
Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
org.gradle.caching=true
group=io.ballerina.lib
version=1.1.0-SNAPSHOT
ballerinaLangVersion=2201.9.0
ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77

checkstylePluginVersion=10.12.0
spotbugsPluginVersion=5.0.14
spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=8.1.1
downloadPluginVersion=5.4.0
releasePluginVersion=2.8.0
ballerinaGradlePluginVersion=2.2.4

unboundIdLdapVersion=7.0.0

stdlibCryptoVersion=2.7.2
stdlibTimeVersion=2.5.0
stdlibIoVersion=1.6.2-20240928-084100-656404f
stdlibCryptoVersion=2.7.3-20241113-081400-d015a39
stdlibTimeVersion=2.6.0-20241113-073800-201b904
8 changes: 6 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ test {
}

spotbugsMain {
effort "max"
reportLevel "low"
def classLoader = plugins["com.github.spotbugs"].class.classLoader
def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence")
def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort")
ignoreFailures = true
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = file("$project.buildDir/reports/spotbugs")
reports {
html.enabled true
Expand Down
213 changes: 121 additions & 92 deletions native/src/main/java/io/ballerina/lib/ldap/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
import com.unboundid.util.ssl.TrustStoreTrustManager;
import io.ballerina.lib.ldap.ssl.SSLConfig;
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.TypeTags;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.utils.ValueUtils;
Expand All @@ -65,6 +64,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import static com.unboundid.ldap.sdk.ResultCode.NO_SUCH_OBJECT;
import static com.unboundid.ldap.sdk.ResultCode.OTHER;
Expand Down Expand Up @@ -223,83 +223,104 @@ private static AggregateTrustManager buildAggregatedTrustManager(SSLConfig sslCo
}

public static Object add(Environment env, BObject ldapClient, BString dN, BMap<BString, Object> entry) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
AddRequest addRequest = generateAddRequest(dN, entry);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncAdd(addRequest, customAsyncResultListener);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
AddRequest addRequest = generateAddRequest(dN, entry);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncAdd(addRequest, customAsyncResultListener);
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static Object modify(Environment env, BObject ldapClient, BString dN, BMap<BString, BString> entry) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
ModifyRequest modifyRequest = generateModifyRequest(dN, entry);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncModify(modifyRequest, customAsyncResultListener);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
ModifyRequest modifyRequest = generateModifyRequest(dN, entry);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncModify(modifyRequest, customAsyncResultListener);
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static Object modifyDn(Environment env, BObject ldapClient, BString currentDn,
BString newRdn, boolean deleteOldRdn) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
ModifyDNRequest modifyRequest = new ModifyDNRequest(currentDn.getValue(), newRdn.getValue(), deleteOldRdn);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncModifyDN(modifyRequest, customAsyncResultListener);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
ModifyDNRequest modifyRequest =
new ModifyDNRequest(currentDn.getValue(), newRdn.getValue(), deleteOldRdn);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncModifyDN(modifyRequest, customAsyncResultListener);
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static Object delete(Environment env, BObject ldapClient, BString dN) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncDelete(new DeleteRequest(dN.getValue()), customAsyncResultListener);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncDelete(new DeleteRequest(dN.getValue()), customAsyncResultListener);
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static Object compare(Environment env, BObject ldapClient,
BString dN, BString attributeName, BString assertionValue) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
CompareRequest compareRequest = new CompareRequest(dN.getValue(), attributeName.getValue(),
assertionValue.getValue());
ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> {
if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) {
future.complete(true);
} else if (compareResult.getResultCode().equals(ResultCode.COMPARE_FALSE)) {
future.complete(false);
} else {
LDAPException ldapException = new LDAPException(compareResult);
future.complete(Utils.createError(ldapException.getMessage(), ldapException));
}
});
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
CompareRequest compareRequest = new CompareRequest(dN.getValue(), attributeName.getValue(),
assertionValue.getValue());
CompletableFuture<Object> future = new CompletableFuture<>();
ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> {
if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) {
future.complete(true);
} else if (compareResult.getResultCode().equals(ResultCode.COMPARE_FALSE)) {
future.complete(false);
} else {
LDAPException ldapException = new LDAPException(compareResult);
future.complete(Utils.createError(ldapException.getMessage(), ldapException));
}
});
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static Object getEntry(BObject ldapClient, BString dN, BTypedesc typeParam) {
Expand All @@ -321,37 +342,45 @@ public static Object getEntry(BObject ldapClient, BString dN, BTypedesc typePara
}

public static Object search(Environment env, BObject ldapClient, BString baseDn, BString filter, BString scope) {
Future future = env.markAsync();
try {
SearchScope searchScope = getSearchScope(scope);
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
SearchResultListener searchResultListener = new CustomSearchResultListener(future, baseDn.getValue());
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
SearchScope searchScope = getSearchScope(scope);
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
SearchResultListener searchResultListener = new CustomSearchResultListener(future, baseDn.getValue());
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static Object searchWithType(Environment env, BObject ldapClient, BString baseDn,
BString filter, BString scope, BTypedesc typeParam) {
Future future = env.markAsync();
try {
SearchScope searchScope = getSearchScope(scope);
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
SearchResultListener searchResultListener = new CustomSearchEntryListener(future, typeParam,
baseDn.getValue());
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
SearchScope searchScope = getSearchScope(scope);
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
validateConnection(ldapConnection);
SearchResultListener searchResultListener = new CustomSearchEntryListener(future, typeParam,
baseDn.getValue());
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
return future.get();
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
} catch (Throwable e) {
return Utils.createError(e.getMessage(), e);
}
});
}

public static void close(BObject ldapClient) {
Expand Down
Loading

0 comments on commit 83b683c

Please sign in to comment.