Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complete API support for the LDAP connector #46

Merged
merged 20 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix async APIs with future completions
  • Loading branch information
Nuvindu committed Jun 17, 2024
commit be8666f3d7ac36c392f90efdbfaaf2c50261fdfa
42 changes: 21 additions & 21 deletions native/src/main/java/io/ballerina/lib/ldap/Ldap.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,67 +93,67 @@ public static BError initLdapConnection(BObject ldapClient, BMap<BString, Object

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

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

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);
Future future = env.markAsync();
validateConnection(ldapConnection);
ModifyDNRequest modifyRequest = new ModifyDNRequest(currentDN.getValue(), newRDN.getValue(), deleteOldRDN);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncModifyDN(modifyRequest, customAsyncResultListener);
return null;
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
}

public static Object delete(Environment env, BObject ldapClient, BString distinguishedName) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
Future future = env.markAsync();
validateConnection(ldapConnection);
CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future);
ldapConnection.asyncDelete(new DeleteRequest(distinguishedName.getValue()), customAsyncResultListener);
return null;
} catch (Exception e) {
return Utils.createError(e.getMessage(), e);
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
}

public static Object compare(Environment env, BObject ldapClient,
BString distinguishedName, BString attributeName, BString assertionValue) {
Future future = env.markAsync();
try {
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
Future future = env.markAsync();
validateConnection(ldapConnection);
CompareRequest compareRequest = new CompareRequest(distinguishedName.getValue(), attributeName.getValue(),
assertionValue.getValue());
Expand All @@ -165,10 +165,10 @@ public static Object compare(Environment env, BObject ldapClient,
future.complete(Utils.createError(ldapException.getMessage(), ldapException));
}
});
return null;
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
}

public static Object getEntry(BObject ldapClient, BString distinguishedName, BTypedesc typeParam) {
Expand All @@ -191,37 +191,37 @@ public static Object getEntry(BObject ldapClient, BString distinguishedName, BTy

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);
Future future = env.markAsync();
validateConnection(ldapConnection);
SearchResultListener searchResultListener = new CustomSearchResultListener(future, baseDN.getValue());
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDN.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
return null;
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
}

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);
Future future = env.markAsync();
validateConnection(ldapConnection);
SearchResultListener searchResultListener = new CustomSearchEntryListener(future, typeParam,
baseDN.getValue());
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDN.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
return null;
} catch (LDAPException e) {
return Utils.createError(e.getMessage(), e);
future.complete(Utils.createError(e.getMessage(), e));
}
return null;
}

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