Skip to content

Commit

Permalink
lsc-project#176: Fixed bug override globally configured pageSize vari…
Browse files Browse the repository at this point in the history
…able in the middle of the code.
  • Loading branch information
abpai94 committed Jul 26, 2024
1 parent 8ce90e1 commit 1d09c13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 323 deletions.
257 changes: 0 additions & 257 deletions lsc.episode

This file was deleted.

86 changes: 20 additions & 66 deletions src/main/java/org/lsc/jndi/JndiServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ private void initConnection()
}

String pageSizeStr = (String) ctx.getEnvironment().get("java.naming.ldap.pageSize");
if (pageSizeStr != null) {
if (pageSizeStr != null && Integer.parseInt(pageSizeStr) > -1) {
pageSize = Integer.parseInt(pageSizeStr);
List<PagedResultsControl> requestControls = new ArrayList<>();
requestControls.add(new PagedResultsControl(pageSize, Control.CRITICAL));
ctx.setRequestControls(requestControls.toArray(new Control[requestControls.size()]));
} else {
pageSize = -1;
}
Expand Down Expand Up @@ -745,7 +748,7 @@ public List<String> getDnList(final String base, final String filter,
private List<String> doGetDnList(final String base, final String filter,
final int scope) throws NamingException {
NamingEnumeration<SearchResult> ne = null;
List<String> iist = new ArrayList<String>();
List<String> list = new ArrayList<String>();
try {
SearchControls sc = new SearchControls();
sc.setDerefLinkFlag(false);
Expand All @@ -759,14 +762,14 @@ private List<String> doGetDnList(final String base, final String filter,
completedBaseDn = "," + base;
}
while (ne.hasMoreElements()) {
iist.add(((SearchResult) ne.next()).getName() + completedBaseDn);
list.add(((SearchResult) ne.next()).getName() + completedBaseDn);
}
} catch (NamingException e) {
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);
throw e;
}
return iist;
}
return list;
}

/**
Expand Down Expand Up @@ -1137,69 +1140,25 @@ public Map<String, LscDatasets> doGetAttrsList(final String base,
constraints.setReturningObjFlag(true);

try {
boolean requestPagedResults = false;

List<Control> extControls = new ArrayList<Control>();

if (pageSize > 0) {
requestPagedResults = true;
LOGGER.debug("Using pagedResults control for {} entries at a time", pageSize);
}

if (requestPagedResults) {
extControls.add(new PagedResultsControl(pageSize, Control.CRITICAL));
}

if(sortedBy != null) {
extControls.add(new SortControl(sortedBy, Control.CRITICAL));
}

if (extControls.size() > 0) {
ctx.setRequestControls(extControls.toArray(new Control[extControls.size()]));
}

byte[] pagedResultsResponse = null;
do {
NamingEnumeration<SearchResult> results = ctx.search(searchBase, searchFilter, constraints);
NamingEnumeration<SearchResult> results = ctx.search(searchBase, searchFilter, constraints);

if (results != null) {
Map<String, Object> attrsValues = null;
while (results.hasMoreElements()) {
attrsValues = new HashMap<String, Object>();
if (results != null) {
Map<String, Object> attrsValues = null;
while (results.hasMoreElements()) {
attrsValues = new HashMap<String, Object>();

SearchResult ldapResult = (SearchResult) results.next();
SearchResult ldapResult = (SearchResult) results.next();

// get the value for each attribute requested
for (String attributeName : attrsNames) {
Attribute attr = ldapResult.getAttributes().get(attributeName);
if (attr != null && attr.get() != null) {
attrsValues.put(attributeName, attr.get());
}
}

res.put(ldapResult.getNameInNamespace(), new LscDatasets(attrsValues));
}
}

Control[] respCtls = ctx.getResponseControls();
if (respCtls != null) {
for(Control respCtl : respCtls) {
if (requestPagedResults && respCtl instanceof PagedResultsResponseControl) {
pagedResultsResponse = ((PagedResultsResponseControl) respCtl).getCookie();
// get the value for each attribute requested
for (String attributeName : attrsNames) {
Attribute attr = ldapResult.getAttributes().get(attributeName);
if (attr != null && attr.get() != null) {
attrsValues.put(attributeName, attr.get());
}
}
}

if (requestPagedResults && pagedResultsResponse != null) {
ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, pagedResultsResponse, Control.CRITICAL)});
res.put(ldapResult.getNameInNamespace(), new LscDatasets(attrsValues));
}

} while (pagedResultsResponse != null);

// clear requestControls for future use of the JNDI context
if (requestPagedResults) {
ctx.setRequestControls(null);
}
} catch (CommunicationException e) {
// Avoid handling the communication exception as a generic one
Expand All @@ -1213,11 +1172,6 @@ public Map<String, LscDatasets> doGetAttrsList(final String base,
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);

} catch (IOException e) {
// clear requestControls for future use of the JNDI context
ctx.setRequestControls(null);
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);
}
return res;
}
Expand Down

0 comments on commit 1d09c13

Please sign in to comment.