(Stuart Lewis) Fix for SF bug #2055941 LDAP authentication fails for new users in SWORD and Manakin

git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@3051 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Stuart Lewis
2008-08-17 14:11:20 +00:00
parent 8b192d2665
commit 160adab1c9

View File

@@ -62,14 +62,10 @@ import org.dspace.core.LogManager;
import org.dspace.eperson.EPerson;
/**
* This is UNTESTED, since I do not have LDAP servers available.
* It was adpated from LDAPServlet and should replace it.
* See the <code>AuthenticationMethod</code> interface for more details.
* Authentication module to authenticate against a flat LDAP tree where
* all users are in the same unit.
*
* As of August 2005 we need a volunteer to complete and test this
* implementation. They should add themselves to the author tag below.
*
* @author Larry Stone
* @author Larry Stone, Stuart Lewis
* @version $Revision$
*/
public class LDAPAuthentication
@@ -148,7 +144,7 @@ public class LDAPAuthentication
// Skip out when no netid or password is given.
if (netid == null || password == null)
return BAD_ARGS;
// Locate the eperson
EPerson eperson = null;
try
@@ -228,7 +224,8 @@ public class LDAPAuthentication
AuthenticationManager.initEPerson(context, request, eperson);
eperson.update();
context.commit();
}
context.setCurrentUser(eperson);
}
catch (AuthorizeException e)
{
return NO_SUCH_USER;
@@ -297,33 +294,33 @@ public class LDAPAuthentication
String ldap_id_field = ConfigurationManager.getProperty("ldap.id_field");
String ldap_search_context = ConfigurationManager.getProperty("ldap.search_context");
String ldap_object_context = ConfigurationManager.getProperty("ldap.object_context");
// Set up environment for creating initial context
Hashtable env = new Hashtable(11);
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(javax.naming.Context.PROVIDER_URL, ldap_provider_url);
// Authenticate
env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "simple");
env.put(javax.naming.Context.SECURITY_PRINCIPAL, ldap_id_field+"="+netid+","+ldap_object_context);
env.put(javax.naming.Context.SECURITY_CREDENTIALS, password);
DirContext ctx = null;
try
{
// Create initial context
ctx = new InitialDirContext(env);
String ldap_email_field = ConfigurationManager.getProperty("ldap.email_field");
String ldap_givenname_field = ConfigurationManager.getProperty("ldap.givenname_field");
String ldap_surname_field = ConfigurationManager.getProperty("ldap.surname_field");
String ldap_phone_field = ConfigurationManager.getProperty("ldap.phone_field");
Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasicAttribute(ldap_id_field, netid));
String attlist[] = {ldap_email_field, ldap_givenname_field, ldap_surname_field, ldap_phone_field};
// look up attributes
try
{
@@ -332,25 +329,25 @@ public class LDAPAuthentication
SearchResult sr = (SearchResult)answer.next();
Attributes atts = sr.getAttributes();
Attribute att;
if (attlist[0]!=null)
{
att = atts.get(attlist[0]);
if (att != null) ldapEmail = (String)att.get();
}
if (attlist[1]!=null)
{
att = atts.get(attlist[1]);
if (att != null) ldapGivenName = (String)att.get();
}
if (attlist[2]!=null)
{
att = atts.get(attlist[2]);
if (att != null) ldapSurname = (String)att.get();
}
if (attlist[3]!=null)
{
att = atts.get(attlist[3]);
@@ -390,7 +387,7 @@ public class LDAPAuthentication
{
return false;
}
return true;
}
@@ -433,4 +430,4 @@ public class LDAPAuthentication
{
return "org.dspace.eperson.LDAPAuthentication.title";
}
}
}