Issue #56 - address users issues with ldap login

This commit is contained in:
Jesse McConnell 2016-08-03 16:59:17 -05:00
parent 4b920622d5
commit 4bf885cedd
1 changed files with 19 additions and 19 deletions

View File

@ -43,6 +43,8 @@ import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import org.eclipse.jetty.jaas.callback.ObjectCallback; import org.eclipse.jetty.jaas.callback.ObjectCallback;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.security.Credential; import org.eclipse.jetty.util.security.Credential;
@ -687,38 +689,36 @@ public class LdapLoginModule extends AbstractLoginModule
return env; return env;
} }
public static String convertCredentialJettyToLdap(String encryptedPassword)
{
if ("MD5:".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH)))
{
return "{MD5}" + encryptedPassword.substring("MD5:".length(), encryptedPassword.length());
}
if ("CRYPT:".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH)))
{
return "{CRYPT}" + encryptedPassword.substring("CRYPT:".length(), encryptedPassword.length());
}
return encryptedPassword;
}
public static String convertCredentialLdapToJetty(String encryptedPassword) public static String convertCredentialLdapToJetty(String encryptedPassword)
{ {
if (encryptedPassword == null) if (encryptedPassword == null)
{ {
return encryptedPassword; return null;
} }
if ("{MD5}".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH))) if (encryptedPassword.toUpperCase(Locale.ENGLISH).startsWith("{MD5}"))
{ {
return "MD5:" + encryptedPassword.substring("{MD5}".length(), encryptedPassword.length()); String src = encryptedPassword.substring("{MD5}".length(), encryptedPassword.length());
return "MD5:" + base64ToHex(src);
} }
if ("{CRYPT}".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH))) if (encryptedPassword.toUpperCase(Locale.ENGLISH).startsWith("{CRYPT}"))
{ {
return "CRYPT:" + encryptedPassword.substring("{CRYPT}".length(), encryptedPassword.length()); return "CRYPT:" + encryptedPassword.substring("{CRYPT}".length(), encryptedPassword.length());
} }
return encryptedPassword; return encryptedPassword;
} }
private static String base64ToHex(String src)
{
byte[] bytes = B64Code.decode(src);
return TypeUtil.toString(bytes, 16);
}
private static String hexToBase64(String src)
{
byte[] bytes = TypeUtil.fromHexString(src);
return new String(B64Code.encode(bytes));
}
} }