portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r929928 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/ components/jetspeed-securi...
Date Thu, 01 Apr 2010 11:19:13 GMT
Author: ate
Date: Thu Apr  1 11:19:12 2010
New Revision: 929928

URL: http://svn.apache.org/viewvc?rev=929928&view=rev
Log:
JS2-1171: Provide LDAP search paging and callback handling support
See: http://issues.apache.org/jira/browse/JS2-1171

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
  (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
  (with props)
Removed:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/CollectingBindingsCallbackHandler.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultEntityContextMapper.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/EntityContextMapper.java
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java?rev=929928&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
Thu Apr  1 11:19:12 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping;
+
+/**
+ * @author <a href="mailto:ate@douma.nu>Ate Douma</a>
+ * @version $Id$
+ */
+public interface SearchResultCallbackHandler
+{
+    boolean handleSearchResult(Object result, int pageSize, int pageIndex, int index);
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/SearchResultCallbackHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java?rev=929928&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
Thu Apr  1 11:19:12 2010
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.impl;
+
+import org.apache.jetspeed.security.mapping.SearchResultCallbackHandler;
+
+/**
+ * @author <a href="mailto:ate@douma.nu>Ate Douma</a>
+ * @version $Id$
+ */
+public abstract class AbstractSearchResultHandler implements SearchResultCallbackHandler
+{
+    private final int maxCount;
+    private int count;
+    private int size;
+    private boolean aborted;
+        
+    public AbstractSearchResultHandler()
+    {
+        this(Integer.MAX_VALUE);
+    }
+    
+    public AbstractSearchResultHandler(int maxCount)
+    {
+        this.maxCount = maxCount < 1 ? Integer.MAX_VALUE : maxCount;
+    }
+
+    public final boolean handleSearchResult(Object result, int pageSize, int pageIndex, int
index)
+    {
+        count++;
+        if (!aborted)
+        {
+            boolean noExceptions = false;
+            try
+            {
+                processSearchResult(result, pageSize, pageIndex, index);
+                noExceptions = true;
+            }
+            finally
+            {
+                if (!noExceptions)
+                {
+                    aborted = true;
+                }
+            }
+            if (!aborted)
+            {
+                size++;
+                if (count > maxCount)
+                {
+                    aborted = true;
+                }
+            }
+        }
+        return !aborted;
+    }
+    
+    public final boolean isAborted()
+    {
+        return aborted;
+    }
+    
+    protected final void setAborted()
+    {
+        aborted = true;
+    }
+    
+    public final int getMaxCount()
+    {
+        return maxCount;
+    }
+    
+    public final int getCount()
+    {
+        return count;
+    }
+    
+    public final int getSize()
+    {
+        return size;
+    }
+    
+    protected abstract void processSearchResult(Object result, int pageSize, int pageIndex,
int index);
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/AbstractSearchResultHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java?rev=929928&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
Thu Apr  1 11:19:12 2010
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * @author <a href="mailto:ate@douma.nu>Ate Douma</a>
+ * @version $Id$
+ */
+public class CollectingSearchResultHandler<T,R> extends AbstractSearchResultHandler
+{
+    private T singleResult;
+    private List<T> results;
+        
+    public CollectingSearchResultHandler()
+    {
+        super();
+    }
+    
+    public CollectingSearchResultHandler(List<T> results)
+    {
+        super();
+        this.results = results;
+    }
+    
+    public CollectingSearchResultHandler(int maxSize)
+    {
+        super(maxSize);
+    }
+
+    public CollectingSearchResultHandler(int maxSize, List<T> results)
+    {
+        super(maxSize);
+        this.results = results;
+    }
+
+    public T getSingleResult()
+    {
+        return singleResult;
+    }
+    
+    public List<T> getResults()
+    {
+        if (results == null)
+        {
+            results = new ArrayList<T>();
+        }
+        return results;
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void processSearchResult(Object result, int pageSize, int pageIndex, int index)
+    {
+        T mappedResult = mapResult((R)result);
+        if (getMaxCount() == 1)
+        {
+            singleResult = mappedResult;
+        }
+        else if (getCount() <= getMaxCount())
+        {
+            getResults().add(mappedResult);
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected T mapResult(R result)
+    {
+        return (T)result;
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CollectingSearchResultHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java?rev=929928&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
Thu Apr  1 11:19:12 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.impl;
+
+
+/**
+ * @author <a href="mailto:ate@douma.nu>Ate Douma</a>
+ * @version $Id$
+ */
+public class CountingSearchResultHandler extends AbstractSearchResultHandler
+{
+    public CountingSearchResultHandler()
+    {
+        super();
+    }
+    
+    public CountingSearchResultHandler(int maxSize)
+    {
+        super(maxSize);
+    }
+
+    protected void processSearchResult(Object result, int pageSize, int pageIndex, int index)
+    {
+        // do nothing
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/impl/CountingSearchResultHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java?rev=929928&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
Thu Apr  1 11:19:12 2010
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.mapping.ldap.dao.impl;
+
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.jetspeed.security.mapping.SearchResultCallbackHandler;
+import org.springframework.ldap.control.PagedResultsCookie;
+import org.springframework.ldap.control.PagedResultsDirContextProcessor;
+import org.springframework.ldap.core.NameClassPairCallbackHandler;
+import org.springframework.ldap.core.SearchExecutor;
+import org.springframework.ldap.support.LdapUtils;
+
+/**
+ * @author <a href="mailto:ate@douma.nu>Ate Douma</a>
+ * @version $Id$
+ */
+public class PagedSearchExecutor implements SearchExecutor, NameClassPairCallbackHandler
+{
+    private static final NamingEnumeration<SearchResult> noResultsEnumeration = new
NamingEnumeration<SearchResult>()
+    {
+        public void close() throws NamingException {}
+        public boolean hasMore() throws NamingException { return false; }
+        public SearchResult next() throws NamingException { return null; }
+        public boolean hasMoreElements() { return false; }
+        public SearchResult nextElement() { return null; }
+    };
+    
+    private String base;
+    private Name baseName;
+    private String filter;
+    private SearchControls controls;
+    private SearchResultCallbackHandler handler;
+    private int pageSize;
+    
+    protected PagedSearchExecutor(String filter, SearchControls controls, SearchResultCallbackHandler
handler, int pageSize)
+    {
+        this.filter = filter;
+        this.controls = controls;
+        this.handler = handler;
+        this.pageSize = pageSize;
+    }
+    
+    public PagedSearchExecutor(String base, String filter, SearchControls controls, SearchResultCallbackHandler
handler)
+    {
+        this(base, filter, controls, handler, -1);
+    }
+
+    public PagedSearchExecutor(Name baseName, String filter, SearchControls controls, SearchResultCallbackHandler
handler)
+    {
+        this(baseName, filter, controls, handler, -1);
+    }
+    
+    public PagedSearchExecutor(String base, String filter, SearchControls controls, SearchResultCallbackHandler
handler, int pageSize)
+    {
+        this(filter, controls, handler, pageSize);
+        this.base = base;
+    }
+
+    public PagedSearchExecutor(Name baseName, String filter, SearchControls controls, SearchResultCallbackHandler
handler, int pageSize)
+    {
+        this(filter, controls, handler, pageSize);
+        this.baseName = baseName;
+    }
+    
+    public NamingEnumeration<SearchResult> executeSearch(DirContext ctx) throws NamingException
+    {
+        NamingEnumeration<SearchResult> results = null;
+        PagedResultsDirContextProcessor processor = null;
+        boolean noExceptions = false;
+        try
+        {
+            PagedResultsCookie cookie = null;
+            int index = 0;
+            boolean doNext = true;
+            if (pageSize > 0)
+            {
+                do
+                {
+                    processor = new PagedResultsDirContextProcessor(pageSize, cookie);
+                    processor.preProcess(ctx);
+                    results = base != null ? ctx.search(base, filter, controls) : ctx.search(baseName,
filter, controls);
+                    int pageIndex = 0;
+                    while (doNext && results.hasMore())
+                    {
+                        doNext = handler.handleSearchResult(results.next(), pageSize, pageIndex++,
index++);
+                    }                
+                    processor.postProcess(ctx);
+                    cookie = processor.getCookie();
+                }
+                while (doNext && cookie != null && cookie.getCookie() !=
null && cookie.getCookie().length != 0);
+            }
+            else
+            {
+                results = base != null ? ctx.search(base, filter, controls) : ctx.search(baseName,
filter, controls);
+                int pageIndex = 0;
+                while (doNext && results.hasMore())
+                {
+                    doNext = handler.handleSearchResult(results.next(), pageSize, pageIndex++,
index++);
+                }                
+            }
+            noExceptions = true;
+        }
+        finally
+        {
+            if (results != null)
+            {
+                try 
+                {
+                    results.close();
+                }
+                catch (Exception e)
+                {
+                    // Never mind
+                }
+            }
+            if (processor != null)
+            {
+                try
+                {
+                    processor.postProcess(ctx);
+                }
+                catch (NamingException e)
+                {
+                    if (noExceptions)
+                    {   
+                        throw LdapUtils.convertLdapException(e);
+                    }
+                    else
+                    {
+                        // ignore as we already have one
+                    }
+                }
+            }
+        }
+        return noResultsEnumeration;
+    }
+
+    public void handleNameClassPair(NameClassPair nameClassPair)
+    {
+        // ignored
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/PagedSearchExecutor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java?rev=929928&r1=929927&r2=929928&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/SpringLDAPEntityDAO.java
Thu Apr  1 11:19:12 2010
@@ -21,21 +21,19 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.naming.Binding;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.mapping.EntityFactory;
+import org.apache.jetspeed.security.mapping.impl.CollectingSearchResultHandler;
 import org.apache.jetspeed.security.mapping.ldap.EntityFactoryImpl;
-import org.apache.jetspeed.security.mapping.ldap.dao.CollectingBindingsCallbackHandler;
-import org.apache.jetspeed.security.mapping.ldap.dao.EntityContextMapper;
-import org.apache.jetspeed.security.mapping.ldap.dao.DefaultEntityContextMapper;
 import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
 import org.apache.jetspeed.security.mapping.ldap.dao.LDAPEntityDAOConfiguration;
 import org.apache.jetspeed.security.mapping.model.Attribute;
@@ -47,10 +45,8 @@ import org.springframework.ldap.NameNotF
 import org.springframework.ldap.NamingException;
 import org.springframework.ldap.SchemaViolationException;
 import org.springframework.ldap.core.DirContextOperations;
-import org.springframework.ldap.core.DirContextProcessor;
 import org.springframework.ldap.core.DistinguishedName;
 import org.springframework.ldap.core.LdapTemplate;
-import org.springframework.ldap.core.simple.SimpleLdapTemplate;
 import org.springframework.ldap.filter.AndFilter;
 import org.springframework.ldap.filter.EqualsFilter;
 import org.springframework.ldap.filter.Filter;
@@ -62,24 +58,15 @@ import org.springframework.ldap.filter.O
  */
 public class SpringLDAPEntityDAO implements EntityDAO
 {
-    private static final DirContextProcessor nullDirContextProcessor = new DirContextProcessor()
-    {
-        public void postProcess(DirContext ctx) throws javax.naming.NamingException{}
-        public void preProcess(DirContext ctx) throws javax.naming.NamingException{}
-    };
-
     private final LDAPEntityDAOConfiguration configuration;
     private final EntityFactory              entityFactory;
-    private EntityContextMapper              contextMapper;
     private LdapTemplate                     ldapTemplate;
-    private SimpleLdapTemplate               simpleLdapTemplate;
     private String                           defaultSearchFilterStr;
 
     public SpringLDAPEntityDAO(LDAPEntityDAOConfiguration configuration)
     {
         this.configuration = configuration;
         this.entityFactory = new EntityFactoryImpl(configuration);
-        this.contextMapper = new DefaultEntityContextMapper(entityFactory);
         this.defaultSearchFilterStr = createSearchFilter(null);
     }
 
@@ -87,11 +74,6 @@ public class SpringLDAPEntityDAO impleme
     {
         return configuration;
     }
-
-    protected EntityContextMapper getContextMapper()
-    {
-        return contextMapper;
-    }
     
     public String getEntityType()
     {
@@ -103,28 +85,30 @@ public class SpringLDAPEntityDAO impleme
         return entityFactory;
     }
     
-    public void setEntityContextMapper(EntityContextMapper contextMapper)
+    public void setLdapTemplate(LdapTemplate ldapTemplate)
     {
-        this.contextMapper = contextMapper;
-    }
-
-    public void setLdapTemplate(SimpleLdapTemplate simpleLdapTemplate)
-    {
-        this.simpleLdapTemplate = simpleLdapTemplate;
-        this.ldapTemplate = (LdapTemplate)simpleLdapTemplate.getLdapOperations();
+        this.ldapTemplate = ldapTemplate;
     }
 
     public Collection<Entity> getEntities(Filter filter) throws SecurityException
     {
-        String filterStr = createSearchFilter(filter);
-        Collection<Entity> results = null;
+        String sf = createSearchFilter(filter);
+        SearchControls sc = getSearchControls(SearchControls.SUBTREE_SCOPE, true, configuration.getEntityAttributeNames());
+        CollectingSearchResultHandler<Entity,SearchResult> cbh = new CollectingSearchResultHandler<Entity,SearchResult>()
+        {
+            protected Entity mapResult(SearchResult result)
+            {
+                return getEntityFactory().loadEntity(result.getObject());
+            }
+        };
+        PagedSearchExecutor pse = new PagedSearchExecutor(configuration.getSearchDN(), sf,
sc, cbh);
+        
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            results = simpleLdapTemplate.search(configuration.getSearchDN(), filterStr, 
-                                                getSearchControls(SearchControls.SUBTREE_SCOPE,
true,configuration.getEntityAttributeNames()), 
-                                                getContextMapper(), nullDirContextProcessor);
+            ldapTemplate.search(pse,pse); 
+            return cbh.getResults();
         }
         catch (NamingException e)
         {
@@ -134,24 +118,32 @@ public class SpringLDAPEntityDAO impleme
         {
             Thread.currentThread().setContextClassLoader(currentClassLoader);
         }
-        return results;
     }
 
     public Collection<Entity> getEntities(Entity parent, Filter filter) throws SecurityException
     {
-        String filterStr = createSearchFilter(filter);
-        Collection<Entity> results = null;
+        List<Entity> results = new ArrayList<Entity>();
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         DistinguishedName parentDN = getRelativeDN(parent.getInternalId());
         if (configuration.getSearchDN().size() == 0 || parentDN.endsWith(configuration.getSearchDN()))
         {
+            String sf = createSearchFilter(filter);
+            SearchControls sc = getSearchControls(SearchControls.ONELEVEL_SCOPE, true, configuration.getEntityAttributeNames());
+            CollectingSearchResultHandler<Entity,SearchResult> cbh = new CollectingSearchResultHandler<Entity,SearchResult>(results)
+            {
+                protected Entity mapResult(SearchResult result)
+                {
+                    return getEntityFactory().loadEntity(result.getObject());
+                }
+            };
+            PagedSearchExecutor pse = new PagedSearchExecutor(parentDN, sf, sc, cbh);
+            
             try
             {
                 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-                results = simpleLdapTemplate.search(parentDN, filterStr, 
-                                                    getSearchControls(SearchControls.ONELEVEL_SCOPE,
true,configuration.getEntityAttributeNames()), 
-                                                    getContextMapper(), nullDirContextProcessor);
-                            }
+                
+                ldapTemplate.search(pse, pse);
+            }
             catch (NamingException e)
             {
                 throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(),
"getEntities", e.getMessage()), e);
@@ -192,20 +184,28 @@ public class SpringLDAPEntityDAO impleme
 
     public Entity getEntityByInternalId(String internalId) throws SecurityException
     {
-        Entity resultEntity = null;
         DistinguishedName principalDN = getRelativeDN(internalId);
         if (configuration.getSearchDN().size() == 0 || principalDN.endsWith(configuration.getSearchDN()))
         {
+            SearchControls sc = getSearchControls(SearchControls.OBJECT_SCOPE, true, configuration.getEntityAttributeNames());
+            CollectingSearchResultHandler<Entity,SearchResult> cbh = new CollectingSearchResultHandler<Entity,SearchResult>(1)
+            {
+                protected Entity mapResult(SearchResult result)
+                {
+                    return getEntityFactory().loadEntity(result.getObject());
+                }
+            };
+            PagedSearchExecutor pse = new PagedSearchExecutor(principalDN, defaultSearchFilterStr,
sc, cbh);
+            
             ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
             try
             {
                 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-                List<Entity> result = simpleLdapTemplate.search(principalDN, defaultSearchFilterStr,

-                                                                getSearchControls(SearchControls.OBJECT_SCOPE,
true, configuration.getEntityAttributeNames()), 
-                                                                getContextMapper(), nullDirContextProcessor);
-                if (!result.isEmpty())
+                
+                ldapTemplate.search(pse,pse);
+                if (cbh.getCount() == 1)
                 {
-                    resultEntity = result.get(0);
+                    return cbh.getSingleResult();
                 }
             }
             catch (NamingException e)
@@ -217,7 +217,7 @@ public class SpringLDAPEntityDAO impleme
                 Thread.currentThread().setContextClassLoader(currentClassLoader);
             }
         }
-        return resultEntity;
+        return null;
     }
     
     public Collection<Entity> getEntitiesByInternalId(Collection<String> internalIds)
throws SecurityException
@@ -252,14 +252,26 @@ public class SpringLDAPEntityDAO impleme
 
     public String getInternalId(String entityId, boolean required) throws SecurityException
     {
-        String filterStr = createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(),
entityId));
+        String sf = createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(),
entityId));
+        SearchControls sc = getSearchControls(SearchControls.SUBTREE_SCOPE, false, new String[0]);
+        CollectingSearchResultHandler<String,SearchResult> cbh = 
+            new CollectingSearchResultHandler<String,SearchResult>(1)
+        {
+            protected String mapResult(SearchResult result)
+            {
+                return result.getNameInNamespace();
+            }
+        };
+        PagedSearchExecutor pse = new PagedSearchExecutor(configuration.getSearchDN(), sf,
sc, cbh);
+        
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
-            ldapTemplate.search(configuration.getSearchDN(), filterStr, getSearchControls(SearchControls.SUBTREE_SCOPE,
false, new String[0]), handler);
-            if (handler.getList().isEmpty() || handler.getList().size() != 1)
+            
+            ldapTemplate.search(pse,pse);
+            
+            if (cbh.getCount() != 1)
             {
                 if (required)
                 {
@@ -267,7 +279,7 @@ public class SpringLDAPEntityDAO impleme
                 }
                 return null;
             }
-            return ((Binding)handler.getList().get(0)).getNameInNamespace();
+            return cbh.getSingleResult();
         }
         catch (NamingException e)
         {
@@ -293,18 +305,30 @@ public class SpringLDAPEntityDAO impleme
 
     protected DirContextOperations getEntityContextById(String entityId, boolean withAttributes)
throws SecurityException
     {
+        String sf = createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(),
entityId));
+        SearchControls sc = getSearchControls(SearchControls.SUBTREE_SCOPE, true, 
+                                              withAttributes ? configuration.getEntityAttributeNames()
: new String[0]);
+        CollectingSearchResultHandler<DirContextOperations,SearchResult> cbh = 
+            new CollectingSearchResultHandler<DirContextOperations,SearchResult>(1)
+        {
+            protected DirContextOperations mapResult(SearchResult result)
+            {
+                return (DirContextOperations)result.getObject();
+            }
+        };
+        PagedSearchExecutor pse = new PagedSearchExecutor(configuration.getSearchDN(), sf,
sc, cbh);
+        
         ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-            CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
-            ldapTemplate.search(configuration.getSearchDN(), createSearchFilter(new EqualsFilter(configuration.getLdapIdAttribute(),
entityId)),
-                                getSearchControls(SearchControls.SUBTREE_SCOPE, true, withAttributes
? configuration.getEntityAttributeNames() : new String[0]), 
-                                handler);
-            if (!handler.getList().isEmpty() && handler.getList().size() == 1)
+
+            ldapTemplate.search(pse, pse);
+            if (cbh.getCount() == 1)
             {
-                return (DirContextOperations)((Binding)handler.getList().get(0)).getObject();
+                return cbh.getSingleResult();
             }
+            return null;
         }
         catch (NamingException e)
         {
@@ -314,7 +338,6 @@ public class SpringLDAPEntityDAO impleme
         {
             Thread.currentThread().setContextClassLoader(currentClassLoader);
         }
-        return null;
     }
 
     protected DirContextOperations getEntityContextByInternalId(String internalId, boolean
withAttributes) throws SecurityException
@@ -322,17 +345,28 @@ public class SpringLDAPEntityDAO impleme
         DistinguishedName principalDN = getRelativeDN(internalId);
         if (configuration.getSearchDN().size() == 0 || principalDN.endsWith(configuration.getSearchDN()))
         {
+            String sf = createSearchFilter(null);
+            SearchControls sc = getSearchControls(SearchControls.OBJECT_SCOPE, true, 
+                                                  withAttributes ? configuration.getEntityAttributeNames()
: new String[0]);
+            CollectingSearchResultHandler<DirContextOperations,SearchResult> cbh =

+                new CollectingSearchResultHandler<DirContextOperations,SearchResult>(1)
+            {
+                protected DirContextOperations mapResult(SearchResult result)
+                {
+                    return (DirContextOperations)result.getObject();
+                }
+            };
+            PagedSearchExecutor pse = new PagedSearchExecutor(principalDN, sf, sc, cbh);

+            
             ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
             try
             {
                 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-                CollectingBindingsCallbackHandler handler = new CollectingBindingsCallbackHandler();
-                ldapTemplate.search(principalDN, createSearchFilter(null),
-                                    getSearchControls(SearchControls.OBJECT_SCOPE, true,
withAttributes ? configuration.getEntityAttributeNames() : new String[0]), 
-                                    handler);
-                if (!handler.getList().isEmpty())
+                
+                ldapTemplate.search(pse,pse);
+                if (cbh.getCount() == 1)
                 {
-                    return (DirContextOperations)((Binding)handler.getList().get(0)).getObject();
+                    return cbh.getSingleResult();
                 }
             }
             catch (NamingException e)

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java?rev=929928&r1=929927&r2=929928&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/mapping/ldap/AbstractLDAPTest.java
Thu Apr  1 11:19:12 2010
@@ -25,8 +25,10 @@ import org.apache.jetspeed.security.mapp
 import org.apache.jetspeed.test.JetspeedTestCase;
 import org.springframework.core.io.Resource;
 import org.springframework.ldap.core.ContextSource;
-import org.springframework.ldap.core.simple.SimpleLdapTemplate;
+import org.springframework.ldap.core.LdapTemplate;
 import org.springframework.ldap.core.support.LdapContextSource;
+import org.springframework.ldap.pool.factory.MutablePoolingContextSource;
+import org.springframework.ldap.pool.factory.PoolingContextSource;
 
 /**
  * @author <a href="mailto:ddam@apache.org">Dennis Dam</a>
@@ -49,7 +51,7 @@ public abstract class AbstractLDAPTest e
 
     public static final AttributeDefImpl UNIQUEMEMBER_ATTR_DEF = new AttributeDefImpl("uniqueMember",true).cfgRequired(true).cfgRequiredDefaultValue("uid=someDummyValue");
 
-    protected SimpleLdapTemplate ldapTemplate;
+    protected LdapTemplate ldapTemplate;
 
     protected ContextSource contextSource;
 
@@ -90,8 +92,12 @@ public abstract class AbstractLDAPTest e
         contextSource.setBase(baseDN);
         contextSource.setUserDn("uid=admin,ou=system");
         contextSource.setPassword("secret");
+        contextSource.setPooled(false);
         contextSource.afterPropertiesSet();
-        ldapTemplate = new SimpleLdapTemplate(contextSource);
+        PoolingContextSource pcs = new MutablePoolingContextSource();
+        pcs.setContextSource(contextSource);
+        
+        ldapTemplate = new LdapTemplate(pcs);
 
         if (!ldapService.isRunning()) return;
         

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml?rev=929928&r1=929927&r2=929928&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-ldap.xml
Thu Apr  1 11:19:12 2010
@@ -278,7 +278,7 @@
     <meta key="j2:cat" value="ldapSecurity" />
     <constructor-arg ref="UserDaoConfiguration"/>
     <property name="ldapTemplate">
-      <bean class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
+      <bean class="org.springframework.ldap.core.LdapTemplate">
         <constructor-arg ref="LdapSpringContext" />
       </bean>
     </property>
@@ -330,7 +330,7 @@
     <meta key="j2:cat" value="ldapSecurity" />
     <constructor-arg ref="RoleDaoConfiguration"/>
     <property name="ldapTemplate">
-      <bean class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
+      <bean class="org.springframework.ldap.core.LdapTemplate">
         <constructor-arg ref="LdapSpringContext" />
       </bean>
     </property>
@@ -340,7 +340,7 @@
     <meta key="j2:cat" value="ldapSecurity" />
     <constructor-arg ref="GroupDaoConfiguration"/>
     <property name="ldapTemplate">
-      <bean class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
+      <bean class="org.springframework.ldap.core.LdapTemplate">
         <constructor-arg ref="LdapSpringContext" />
       </bean>
     </property>
@@ -357,7 +357,7 @@
     </property>
   </bean>
 
-  <bean id="LdapSpringContext" class="org.springframework.ldap.pool.factory.PoolingContextSource">
+  <bean id="LdapSpringContext" class="org.springframework.ldap.pool.factory.MutablePoolingContextSource">
     <meta key="j2:cat" value="ldapSecurity" />
     <property name="contextSource">
       <bean class="org.springframework.ldap.core.support.LdapContextSource">



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message