Author: trang_vu
Date: 2011-08-17 03:00:26 -0400 (Wed, 17 Aug 2011)
New Revision: 4763
Modified:
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java
Log:
COR-34: Improve performance of LDAP organization service
Fix description
* Cache implementation.
Modified:
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -218,6 +218,7 @@
}
catch (CommunicationException e1)
{
+ release(ctx);
// create new LDAP context
ctx = getLdapContext(true);
// try repeat operation where communication error occurs
@@ -225,6 +226,7 @@
}
catch (ServiceUnavailableException e2)
{
+ release(ctx);
// do the same as for CommunicationException
ctx = getLdapContext(true);
//
@@ -285,6 +287,7 @@
}
catch (CommunicationException e1)
{
+ release(ctx);
// create new LDAP context
ctx = getLdapContext(true);
// try repeat operation where communication error occurs
@@ -292,6 +295,7 @@
}
catch (ServiceUnavailableException e2)
{
+ release(ctx);
// do the same as for CommunicationException
ctx = getLdapContext(true);
//
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -48,12 +48,14 @@
* items
* @param ldapService {@link LDAPService}
* @param ad See {@link ADSearchBySID}
+ * @param cacheHandler
+ * The Cache Handler
* @throws Exception if any errors occurs
*/
- public ADGroupDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService,
ADSearchBySID ad)
- throws Exception
+ public ADGroupDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService,
ADSearchBySID ad,
+ CacheHandler cacheHandler) throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
adSearch = ad;
}
@@ -126,10 +128,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -22,6 +22,7 @@
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.Membership;
import org.exoplatform.services.organization.impl.MembershipImpl;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import java.util.ArrayList;
import java.util.Collection;
@@ -48,12 +49,14 @@
* items
* @param ldapService {@link LDAPService}
* @param ad See {@link ADSearchBySID}
+ * @param cacheHandler
+ * The Cache Handler
* @throws Exception if any errors occurs
*/
- public ADMembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService, ADSearchBySID ad)
- throws Exception
+ public ADMembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService, ADSearchBySID ad,
+ CacheHandler cacheHandler) throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
adSearch = ad;
}
@@ -64,6 +67,13 @@
@Override
public Membership findMembershipByUserGroupAndType(String userName, String groupId,
String type) throws Exception
{
+ MembershipImpl membership =
+ (MembershipImpl)cacheHandler.get(cacheHandler.getMembershipKey(userName,
groupId, type), CacheType.MEMBERSHIP);
+ if (membership != null)
+ {
+ return membership;
+ }
+
LdapContext ctx = ldapService.getLdapContext(true);
String groupDN = getGroupDNFromGroupId(groupId);
try
@@ -74,15 +84,16 @@
{
Collection memberships = findMemberships(ctx, userName, groupDN, type);
if (memberships.size() > 0)
- return (MembershipImpl)memberships.iterator().next();
+ {
+ membership = (MembershipImpl)memberships.iterator().next();
+ cacheHandler.put(cacheHandler.getMembershipKey(membership), membership,
CacheType.MEMBERSHIP);
+ return membership;
+ }
return null;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -110,10 +121,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -142,10 +150,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -184,7 +189,7 @@
results = ctx.search(userDN, filter, constraints);
while (results.hasMore())
{
- SearchResult sr = (SearchResult)results.next();
+ SearchResult sr = results.next();
Attributes attrs = sr.getAttributes();
Attribute attr = attrs.get("tokenGroups");
for (int x = 0; x < attr.size(); x++)
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -20,6 +20,7 @@
import org.exoplatform.services.ldap.LDAPService;
import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import javax.naming.Context;
import javax.naming.NamingException;
@@ -61,11 +62,14 @@
/**
* @param ldapAttrMapping {@link LDAPAttributeMapping}
* @param ldapService {@link LDAPService}
+ * @param cservice
+ * The Cache Handler
* @throws Exception if any errors occurs
*/
- public ADUserDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService)
throws Exception
+ public ADUserDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService,
CacheHandler cacheHandler)
+ throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
LDAPUserPageList.SEARCH_CONTROL = Control.CRITICAL;
}
@@ -93,14 +97,13 @@
ctx.createSubcontext(userDN, attrs);
if (broadcast)
postSave(user, true);
+
+ cacheHandler.put(user.getUserName(), user, CacheType.USER);
break;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -118,7 +121,7 @@
* {@inheritDoc}
*/
@Override
- void saveUserPassword(User user, String userDN) throws Exception
+ protected void saveUserPassword(User user, String userDN) throws Exception
{
Object v =
ldapService.getLdapContext().getEnvironment().get(Context.SECURITY_PROTOCOL);
if (v == null)
@@ -147,10 +150,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -24,6 +24,7 @@
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.User;
import org.exoplatform.services.organization.impl.GroupImpl;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -82,14 +83,21 @@
private static int maxConnectionError = -1;
/**
+ * The Cache Handler.
+ */
+ protected final CacheHandler cacheHandler;
+
+ /**
* @param ldapAttrMapping {@link LDAPAttributeMapping}
* @param ldapService {@link LDAPService}
* @throws Exception if any error occurs
*/
- public BaseDAO(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService) throws
Exception
+ public BaseDAO(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService,
CacheHandler cacheHandler)
+ throws Exception
{
this.ldapAttrMapping = ldapAttrMapping;
this.ldapService = ldapService;
+ this.cacheHandler = cacheHandler;
initializeNameParser();
}
@@ -141,6 +149,26 @@
}
/**
+ * Construct object name from {@link Group} id.
+ *
+ * @param groupDN group DN
+ * @return object name
+ */
+ protected String getGroupIdFromGroupDN(String groupDN) throws NamingException
+ {
+ // extract group's id, group's name and parent's group from DN
+ StringBuffer buffer = new StringBuffer();
+ String[] baseParts = explodeDN(ldapAttrMapping.groupsURL, true);
+ String[] membershipParts = explodeDN(groupDN, true);
+ for (int x = (membershipParts.length - baseParts.length - 1); x > -1; x--)
+ {
+ buffer.append("/" + membershipParts[x]);
+ }
+
+ return buffer.toString();
+ }
+
+ /**
* Get collection of {@link Attribute} with specified name from
* {@link Attributes}.
*
@@ -204,6 +232,20 @@
*/
protected Group getGroupFromMembershipDN(LdapContext ctx, String membershipDN) throws
NamingException
{
+ String groupDN = getGroupDNFromMembershipDN(membershipDN);
+ Group group = getGroupByDN(ctx, groupDN);
+ return group;
+ }
+
+ /**
+ * Retrieve Group DN from membership DN.
+ *
+ * @param membershipDN membership Distinguished Name
+ * @return GroupDN
+ * @throws NamingException if any naming errors occurs
+ */
+ protected String getGroupDNFromMembershipDN(String membershipDN) throws
NamingException
+ {
String[] membershipParts = explodeDN(membershipDN, false);
StringBuffer buffer = new StringBuffer();
for (int x = 1; x < membershipParts.length; x++)
@@ -217,8 +259,7 @@
buffer.append(membershipParts[x] + ",");
}
}
- Group group = getGroupByDN(ctx, buffer.toString());
- return group;
+ return buffer.toString();
}
/**
@@ -245,12 +286,7 @@
}
catch (NamingException e)
{
- // check is allowed to try one more time
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- // not connection exception or error occurs more than
MAX_CONNECTION_ERROR
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -261,6 +297,30 @@
}
/**
+ * Re-load the ctx if the context allows it
+ * @param ctx the previous context
+ * @param err the total of errors that have already occurred
+ * @param e the last exception that occurs
+ * @return the new context if the context reload is allowed throws an exception
otherwise
+ * @throws NamingException if context could not be reloaded
+ */
+ protected LdapContext reloadCtx(LdapContext ctx, int err, NamingException e) throws
NamingException
+ {
+ // check is allowed to try one more time
+ if (isConnectionError(e) && err < getMaxConnectionError())
+ {
+ // release the previous context
+ ldapService.release(ctx);
+ // reload the context
+ ctx = ldapService.getLdapContext(true);
+ }
+ else
+ // not connection exception or error occurs more than MAX_CONNECTION_ERROR
+ throw e;
+ return ctx;
+ }
+
+ /**
* Get Group what reflected to object with specified Distinguished Name.
*
* @param ctx {@link LdapContext}
@@ -270,6 +330,26 @@
*/
protected Group getGroupByDN(LdapContext ctx, String groupDN) throws NamingException
{
+ try
+ {
+ Attributes attrs = ctx.getAttributes(groupDN);
+ return buildGroup(groupDN, attrs);
+ }
+ catch (NameNotFoundException e)
+ {
+ if (LOG.isDebugEnabled())
+ e.printStackTrace();
+ // Object with specified Distinguished Name not found. Null will be
+ // returned. This result we regard as successful, just nothing found.
+ return null;
+ }
+ }
+
+ protected Group buildGroup(String groupDN, Attributes attrs) throws NamingException
+ {
+ GroupImpl group = new GroupImpl();
+
+ // extract group's id, group's name and parent's group from DN
StringBuffer idBuffer = new StringBuffer();
String parentId = null;
String[] baseParts = explodeDN(ldapAttrMapping.groupsURL, true);
@@ -280,25 +360,17 @@
if (x == 1)
parentId = idBuffer.toString();
}
- try
+
+ group.setGroupName(membershipParts[0]);
+ group.setId(idBuffer.toString());
+ if (attrs != null)
{
- Attributes attrs = ctx.getAttributes(groupDN);
- GroupImpl group = new GroupImpl();
- group.setGroupName(membershipParts[0]);
- group.setId(idBuffer.toString());
group.setDescription(ldapAttrMapping.getAttributeValueAsString(attrs,
ldapAttrMapping.ldapDescriptionAttr));
group.setLabel(ldapAttrMapping.getAttributeValueAsString(attrs,
ldapAttrMapping.groupLabelAttr));
- group.setParentId(parentId);
- return group;
}
- catch (NameNotFoundException e)
- {
- if (LOG.isDebugEnabled())
- e.printStackTrace();
- // Object with specified Distinguished Name not found. Null will be
- // returned. This result we regard as successful, just nothing found.
- return null;
- }
+ group.setParentId(parentId);
+
+ return group;
}
/**
@@ -352,10 +424,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -381,9 +450,7 @@
answer = findUser(ctx, username, true);
while (answer.hasMoreElements())
{
- String userDN = answer.next().getNameInNamespace();
- Attributes attrs = ctx.getAttributes(userDN);
- return ldapAttrMapping.attributesToUser(attrs);
+ return ldapAttrMapping.attributesToUser(answer.next().getAttributes());
}
return null;
}
@@ -465,10 +532,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -525,6 +589,10 @@
removeAllSubtree(ctx, sr.getNameInNamespace());
}
ctx.destroySubcontext(dn);
+
+ String groupId = buildGroup(dn, null).getId();
+ cacheHandler.remove(groupId, CacheType.GROUP);
+ cacheHandler.remove(CacheHandler.GROUP_PREFIX + groupId, CacheType.MEMBERSHIP);
}
finally
{
@@ -649,14 +717,7 @@
}
catch (NamingException e)
{
- // check is allowed to try one more time
- if (isConnectionError(e) && err < getMaxConnectionError())
- // update LdapContext
- ctx = ldapService.getLdapContext(true);
- else
- // not connection exception or error occurs more than
- // MAX_CONNECTION_ERROR times
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -26,11 +26,14 @@
import org.exoplatform.services.organization.GroupEventListenerHandler;
import org.exoplatform.services.organization.GroupHandler;
import org.exoplatform.services.organization.impl.GroupImpl;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.naming.CompositeName;
import javax.naming.Name;
@@ -69,11 +72,14 @@
* @param ldapAttrMapping mapping LDAP attributes to eXo organization service
* items (users, groups, etc)
* @param ldapService {@link LDAPService}
+ * @param cacheHandler
+ * The Cache Handler
* @throws Exception if any errors occurs
*/
- public GroupDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService)
throws Exception
+ public GroupDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService,
CacheHandler cacheHandler)
+ throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
this.listeners = new ArrayList<GroupEventListener>(3);
}
@@ -136,14 +142,13 @@
ctx.createSubcontext(groupDN, ldapAttrMapping.groupToAttributes(child));
if (broadcast)
postSave(group, true);
+
+ cacheHandler.put(child.getId(), group, CacheType.GROUP);
return;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
@@ -192,14 +197,13 @@
ctx.modifyAttributes(groupDN, mods);
if (broadcast)
postSave(group, true);
+
+ cacheHandler.put(group.getId(), group, CacheType.GROUP);
return;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -255,15 +259,13 @@
removeAllSubtree(ctx, groupDN);
if (broadcast)
postDelete(group);
+
return group;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
@@ -323,10 +325,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
@@ -348,6 +347,13 @@
{
if (groupId == null)
return null;
+
+ Group group = (Group)cacheHandler.get(groupId, CacheType.GROUP);
+ if (group != null)
+ {
+ return group;
+ }
+
String parentId = null;
StringBuffer buffer = new StringBuffer();
String[] groupIdParts = groupId.split("/");
@@ -366,17 +372,19 @@
try
{
Attributes attrs = ctx.getAttributes(groupDN);
- Group group = ldapAttrMapping.attributesToGroup(attrs);
+ group = ldapAttrMapping.attributesToGroup(attrs);
((GroupImpl)group).setId(groupId);
((GroupImpl)group).setParentId(parentId);
+
+ if (group != null)
+ {
+ cacheHandler.put(groupId, group, CacheType.GROUP);
+ }
return group;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -402,6 +410,13 @@
{
if (groupId == null)
return null;
+
+ Group group = (Group)cacheHandler.get(groupId, CacheType.GROUP);
+ if (group != null)
+ {
+ return group;
+ }
+
String parentId = null;
StringBuffer buffer = new StringBuffer();
String[] groupIdParts = groupId.split("/");
@@ -415,9 +430,14 @@
try
{
Attributes attrs = ctx.getAttributes(groupDN);
- Group group = ldapAttrMapping.attributesToGroup(attrs);
+ group = ldapAttrMapping.attributesToGroup(attrs);
((GroupImpl)group).setId(groupId);
((GroupImpl)group).setParentId(parentId);
+
+ if (group != null)
+ {
+ cacheHandler.put(groupId, group, CacheType.GROUP);
+ }
return group;
}
catch (NameNotFoundException e)
@@ -473,7 +493,7 @@
{
Name entryName = parser.parse(name.get(0));
String groupDN = entryName + "," +
ldapAttrMapping.groupsURL;
- Group group = this.getGroupByDN(ctx, groupDN);
+ Group group = this.buildGroup(groupDN, sr.getAttributes());
if (group != null)
addGroup(groups, group);
}
@@ -482,10 +502,7 @@
}
catch (NamingException e2)
{
- if (isConnectionError(e2) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e2;
+ ctx = reloadCtx(ctx, err, e2);
}
finally
{
@@ -555,7 +572,7 @@
{
Name entryName = parser.parse(name.get(0));
String groupDN = entryName + "," + searchBase;
- Group group = this.getGroupByDN(ctx, groupDN);
+ Group group = this.buildGroup(groupDN, sr.getAttributes());
if (group != null)
addGroup(groups, group);
}
@@ -564,10 +581,7 @@
}
catch (NamingException e2)
{
- if (isConnectionError(e2) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e2;
+ ctx = reloadCtx(ctx, err, e2);
}
finally
{
@@ -613,21 +627,24 @@
results = ctx.search(ldapAttrMapping.groupsURL, filter, constraints);
// add groups for memberships matching user
- // int total = 0;
+ Set<String> uniqueGroupsDN = new HashSet<String>();
while (results != null && results.hasMore())
{
SearchResult sr = results.next();
- // total++;
NameParser parser = ctx.getNameParser("");
CompositeName name = new CompositeName(sr.getName());
if (name.size() < 1)
break;
Name entryName = parser.parse(name.get(0));
String membershipDN = entryName + "," +
ldapAttrMapping.groupsURL;
- Group group = this.getGroupFromMembershipDN(ctx, membershipDN);
- if (group != null)
- addGroup(groups, group);
+ uniqueGroupsDN.add(this.getGroupDNFromMembershipDN(membershipDN));
}
+ for(String groupDN : uniqueGroupsDN)
+ {
+ Group group = this.getGroupByDN(ctx, groupDN);
+ if (group != null)
+ addGroup(groups, group);
+ }
if (LOG.isDebugEnabled())
{
LOG.debug("Retrieved " + groups.size() + " groups from
ldap for user " + userName);
@@ -636,10 +653,7 @@
}
catch (NamingException e2)
{
- if (isConnectionError(e2) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e2;
+ ctx = reloadCtx(ctx, err, e2);
}
finally
{
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -141,7 +141,10 @@
catch (NamingException e)
{
if (BaseDAO.isConnectionError(e) && err <
BaseDAO.getMaxConnectionError())
+ {
+ ldapService.release(ctx);
ctx = ldapService.getLdapContext(true);
+ }
else
throw e;
}
@@ -197,7 +200,10 @@
catch (NamingException e)
{
if (BaseDAO.isConnectionError(e) && err < 1)
+ {
+ ldapService.release(ctx);
ctx = ldapService.getLdapContext(true);
+ }
else
throw e;
}
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -84,7 +84,10 @@
catch (NamingException e)
{
if (BaseDAO.isConnectionError(e) && err <
BaseDAO.getMaxConnectionError())
+ {
+ ldapService.release(ctx);
ctx = ldapService.getLdapContext(true);
+ }
else
throw e;
}
@@ -113,7 +116,10 @@
catch (NamingException e)
{
if (BaseDAO.isConnectionError(e) && err <
BaseDAO.getMaxConnectionError())
+ {
+ ldapService.release(ctx);
ctx = ldapService.getLdapContext(true);
+ }
else
throw e;
}
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -29,6 +29,7 @@
import org.exoplatform.services.organization.MembershipType;
import org.exoplatform.services.organization.User;
import org.exoplatform.services.organization.impl.MembershipImpl;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import java.util.ArrayList;
import java.util.Collection;
@@ -70,12 +71,15 @@
* mapping LDAP attributes to eXo organization service items (users, groups,
etc)
* @param ldapService
* {@link LDAPService}
+ * @param cacheHandler
+ * The Cache Handler
* @throws Exception
* if any errors occurs
*/
- public MembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService) throws Exception
+ public MembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService, CacheHandler cacheHandler)
+ throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
this.listeners = new ArrayList<MembershipEventListener>(3);
}
@@ -131,6 +135,8 @@
ctx.createSubcontext(membershipDN,
ldapAttrMapping.membershipToAttributes(m, userDN));
if (broadcast)
postSave(m, true);
+
+ cacheHandler.put(cacheHandler.getMembershipKey(m), m,
CacheType.MEMBERSHIP);
return;
}
// if contains membership
@@ -148,15 +154,14 @@
ctx.modifyAttributes(membershipDN, mods);
if (broadcast)
postSave(m, true);
+
+ cacheHandler.put(cacheHandler.getMembershipKey(m), m,
CacheType.MEMBERSHIP);
return;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -245,23 +250,25 @@
ctx.modifyAttributes(membershipDN, mods);
if (broadcast)
postSave(m, true);
+
+ cacheHandler.put(cacheHandler.getMembershipKey(m), m,
CacheType.MEMBERSHIP);
}
else
{
if (broadcast)
preDelete(m);
ctx.destroySubcontext(membershipDN);
+
if (broadcast)
postDelete(m);
+
+ cacheHandler.remove(cacheHandler.getMembershipKey(m),
CacheType.MEMBERSHIP);
}
return m;
}
catch (NamingException e1)
{
- if (isConnectionError(e1) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e1;
+ ctx = reloadCtx(ctx, err, e1);
}
}
}
@@ -318,9 +325,13 @@
new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new
BasicAttribute(
ldapAttrMapping.membershipTypeMemberValue, userDN));
ctx.modifyAttributes(membershipDN, mods);
+ cacheHandler.put(cacheHandler.getMembershipKey(membership),
membership, CacheType.MEMBERSHIP);
}
else
+ {
ctx.destroySubcontext(membershipDN);
+ cacheHandler.remove(cacheHandler.getMembershipKey(membership),
CacheType.MEMBERSHIP);
+ }
}
catch (Exception e1)
{
@@ -331,10 +342,7 @@
}
catch (NamingException e2)
{
- if (isConnectionError(e2) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e2;
+ ctx = reloadCtx(ctx, err, e2);
}
finally
{
@@ -365,12 +373,19 @@
*/
public Membership findMembershipByUserGroupAndType(String userName, String groupId,
String type) throws Exception
{
+ MembershipImpl membership =
+ (MembershipImpl)cacheHandler.get(cacheHandler.getMembershipKey(userName,
groupId, type), CacheType.MEMBERSHIP);
+ if (membership != null)
+ {
+ return membership;
+ }
+
LdapContext ctx = ldapService.getLdapContext();
try
{
for (int err = 0;; err++)
{
- Membership membership = null;
+ membership = null;
try
{
String userDN = getDNFromUsername(ctx, userName);
@@ -395,14 +410,15 @@
membership = createMembershipObject(userName, groupId, type);
}
+ if (membership != null)
+ {
+ cacheHandler.put(cacheHandler.getMembershipKey(membership), membership,
CacheType.MEMBERSHIP);
+ }
return membership;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -457,10 +473,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
@@ -538,9 +551,9 @@
{
SearchResult sr = results.next();
String membershipDN = sr.getNameInNamespace();
- Group group = getGroupFromMembershipDN(ctx, membershipDN);
+ String groupId =
getGroupIdFromGroupDN(getGroupDNFromMembershipDN(membershipDN));
String type = explodeDN(membershipDN, true)[0];
- Membership membership = createMembershipObject(userName, group.getId(),
type);
+ Membership membership = createMembershipObject(userName, groupId,
type);
memberships.add(membership);
}
if (LOG.isDebugEnabled())
@@ -551,10 +564,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
@@ -619,10 +629,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -24,6 +24,7 @@
import org.exoplatform.services.organization.MembershipType;
import org.exoplatform.services.organization.MembershipTypeHandler;
import org.exoplatform.services.organization.impl.MembershipTypeImpl;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import java.util.ArrayList;
import java.util.Collection;
@@ -56,11 +57,14 @@
* @param ldapAttrMapping mapping LDAP attributes to eXo organization service
* items (users, groups, etc)
* @param ldapService {@link LDAPService}
+ * @param cacheHandler
+ * The Cache Handler
* @throws Exception if any errors occurs
*/
- public MembershipTypeDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService) throws Exception
+ public MembershipTypeDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService, CacheHandler cacheHandler)
+ throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
}
/**
@@ -95,15 +99,14 @@
mt.setCreatedDate(now);
mt.setModifiedDate(now);
ctx.createSubcontext(membershipTypeDN,
ldapAttrMapping.membershipTypeToAttributes(mt));
+
+ cacheHandler.put(mt.getName(), mt, CacheType.MEMBERSHIPTYPE);
}
return mt;
}
catch (NamingException e1)
{
- if (isConnectionError(e1) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e1;
+ ctx = reloadCtx(ctx, err, e1);
}
}
}
@@ -146,14 +149,13 @@
ldapAttrMapping.ldapDescriptionAttr, mt.getDescription()));
}
ctx.modifyAttributes(membershipTypeDN, mods);
+
+ cacheHandler.put(mt.getName(), mt, CacheType.MEMBERSHIPTYPE);
return mt;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -181,14 +183,13 @@
MembershipType m = ldapAttrMapping.attributesToMembershipType(attrs);
removeMembership(ctx, name);
ctx.destroySubcontext(membershipTypeDN);
+
+ cacheHandler.remove(name, CacheType.MEMBERSHIPTYPE);
return m;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -209,6 +210,12 @@
*/
public MembershipType findMembershipType(String name) throws Exception
{
+ MembershipType mt = (MembershipType)cacheHandler.get(name,
CacheType.MEMBERSHIPTYPE);
+ if (mt != null)
+ {
+ return mt;
+ }
+
String membershipTypeDN =
ldapAttrMapping.membershipTypeNameAttr + "=" + name + "," +
ldapAttrMapping.membershipTypeURL;
LdapContext ctx = ldapService.getLdapContext();
@@ -219,14 +226,16 @@
try
{
Attributes attrs = ctx.getAttributes(membershipTypeDN);
- return ldapAttrMapping.attributesToMembershipType(attrs);
+ mt = ldapAttrMapping.attributesToMembershipType(attrs);
+ if (mt != null)
+ {
+ cacheHandler.put(name, mt, CacheType.MEMBERSHIPTYPE);
+ }
+ return mt;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -274,10 +283,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
finally
{
@@ -307,6 +313,8 @@
{
SearchResult sr = results.next();
ctx.destroySubcontext(sr.getNameInNamespace());
+
+ cacheHandler.remove(CacheHandler.MEMBERSHIPTYPE_PREFIX + name,
CacheType.MEMBERSHIP);
}
}
finally
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -47,25 +47,27 @@
LDAPAttributeMapping ldapAttrMapping =
(LDAPAttributeMapping)params.getObjectParam("ldap.attribute.mapping").getObject();
+ CacheHandler cacheHandler = new CacheHandler(cservice);
+
if (ldapService.getServerType() == LDAPService.ACTIVE_DIRECTORY_SERVER)
{
- userDAO_ = new ADUserDAOImpl(ldapAttrMapping, ldapService);
+ userDAO_ = new ADUserDAOImpl(ldapAttrMapping, ldapService, cacheHandler);
// ADSearchBySID adSearch = new ADSearchBySID(ldapAttrMapping,
ldapService);
ADSearchBySID adSearch = new ADSearchBySID(ldapAttrMapping);
- groupDAO_ = new ADGroupDAOImpl(ldapAttrMapping, ldapService, adSearch);
- membershipDAO_ = new ADMembershipDAOImpl(ldapAttrMapping, ldapService,
adSearch);
+ groupDAO_ = new ADGroupDAOImpl(ldapAttrMapping, ldapService, adSearch,
cacheHandler);
+ membershipDAO_ = new ADMembershipDAOImpl(ldapAttrMapping, ldapService, adSearch,
cacheHandler);
}
else
{
// ValueParam param = params.getValueParam("ldap.userDN.key");
// ldapAttrMapping.userDNKey = param.getValue();
- userDAO_ = new UserDAOImpl(ldapAttrMapping, ldapService);
- groupDAO_ = new GroupDAOImpl(ldapAttrMapping, ldapService);
- membershipDAO_ = new MembershipDAOImpl(ldapAttrMapping, ldapService);
+ userDAO_ = new UserDAOImpl(ldapAttrMapping, ldapService, cacheHandler);
+ groupDAO_ = new GroupDAOImpl(ldapAttrMapping, ldapService, cacheHandler);
+ membershipDAO_ = new MembershipDAOImpl(ldapAttrMapping, ldapService,
cacheHandler);
}
// userProfileHandler_ = new UserProfileHandlerImpl(ldapAttrMapping, ldapService)
;
userProfileDAO_ = new UserProfileDAOImpl(hservice, cservice);
- membershipTypeDAO_ = new MembershipTypeDAOImpl(ldapAttrMapping, ldapService);
+ membershipTypeDAO_ = new MembershipTypeDAOImpl(ldapAttrMapping, ldapService,
cacheHandler);
ValueParam param = params.getValueParam("ldap.userDN.key");
if (param != null)
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -21,8 +21,13 @@
import org.exoplatform.commons.utils.LazyPageList;
import org.exoplatform.commons.utils.ListAccess;
import org.exoplatform.services.ldap.LDAPService;
-import org.exoplatform.services.organization.*;
+import org.exoplatform.services.organization.Query;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.UserEventListener;
+import org.exoplatform.services.organization.UserEventListenerHandler;
+import org.exoplatform.services.organization.UserHandler;
import org.exoplatform.services.organization.impl.UserImpl;
+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
import java.util.ArrayList;
import java.util.Collections;
@@ -53,11 +58,14 @@
* @param ldapAttrMapping mapping LDAP attributes to eXo organization service
* items (users, groups, etc)
* @param ldapService {@link LDAPService}
+ * @param cacheHandler
+ * The Cache Handler
* @throws Exception if any errors occurs
*/
- public UserDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService)
throws Exception
+ public UserDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService,
CacheHandler cacheHandler)
+ throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
}
/**
@@ -104,14 +112,13 @@
ctx.createSubcontext(userDN, attrs);
if (broadcast)
postSave(user, true);
+
+ cacheHandler.put(user.getUserName(), user, CacheType.USER);
break;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -145,14 +152,13 @@
ctx.modifyAttributes(userDN, mods);
if (broadcast)
postSave(user, false);
+
+ cacheHandler.put(user.getUserName(), user, CacheType.USER);
break;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -174,7 +180,7 @@
* @param userDN Distinguished Name
* @throws Exception if any errors occurs
*/
- void saveUserPassword(User user, String userDN) throws Exception
+ protected void saveUserPassword(User user, String userDN) throws Exception
{
ModificationItem[] mods =
new ModificationItem[]{new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new
BasicAttribute(
@@ -191,10 +197,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -227,14 +230,14 @@
ctx.destroySubcontext(userDN);
if (broadcast)
postDelete(user);
+
+ cacheHandler.remove(userName, CacheType.USER);
+ cacheHandler.remove(CacheHandler.USER_PREFIX + userName,
CacheType.MEMBERSHIP);
return user;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -249,6 +252,12 @@
*/
public User findUserByName(String userName) throws Exception
{
+ User user = (User)cacheHandler.get(userName, CacheType.USER);
+ if (user != null)
+ {
+ return user;
+ }
+
LdapContext ctx = ldapService.getLdapContext();
try
{
@@ -256,14 +265,16 @@
{
try
{
- return getUserFromUsername(ctx, userName);
+ user = getUserFromUsername(ctx, userName);
+ if (user != null)
+ {
+ cacheHandler.put(user.getUserName(), user, CacheType.USER);
+ }
+ return user;
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -283,51 +294,6 @@
*/
public ListAccess<User> findUsersByGroupId(String groupId) throws Exception
{
- // ArrayList<User> users = new ArrayList<User>();
- // TreeMap<String, User> map = new TreeMap<String, User>();
- //
- // LdapContext ctx = ldapService.getLdapContext();
- // try {
- // NamingEnumeration<SearchResult> results = null;
- // for (int err = 0;; err++) {
- // map.clear();
- // try {
- // String searchBase = this.getGroupDNFromGroupId(groupId);
- // String filter = ldapAttrMapping.membershipObjectClassFilter;
- // SearchControls constraints = new SearchControls();
- // constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- // results = ctx.search(searchBase, filter, constraints);
- // while (results.hasMoreElements()) {
- // SearchResult sr = results.next();
- // Attributes attrs = sr.getAttributes();
- // List<Object> members = this.getAttributes(attrs,
- //
ldapAttrMapping.membershipTypeMemberValue);
- // for (int x = 0; x < members.size(); x++) {
- // User user = findUserByDN(ctx, (String) members.get(x));
- // if (user != null)
- // map.put(user.getUserName(), user);
- // }
- // }
- // break;
- // } catch (NamingException e) {
- // if (isConnectionError(e) && err < getMaxConnectionError())
- // ctx = ldapService.getLdapContext(true);
- // else
- // throw e;
- // } finally {
- // if (results != null)
- // results.close();
- // }
- // }
- // } finally {
- // ldapService.release(ctx);
- // }
- //
- // for (Iterator<String> i = map.keySet().iterator(); i.hasNext();)
- // users.add(map.get(i.next()));
- //
- // return new ObjectPageList(users, 10);
-
String searchBase = this.getGroupDNFromGroupId(groupId);
String filter = ldapAttrMapping.membershipObjectClassFilter;
return new ByGroupLdapUserListAccess(ldapAttrMapping, ldapService, searchBase,
filter);
@@ -346,8 +312,6 @@
String searchBase = ldapAttrMapping.userURL;
String filter = ldapAttrMapping.userObjectClassFilter;
- // return new LDAPUserPageList(ldapAttrMapping, ldapService, searchBase, filter,
pageSize);
-
return new SimpleLdapUserListAccess(ldapAttrMapping, ldapService, searchBase,
filter);
}
Modified:
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java
===================================================================
---
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java 2011-08-17
06:51:17 UTC (rev 4762)
+++
core/branches/2.3.x/exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java 2011-08-17
07:00:26 UTC (rev 4763)
@@ -61,9 +61,10 @@
*/
private static final Log LOG =
ExoLogger.getLogger("exo.core.component.organization.ldap.UserProfileDAOImpl");
- public UserProfileDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService) throws Exception
+ public UserProfileDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService
ldapService, CacheHandler cacheHandler)
+ throws Exception
{
- super(ldapAttrMapping, ldapService);
+ super(ldapAttrMapping, ldapService, cacheHandler);
this.listeners = new ArrayList<UserProfileEventListener>(3);
}
@@ -107,10 +108,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -153,10 +151,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -191,10 +186,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}
@@ -229,10 +221,7 @@
}
catch (NamingException e)
{
- if (isConnectionError(e) && err < getMaxConnectionError())
- ctx = ldapService.getLdapContext(true);
- else
- throw e;
+ ctx = reloadCtx(ctx, err, e);
}
}
}