Author: bdaw
Date: 2007-11-21 09:30:07 -0500 (Wed, 21 Nov 2007)
New Revision: 9064
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPConnectionContext.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModule.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
Log:
Fix external context usage bug for LDAP connection
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPConnectionContext.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPConnectionContext.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPConnectionContext.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -137,7 +137,7 @@
return env;
}
- public InitialLdapContext createInitialContext() throws IdentityException
+ public LdapContext createInitialContext() throws IdentityException
{
try
{
@@ -145,7 +145,7 @@
if (getExternalContextJndiName() != null)
{
InitialContext iniCtx = new InitialContext();
- return (InitialLdapContext)iniCtx.lookup(getExternalContextJndiName());
+ return (LdapContext)iniCtx.lookup(getExternalContextJndiName());
}
//if not construct our own one using provided options
else
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -22,24 +22,23 @@
******************************************************************************/
package org.jboss.portal.identity.ldap;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.IdentityConfiguration;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.IdentityConfiguration;
-import org.jboss.portal.common.util.Tools;
-import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
+import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
-import java.util.Set;
-import java.util.List;
-import java.util.NoSuchElementException;
+import javax.naming.ldap.LdapContext;
+import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Enumeration;
import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -210,7 +209,7 @@
public List searchRoles(String filter, Object[] filterArgs) throws NamingException,
IdentityException
{
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -32,7 +32,7 @@
import javax.naming.NamingException;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
@@ -219,7 +219,7 @@
public List searchUsers(String filter, Object[] filterArgs) throws NamingException,
IdentityException
{
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModule.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModule.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModule.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -21,23 +21,22 @@
*/
package org.jboss.portal.identity.ldap;
-import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.service.RoleModuleService;
-import javax.naming.directory.Attributes;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
-import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
-import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.InitialContext;
-import javax.naming.ldap.InitialLdapContext;
-import java.util.NoSuchElementException;
+import javax.naming.ldap.LdapContext;
import java.util.List;
+import java.util.NoSuchElementException;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
@@ -72,7 +71,7 @@
public void updateDisplayName(LDAPRoleImpl ldapr, String name) throws
IdentityException
{
String attributeName = getDisplayNameAttributeID();
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -150,7 +149,7 @@
public Role findRoleByDN(String dn) throws IdentityException,
IllegalArgumentException
{
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -160,7 +160,7 @@
throw new IdentityException("Role name cannot be null");
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -240,7 +240,7 @@
throw new IdentityException("Cannot obtain DN of role");
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -327,7 +327,7 @@
public List searchRoles(String filter, Object[] filterArgs) throws NamingException,
IdentityException
{
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -22,30 +22,29 @@
******************************************************************************/
package org.jboss.portal.identity.ldap;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.common.util.Tools;
import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity.ldap.helper.LDAPTools;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.User;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.BasicAttributes;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
+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.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
-import java.util.Set;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Iterator;
import java.util.LinkedList;
-import java.util.Collections;
+import java.util.List;
+import java.util.Set;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -156,7 +155,7 @@
Set users = new HashSet();
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -253,7 +252,7 @@
"require the member field to be set). ");
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -392,7 +391,7 @@
memberName = ldapUser.getUserName();
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -21,31 +21,29 @@
*/
package org.jboss.portal.identity.ldap;
-import org.jboss.portal.identity.ldap.helper.LDAPTools;
import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.User;
-import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
+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.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
-import java.util.Set;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Iterator;
import java.util.LinkedList;
-import java.util.Collections;
-import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -88,7 +86,7 @@
Set roles = new HashSet();
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -300,7 +298,7 @@
memberOfName = ldapRole.getName();
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -403,7 +401,7 @@
throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModule.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -21,30 +21,29 @@
*/
package org.jboss.portal.identity.ldap;
-import org.jboss.portal.identity.service.UserModuleService;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityContext;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.UserProfileModule;
import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.IdentityContext;
-import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.identity.service.UserModuleService;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
-import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.InitialContext;
-import javax.naming.Context;
import javax.naming.ldap.InitialLdapContext;
-import java.util.NoSuchElementException;
-import java.util.Map;
+import javax.naming.ldap.LdapContext;
import java.util.Hashtable;
-import java.util.Enumeration;
import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
/**
* Abstract LDAPUserModule that should be extended to provide compabitibility across
identity modules
@@ -84,7 +83,7 @@
{
String attributeName = getPasswordAttributeId();
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -117,7 +116,6 @@
public boolean validatePassword(LDAPUserImpl ldapu, String password) throws
IdentityException
{
- Hashtable env =getConnectionContext().getEnvironment();
//will use user DN to bind checking the password by default
String principal = ldapu.getDn();
@@ -139,20 +137,40 @@
principal = preffix + ldapu.getUserName() + suffix;
}
- env.put(Context.SECURITY_PRINCIPAL, principal);
- env.put(Context.SECURITY_CREDENTIALS, password);
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
+
try
{
+
+ Hashtable env = ldapContext.getEnvironment();
+
+ env.put(Context.SECURITY_PRINCIPAL, principal);
+ env.put(Context.SECURITY_CREDENTIALS, password);
+
InitialContext ctx = new InitialLdapContext(env, null);
+
if (ctx != null)
{
+ ctx.close();
return true;
}
+
}
catch (NamingException e)
{
//
}
+ finally
+ {
+ try
+ {
+ ldapContext.close();
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to close LDAP connection", e);
+ }
+ }
return false;
}
@@ -196,7 +214,7 @@
*/
public User findUserByDN(String dn) throws IdentityException,
IllegalArgumentException, NoSuchUserException
{
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -144,7 +144,7 @@
log.debug("Creating user: " + userName);
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -226,7 +226,7 @@
throw new IdentityException("Cannot obtain DN of user");
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -376,7 +376,7 @@
log.debug("Search filter: " + filter);
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
Modified:
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
===================================================================
---
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2007-11-21
14:05:47 UTC (rev 9063)
+++
modules/identity/trunk/identity/src/main/java/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2007-11-21
14:30:07 UTC (rev 9064)
@@ -21,29 +21,29 @@
*/
package org.jboss.portal.identity.ldap;
+import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.UserProfileModule;
-import org.jboss.portal.identity.IdentityContext;
import org.jboss.portal.identity.info.ProfileInfo;
import org.jboss.portal.identity.info.PropertyInfo;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.CachedUserImpl;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity.UserModule;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
-import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
-import java.util.Set;
-import java.util.Map;
+import javax.naming.ldap.LdapContext;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.Collection;
-import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
@@ -98,7 +98,7 @@
return null;
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -202,7 +202,7 @@
return;
}
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{
@@ -265,7 +265,7 @@
Map propertyMap = new HashMap();
- InitialLdapContext ldapContext = getConnectionContext().createInitialContext();
+ LdapContext ldapContext = getConnectionContext().createInitialContext();
try
{