Author: bdaw
Date: 2007-02-14 18:00:54 -0500 (Wed, 14 Feb 2007)
New Revision: 6284
Modified:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
Log:
- make some dummy implementation of offset/limit searches in ldap user module
Modified:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java 2007-02-14
21:49:58 UTC (rev 6283)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java 2007-02-14
23:00:54 UTC (rev 6284)
@@ -37,6 +37,7 @@
import java.util.NoSuchElementException;
import java.util.HashSet;
import java.util.Collections;
+import java.util.LinkedList;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -115,7 +116,7 @@
public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws
IdentityException, IllegalArgumentException
{
- Set uf = new HashSet();
+ List uf = new LinkedList();
try
{
log.debug("findUserFilteredByUserName(): filter = " + filter);
@@ -162,7 +163,29 @@
{
throw new IdentityException("User search failed.", e);
}
- return uf;
+ //this is not very cool. No easy way to do this using JNDI so we apply offset/limit
on all returned results
+ //TODO: make it more efficient and apply sort before createUserInstance
invocation;
+
+ int size = uf.size();
+
+ if (offset == 0 && size <= (offset+limit))
+ {
+ return Tools.toSet(uf.iterator());
+ }
+ else if (offset >= size)
+ {
+ return new HashSet();
+ }
+ else if (offset + limit > size)
+ {
+ limit = size;
+ }
+
+ Collections.sort(uf, new LDAPUserImpl.LDAPUserComparator());
+
+
+
+ return Tools.toSet(uf.subList(offset, offset + limit).iterator());
}
public int getUserCount() throws IdentityException, IllegalArgumentException
Modified: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java 2007-02-14
21:49:58 UTC (rev 6283)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java 2007-02-14
23:00:54 UTC (rev 6284)
@@ -25,7 +25,10 @@
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.IdentityContext;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.User;
+import java.util.Comparator;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
* @version $Revision: 1.1 $
@@ -164,4 +167,20 @@
{
return id;
}
+
+ public static class LDAPRoleComparator implements Comparator
+ {
+
+
+ public int compare(Object o1, Object o2)
+ {
+ Role r1 = (Role)o1;
+ Role r2 = (Role)o2;
+
+ String name1 = r1.getName();
+ String name2 = r2.getName();
+
+ return name1.compareToIgnoreCase(name2);
+ }
+ }
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java 2007-02-14
21:49:58 UTC (rev 6283)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java 2007-02-14
23:00:54 UTC (rev 6284)
@@ -30,6 +30,7 @@
import org.jboss.portal.common.util.Tools;
import java.security.NoSuchAlgorithmException;
+import java.util.Comparator;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -200,4 +201,20 @@
return userModule;
}
+ public static class LDAPUserComparator implements Comparator
+ {
+
+
+ public int compare(Object o1, Object o2)
+ {
+ User u1 = (User)o1;
+ User u2 = (User)o2;
+
+ String name1 = u1.getUserName();
+ String name2 = u2.getUserName();
+
+ return name1.compareToIgnoreCase(name2);
+ }
+ }
+
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2007-02-14
21:49:58 UTC (rev 6283)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2007-02-14
23:00:54 UTC (rev 6284)
@@ -43,6 +43,8 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Collections;
import java.security.NoSuchAlgorithmException;
/**
@@ -223,7 +225,7 @@
public Set findUsers(int offset, int limit) throws IdentityException,
IllegalArgumentException
{
- return findUsersFilteredByUserName("*",0,0);
+ return findUsersFilteredByUserName("*",offset, limit);
}
@@ -236,10 +238,14 @@
throw new IllegalArgumentException("Null user name filter");
}
- log.info("Current implementation of findUsersFilteredByUserName returns all
users and is not \"offset\" and \"limit\" sensitive ");
+ //log.info("Current implementation of findUsersFilteredByUserName returns all
users and is not \"offset\" and \"limit\" sensitive ");
+ if (limit == 0)
+ {
+ throw new IdentityException("Search limit shouldn't be set to
0");
+ }
- Set uf = new HashSet();
+ List uf = new LinkedList();
@@ -267,6 +273,9 @@
String dn = ctx.getNameInNamespace();
uf.add(createUserInstance(res.getAttributes(), dn));
}
+
+
+
}
catch (NoSuchElementException e)
{
@@ -276,8 +285,31 @@
{
throw new IdentityException("User search failed.", e);
}
- return uf;
+ //this is not very cool. No easy way to do this using JNDI so we apply offset/limit
on all returned results
+ //TODO: make it more efficient and apply sort before createUserInstance
invocation;
+
+ int size = uf.size();
+
+ if (offset == 0 && size <= (offset+limit))
+ {
+ return Tools.toSet(uf.iterator());
+ }
+ else if (offset >= size)
+ {
+ return new HashSet();
+ }
+ else if (offset + limit > size)
+ {
+ limit = size;
+ }
+
+ Collections.sort(uf, new LDAPUserImpl.LDAPUserComparator());
+
+
+
+ return Tools.toSet(uf.subList(offset, offset + limit).iterator());
+
}
public int getUserCount() throws IdentityException, IllegalArgumentException