Author: dj
Date: Wed Aug 17 07:44:19 2016
New Revision: 1756587

URL: http://svn.apache.org/viewvc?rev=1756587&view=rev
Log:
OAK-4678 : Backport OAK-4344 and OAK-4005

Modified:
    jackrabbit/oak/branches/1.4/   (props changed)
    
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java
    
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java
    
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
    
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java

Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 17 07:44:19 2016
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738775,1738795,1738833,1738950,1738957,1738963,1739894,1740116,1740625-1740626,1740971,1741032,1741339,1741343,1742520,1742888,1742916,1743097,1743172,1743343,1744265,1744959,1745038,1745197,1745368,1746086,1746117,1746342,1746345,1746696,1746981,1747341-1747342,1747492,1747512,1748505,1748553,1748722,1748870,1749275,1749350,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457,1750462,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751755,1751871,1752273-1752274,1752438,1752447,1752508,1752616,1752659,1752672,1753262,1753331-1753332,1753355,1753444,1754117,1754239,1755157
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738775,1738795,1738833,1738950,1738957,1738963,1739894,1740116,1740625-1740626,1740971,1741032,1741339,1741343,1742520,1742888,1742916,1743097,1743172,1743343,1744265,1744959,1745038,1745197,1745368,1746086,1746117,1746342,1746345,1746696,1746981,1747341-1747342,1747492,1747512,1748505,1748553,1748722,1748870,1749275,1749350,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457,1750462,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751755,1751871,1752198,1752202,1752273-1752274,1752438,1752447,1752508,1752616,1752659,1752672,1753262,1753331-1753332,1753355,1753444,1754117,1754239,1755157
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java?rev=1756587&r1=1756586&r2=1756587&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java
 Wed Aug 17 07:44:19 2016
@@ -21,9 +21,9 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -44,13 +44,7 @@ import org.apache.directory.api.ldap.mod
 import 
org.apache.directory.api.ldap.model.exception.LdapAuthenticationException;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import 
org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchResultDone;
-import org.apache.directory.api.ldap.model.message.SearchResultEntry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.message.*;
 import org.apache.directory.api.ldap.model.message.controls.PagedResults;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.name.Rdn;
@@ -221,7 +215,7 @@ public class LdapIdentityProvider implem
         LdapConnection connection = connect();
         timer.mark("connect");
         try {
-            Entry entry = getEntry(connection, config.getUserConfig(), userId);
+            Entry entry = getEntry(connection, config.getUserConfig(), userId, 
config.getCustomAttributes());
             timer.mark("lookup");
             if (log.isDebugEnabled()) {
                 log.debug("getUser({}) {}", userId, timer.getString());
@@ -246,7 +240,7 @@ public class LdapIdentityProvider implem
         LdapConnection connection = connect();
         timer.mark("connect");
         try {
-            Entry entry = getEntry(connection, config.getGroupConfig(), name);
+            Entry entry = getEntry(connection, config.getGroupConfig(), name, 
config.getCustomAttributes());
             timer.mark("lookup");
             if (log.isDebugEnabled()) {
                 log.debug("getGroup({}) {}", name, timer.getString());
@@ -268,19 +262,10 @@ public class LdapIdentityProvider implem
     @Nonnull
     @Override
     public Iterator<ExternalUser> listUsers() throws ExternalIdentityException 
{
-        DebugTimer timer = new DebugTimer();
-        LdapConnection connection = connect();
-        timer.mark("connect");
         try {
-            final List<Entry> entries = getEntries(connection, 
config.getUserConfig());
-            timer.mark("lookup");
-            if (log.isDebugEnabled()) {
-                log.debug("listUsers() {}", timer.getString());
-            }
+            final Iterator<Entry> iter = 
getEntryIterator(config.getUserConfig());
             return new AbstractLazyIterator<ExternalUser>() {
 
-                private final Iterator<Entry> iter = entries.iterator();
-
                 @Override
                 protected ExternalUser getNext() {
                     while (iter.hasNext()) {
@@ -294,30 +279,19 @@ public class LdapIdentityProvider implem
                 }
             };
         } catch (LdapException e) {
-            throw lookupFailedException(e, timer);
+            throw lookupFailedException(e, null);
         } catch (CursorException e) {
-            throw lookupFailedException(e, timer);
-        } finally {
-            disconnect(connection);
+            throw lookupFailedException(e, null);
         }
     }
 
     @Nonnull
     @Override
     public Iterator<ExternalGroup> listGroups() throws 
ExternalIdentityException {
-        DebugTimer timer = new DebugTimer();
-        LdapConnection connection = connect();
-        timer.mark("connect");
         try {
-            final List<Entry> entries = getEntries(connection, 
config.getGroupConfig());
-            timer.mark("lookup");
-            if (log.isDebugEnabled()) {
-                log.debug("listGroups() {}", timer.getString());
-            }
+            final Iterator<Entry> iter = 
getEntryIterator(config.getGroupConfig());
             return new AbstractLazyIterator<ExternalGroup>() {
 
-                private final Iterator<Entry> iter = entries.iterator();
-
                 @Override
                 protected ExternalGroup getNext() {
                     while (iter.hasNext()) {
@@ -331,11 +305,9 @@ public class LdapIdentityProvider implem
                 }
             };
         } catch (LdapException e) {
-            throw lookupFailedException(e, timer);
+            throw lookupFailedException(e, null);
         } catch (CursorException e) {
-            throw lookupFailedException(e, timer);
-        } finally {
-            disconnect(connection);
+            throw lookupFailedException(e, null);
         }
     }
 
@@ -391,6 +363,7 @@ public class LdapIdentityProvider implem
     }
 
     //-----------------------------------------------------------< internal 
>---
+
     /**
      * Collects the declared (direct) groups of an identity
      * @param ref reference to the identity
@@ -568,14 +541,18 @@ public class LdapIdentityProvider implem
     }
 
     @CheckForNull
-    private Entry getEntry(@Nonnull LdapConnection connection, @Nonnull 
LdapProviderConfig.Identity idConfig, @Nonnull String id)
+    private Entry getEntry(@Nonnull LdapConnection connection, @Nonnull 
LdapProviderConfig.Identity idConfig, @Nonnull String id, @Nonnull String[] 
customAttributes)
             throws CursorException, LdapException {
         String searchFilter = idConfig.getSearchFilter(id);
 
         // Create the SearchRequest object
         SearchRequest req = new SearchRequestImpl();
         req.setScope(SearchScope.SUBTREE);
-        req.addAttributes(SchemaConstants.ALL_USER_ATTRIBUTES);
+        if (customAttributes.length == 0) {
+            req.addAttributes(SchemaConstants.ALL_USER_ATTRIBUTES);
+        } else {
+            req.addAttributes(customAttributes);
+        }
         req.setTimeLimit((int) config.getSearchTimeout());
         req.setBase(new Dn(idConfig.getBaseDN()));
         req.setFilter(searchFilter);
@@ -611,13 +588,9 @@ public class LdapIdentityProvider implem
         return resultEntry;
     }
 
-    /**
-     * currently fetch all entries so that we can close the connection 
afterwards. maybe switch to an iterator approach
-     * later.
-     */
+
     @Nonnull
-    private List<Entry> getEntries(@Nonnull LdapConnection connection, 
@Nonnull LdapProviderConfig.Identity idConfig)
-            throws CursorException, LdapException {
+    private SearchResultIterator getEntryIterator(@Nonnull 
LdapProviderConfig.Identity idConfig) throws LdapException, CursorException, 
ExternalIdentityException {
         StringBuilder filter = new StringBuilder();
         int num = 0;
         for (String objectClass: idConfig.getObjectClasses()) {
@@ -635,37 +608,97 @@ public class LdapIdentityProvider implem
                 ? "(&" + filter + ')'
                 : filter.toString();
 
-        // do paged searches (OAK-2874)
-        int pageSize = 1000;
-        byte[] cookie = null;
+        return new SearchResultIterator(searchFilter, idConfig);
+    }
 
-        List<Entry> result = new LinkedList<Entry>();
-        do {
+    private final class SearchResultIterator implements Iterator<Entry> {
 
-            // Create the SearchRequest object
+        private final String searchFilter;
+        private final LdapProviderConfig.Identity idConfig;
+
+        private byte[] cookie;
+        private List page = Collections.emptyList();
+        private boolean searchComplete;
+        private int pos = -1;
+
+        public SearchResultIterator(
+                @Nonnull String searchFilter,
+                @Nonnull LdapProviderConfig.Identity idConfig) throws 
LdapException, CursorException, ExternalIdentityException {
+            this.searchFilter = searchFilter;
+            this.idConfig = idConfig;
+            findNextEntry();
+        }
+
+        //-------------------------------------------------------< Iterator 
>---
+
+        @Override
+        public boolean hasNext() {
+            return pos >= 0;
+        }
+
+        @Override
+        public Entry next() {
+            if (hasNext()) {
+                try {
+                    Entry entry = (Entry) page.get(pos);
+                    findNextEntry();
+                    return entry;
+                } catch (LdapException e) {
+                    log.error("Error while performing LDAP search", e);
+                } catch (CursorException e) {
+                    log.error("Error while performing LDAP search", e);
+                } catch (ExternalIdentityException e) {
+                    log.error("Error while performing LDAP search", e);
+                }
+            }
+            throw new NoSuchElementException();
+        }
+
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+        //-------------------------------------------------------< internal 
>---
+
+        private SearchRequest createSearchRequest(LdapConnection connection, 
byte[] cookie, @Nonnull String[] userAttributes) throws LdapException {
             SearchRequest req = new SearchRequestImpl();
             req.setScope(SearchScope.SUBTREE);
-            req.addAttributes(SchemaConstants.ALL_USER_ATTRIBUTES);
+            if (userAttributes.length == 0) {
+                req.addAttributes(SchemaConstants.ALL_USER_ATTRIBUTES);
+            } else {
+                req.addAttributes(userAttributes);
+            }
             req.setTimeLimit((int) config.getSearchTimeout());
             req.setBase(new Dn(idConfig.getBaseDN()));
             req.setFilter(searchFilter);
 
             PagedResults pagedSearchControl = new 
PagedResultsDecorator(connection.getCodecService());
-            pagedSearchControl.setSize(pageSize);
+            // do paged searches (OAK-2874)
+            pagedSearchControl.setSize(1000);
             pagedSearchControl.setCookie(cookie);
             req.addControl(pagedSearchControl);
 
-            // Process the request
+            return req;
+        }
+
+        private boolean loadNextPage() throws ExternalIdentityException, 
LdapException, CursorException {
+            if (searchComplete) {
+                return false;
+            }
             SearchCursor searchCursor = null;
+            DebugTimer timer = new DebugTimer();
+            LdapConnection connection = connect();
+            timer.mark("connect");
+            page = new ArrayList<Entry>();
             try {
-                searchCursor = connection.search(req);
+                searchCursor = 
connection.search(createSearchRequest(connection, cookie, 
config.getCustomAttributes()));
                 while (searchCursor.next()) {
                     Response response = searchCursor.get();
 
-                    // process the SearchResultEntry
                     if (response instanceof SearchResultEntry) {
                         Entry resultEntry = ((SearchResultEntry) 
response).getEntry();
-                        result.add(resultEntry);
+                        page.add(resultEntry);
                         if (log.isDebugEnabled()) {
                             log.debug("search below {} with {} found {}", 
idConfig.getBaseDN(), searchFilter, resultEntry.getDn());
                         }
@@ -674,27 +707,38 @@ public class LdapIdentityProvider implem
 
                 SearchResultDone done = searchCursor.getSearchResultDone();
                 cookie = null;
-                if (done.getLdapResult().getResultCode() == 
ResultCodeEnum.UNWILLING_TO_PERFORM) {
-                    break;
-                }
+                if (done.getLdapResult().getResultCode() != 
ResultCodeEnum.UNWILLING_TO_PERFORM) {
 
-                PagedResults ctrl = (PagedResults) 
done.getControl(PagedResults.OID);
-                if (ctrl != null) {
-                    cookie = ctrl.getCookie();
+                    PagedResults ctrl = (PagedResults) 
done.getControl(PagedResults.OID);
+                    if (ctrl != null) {
+                        cookie = ctrl.getCookie();
+                    }
                 }
+                searchComplete = cookie == null;
+                timer.mark("lookup");
 
+                return !page.isEmpty();
             } finally {
                 if (searchCursor != null) {
                     searchCursor.close();
                 }
+                disconnect(connection);
             }
+        }
 
-        } while (cookie != null);
-
-        if (log.isDebugEnabled()) {
-            log.debug("search below {} with {} found {} entries.", 
idConfig.getBaseDN(), searchFilter, result.size());
+        private void findNextEntry() throws LdapException, CursorException, 
ExternalIdentityException {
+            if (pos == -1 && !loadNextPage()) {
+                return;
+            }
+            if (pos + 1 == page.size()) {
+                pos = -1;
+                page = Collections.emptyList();
+                if (!loadNextPage()) {
+                    return;
+                }
+            }
+            pos++;
         }
-        return result;
     }
 
     @Nonnull

Modified: 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java?rev=1756587&r1=1756586&r2=1756587&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java
 Wed Aug 17 07:44:19 2016
@@ -403,6 +403,22 @@ public class LdapProviderConfig {
     public static final String PARAM_GROUP_MEMBER_ATTRIBUTE = 
"group.memberAttribute";
 
     /**
+     * @see Identity#getCustomAttributes()
+     */
+    public static final String[] PARAM_CUSTOM_ATTRIBUTES_DEFAULT = {};
+
+    /**
+     * @see Identity#getCustomAttributes()
+     */
+    @Property(
+            label = "Custom Attributes",
+            description = "Attributes retrieved when looking up LDAP entries. 
Leave empty to retrieve all attributes.",
+            value = {},
+            cardinality = Integer.MAX_VALUE
+    )
+    public static final String PARAM_CUSTOM_ATTRIBUTES = "customattributes";
+
+    /**
      * Defines the configuration of an identity (user or group).
      */
     public class Identity {
@@ -413,6 +429,8 @@ public class LdapProviderConfig {
 
         private String idAttribute;
 
+        private String[] customAttributes = {};
+
         private String extraFilter;
 
         private String filterTemplate;
@@ -575,6 +593,7 @@ public class LdapProviderConfig {
             sb.append("baseDN='").append(baseDN).append('\'');
             sb.append(", 
objectClasses=").append(Arrays.toString(objectClasses));
             sb.append(", idAttribute='").append(idAttribute).append('\'');
+            sb.append(", 
userAttributes='").append(Arrays.toString(customAttributes));
             sb.append(", extraFilter='").append(extraFilter).append('\'');
             sb.append(", 
filterTemplate='").append(filterTemplate).append('\'');
             sb.append(", makeDnPath=").append(makeDnPath);
@@ -666,14 +685,14 @@ public class LdapProviderConfig {
                 .setNoCertCheck(params.getConfigValue(PARAM_NO_CERT_CHECK, 
PARAM_NO_CERT_CHECK_DEFAULT))
                 .setBindDN(params.getConfigValue(PARAM_BIND_DN, 
PARAM_BIND_DN_DEFAULT))
                 .setBindPassword(params.getConfigValue(PARAM_BIND_PASSWORD, 
PARAM_BIND_PASSWORD_DEFAULT))
-                
.setGroupMemberAttribute(params.getConfigValue(PARAM_GROUP_MEMBER_ATTRIBUTE, 
PARAM_GROUP_MEMBER_ATTRIBUTE_DEFAULT));
+                
.setGroupMemberAttribute(params.getConfigValue(PARAM_GROUP_MEMBER_ATTRIBUTE, 
PARAM_GROUP_MEMBER_ATTRIBUTE_DEFAULT))
+                
.setCustomAttributes(params.getConfigValue(PARAM_CUSTOM_ATTRIBUTES, 
PARAM_CUSTOM_ATTRIBUTES_DEFAULT));
 
         ConfigurationParameters.Milliseconds ms = 
ConfigurationParameters.Milliseconds.of(params.getConfigValue(PARAM_SEARCH_TIMEOUT,
 PARAM_SEARCH_TIMEOUT_DEFAULT));
         if (ms != null) {
             cfg.setSearchTimeout(ms.value);
         }
 
-
         cfg.getUserConfig()
                 .setBaseDN(params.getConfigValue(PARAM_USER_BASE_DN, 
PARAM_USER_BASE_DN))
                 .setIdAttribute(params.getConfigValue(PARAM_USER_ID_ATTRIBUTE, 
PARAM_USER_ID_ATTRIBUTE_DEFAULT))
@@ -721,6 +740,8 @@ public class LdapProviderConfig {
 
     private String memberOfFilterTemplate;
 
+    private String[] customAttributes = PARAM_CUSTOM_ATTRIBUTES_DEFAULT;
+
     private final PoolConfig adminPoolConfig = new PoolConfig()
             .setMaxActive(PARAM_ADMIN_POOL_MAX_ACTIVE_DEFAULT);
 
@@ -963,6 +984,29 @@ public class LdapProviderConfig {
         return this;
     }
 
+    /**
+     * Optionally configures an array of attribute names that will be 
retrieved when looking up LDAP entries.
+     * Defaults to the empty array indicating that all attributes will be 
retrieved.
+     *
+     * @return an array of attribute names. The empty array indicates that all 
attributes will be retrieved.
+     */
+    @Nonnull
+    public String[] getCustomAttributes() {
+        return customAttributes;
+    }
+
+    /**
+     * Sets the attribute names to be retrieved when looking up LDAP entries. 
The empty array indicates that all attributes will be retrieved.
+     *
+     * @param customAttributes an array of attribute names
+     * @return the Identity instance
+     */
+    @Nonnull
+    public LdapProviderConfig setCustomAttributes(@Nonnull String[] 
customAttributes) {
+        this.customAttributes = customAttributes;
+        return this;
+    }
+
     /**
      * Returns the LDAP filter that is used when searching for groups where an 
identity is member of.
      * The filter is based on the configuration and has the following format:

Modified: 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java?rev=1756587&r1=1756586&r2=1756587&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
 Wed Aug 17 07:44:19 2016
@@ -56,7 +56,7 @@ public class LargeLdapProviderTest {
 
     protected static String[] TEST_MEMBERS;
 
-    protected static int NUM_USERS = 100;
+    protected static int NUM_USERS = 2222;
 
     protected static int SIZE_LIMIT = 50;
 

Modified: 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java?rev=1756587&r1=1756586&r2=1756587&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.4/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java
 Wed Aug 17 07:44:19 2016
@@ -29,7 +29,6 @@ import java.util.Map;
 import javax.jcr.SimpleCredentials;
 import javax.security.auth.login.LoginException;
 
-import com.google.common.collect.ImmutableMap;
 import org.apache.directory.server.constants.ServerDNConstants;
 import 
org.apache.jackrabbit.oak.security.authentication.ldap.impl.LdapIdentityProvider;
 import 
org.apache.jackrabbit.oak.security.authentication.ldap.impl.LdapProviderConfig;
@@ -44,7 +43,6 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.Ignore;
 
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertNotNull;
@@ -105,13 +103,19 @@ public class LdapProviderTest {
     }
 
     protected LdapIdentityProvider createIDP() {
+        //The attribute "mail" is excluded deliberately
+        return createIDP(new String[] { "objectclass", "uid", "givenname", 
"description", "sn"});
+    }
+
+    protected LdapIdentityProvider createIDP(String[] userProperties) {
         providerConfig = new LdapProviderConfig()
                 .setName(IDP_NAME)
                 .setHostname("127.0.0.1")
                 .setPort(LDAP_SERVER.getPort())
                 .setBindDN(ServerDNConstants.ADMIN_SYSTEM_DN)
                 .setBindPassword(InternalLdapServer.ADMIN_PW)
-                .setGroupMemberAttribute("uniquemember");
+                .setGroupMemberAttribute("uniquemember")
+                .setCustomAttributes(userProperties);
 
         providerConfig.getUserConfig()
                 .setBaseDN(ServerDNConstants.USERS_SYSTEM_DN)
@@ -205,10 +209,11 @@ public class LdapProviderTest {
                         Matchers.equalTo("objectclass"),
                         Matchers.containsInAnyOrder( "inetOrgPerson", "top", 
"person", "organizationalPerson")));
         assertThat(properties, Matchers.<String, Object>hasEntry("uid", 
"hhornblo"));
-        assertThat(properties, Matchers.<String, Object>hasEntry("mail", 
"[email protected]"));
         assertThat(properties, Matchers.<String, Object>hasEntry("givenname", 
"Horatio"));
         assertThat(properties, Matchers.<String, 
Object>hasEntry("description", "Capt. Horatio Hornblower, R.N"));
         assertThat(properties, Matchers.<String, Object>hasEntry("sn", 
"Hornblower"));
+
+        assertThat(properties, Matchers.not(Matchers.<String, 
Object>hasEntry("mail", "[email protected]")));
     }
 
     @Test


Reply via email to