Merged V2.9 to HEAD

9241: Merged V2.2 to V2.9
      9119: Merged V2.1 to V2.2
         8671: Fix for AR-2221 - JavaScript scriptable Map objects recursively converted to Freemarker accessable maps
   9256: Merged V2.2 to V2.9 
      9100: Merged V2.1 to V2.2 
         8728 <Not required>: Latest AMP changes for AR-2212 
         8731: Faster content store cleaner 
         8738: Fix for AWC 1930 - support simple bind when building DNs that contain a comma 
         8835: Fix regression issue as discussed in ACT 2019 
         8861: Fix WCM-1158 
         8866: Fixed AR-2272: Module Management Tool distribution is broken 
         8872: Fixed distribution of benchmark executable jar after EHCache upgrade 
         8933: Fix for ACT-2469


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9260 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-05-23 21:41:53 +00:00
parent bb3c776130
commit db95d287ee
12 changed files with 515 additions and 37 deletions

View File

@@ -37,28 +37,39 @@ import org.alfresco.repo.security.authentication.AuthenticationException;
*/
public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationComponent
{
private boolean escapeCommasInBind = false;
private boolean escapeCommasInUid = false;
private String userNameFormat;
private LDAPInitialDirContextFactory ldapInitialContextFactory;
public LDAPAuthenticationComponentImpl()
{
super();
}
public void setLDAPInitialDirContextFactory(LDAPInitialDirContextFactory ldapInitialDirContextFactory)
{
this.ldapInitialContextFactory = ldapInitialDirContextFactory;
}
public void setUserNameFormat(String userNameFormat)
{
this.userNameFormat = userNameFormat;
}
public void setEscapeCommasInBind(boolean escapeCommasInBind)
{
this.escapeCommasInBind = escapeCommasInBind;
}
public void setEscapeCommasInUid(boolean escapeCommasInUid)
{
this.escapeCommasInUid = escapeCommasInUid;
}
/**
* Implement the authentication method
*/
@@ -67,16 +78,16 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo
InitialDirContext ctx = null;
try
{
ctx = ldapInitialContextFactory.getInitialDirContext(String.format(userNameFormat, new Object[]{userName}), new String(password));
ctx = ldapInitialContextFactory.getInitialDirContext(String.format(userNameFormat, new Object[] { escapeUserName(userName, escapeCommasInBind) }), new String(password));
// Authentication has been successful.
// Set the current user, they are now authenticated.
setCurrentUser(userName);
setCurrentUser(escapeUserName(userName, escapeCommasInUid));
}
finally
{
if(ctx != null)
if (ctx != null)
{
try
{
@@ -91,6 +102,29 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo
}
}
private static String escapeUserName(String userName, boolean escape)
{
if (escape)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < userName.length(); i++)
{
char c = userName.charAt(i);
if (c == ',')
{
sb.append('\\');
}
sb.append(c);
}
return sb.toString();
}
else
{
return userName;
}
}
@Override
protected boolean implementationAllowsGuestLogin()
@@ -99,16 +133,16 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo
try
{
ctx = ldapInitialContextFactory.getDefaultIntialDirContext();
return true;
return true;
}
catch(Exception e)
catch (Exception e)
{
return false;
}
finally
{
if(ctx != null)
if (ctx != null)
{
try
{
@@ -121,6 +155,5 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo
}
}
}
}