Repository: incubator-blur Updated Branches: refs/heads/master 3da62a1df -> 06c929b96
Adding a CLI program to check passwords against ldap. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/56bb87be Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/56bb87be Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/56bb87be Branch: refs/heads/master Commit: 56bb87be67bf8f2614b536ba57bbfc8ca609ab04 Parents: 3da62a1 Author: Aaron McCurry <[email protected]> Authored: Thu Feb 12 08:19:50 2015 -0500 Committer: Aaron McCurry <[email protected]> Committed: Thu Feb 12 08:19:50 2015 -0500 ---------------------------------------------------------------------- .../sasl/LdapAuthenticationProviderImpl.java | 43 +++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/56bb87be/blur-thrift/src/main/java/org/apache/blur/thrift/sasl/LdapAuthenticationProviderImpl.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/sasl/LdapAuthenticationProviderImpl.java b/blur-thrift/src/main/java/org/apache/blur/thrift/sasl/LdapAuthenticationProviderImpl.java index 51ff07e..235b149 100644 --- a/blur-thrift/src/main/java/org/apache/blur/thrift/sasl/LdapAuthenticationProviderImpl.java +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/sasl/LdapAuthenticationProviderImpl.java @@ -20,6 +20,8 @@ import static org.apache.blur.utils.BlurConstants.BLUR_SECURITY_SASL_LDAP_BASEDN import static org.apache.blur.utils.BlurConstants.BLUR_SECURITY_SASL_LDAP_DOMAIN; import static org.apache.blur.utils.BlurConstants.BLUR_SECURITY_SASL_LDAP_URL; +import java.io.Console; +import java.io.IOException; import java.net.InetSocketAddress; import java.util.Hashtable; @@ -40,17 +42,36 @@ public class LdapAuthenticationProviderImpl extends PasswordAuthenticationProvid private final String _baseDN; private final String _ldapDomain; -// public static void main(String[] args) throws IOException { -// BlurConfiguration blurConfiguration = new BlurConfiguration(); -// blurConfiguration.set(BLUR_SECURITY_SASL_LDAP_URL,"ldap://localhost:10389/o=sevenSeas"); -// LdapAuthenticationProviderImpl ldapAuthenticationProviderImpl = new LdapAuthenticationProviderImpl( -// blurConfiguration); -// try { -// ldapAuthenticationProviderImpl.authenticate("cn=James Hook,ou=people,o=sevenSeas", "peterPan", null); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } + public static void main(String[] args) throws IOException { + if (args.length < 2) { + System.err.println("<ldap uri> <username>"); + System.exit(1); + } + String ldap = args[0]; + StringBuilder builder = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + if (builder.length() != 0) { + builder.append(' '); + } + builder.append(args[i]); + } + String user = builder.toString(); + + Console cons; + + if ((cons = System.console()) != null) { + char[] passwd = cons.readPassword("%s", "Type Password:\n"); + BlurConfiguration blurConfiguration = new BlurConfiguration(); + blurConfiguration.set(BLUR_SECURITY_SASL_LDAP_URL, ldap); + LdapAuthenticationProviderImpl ldapAuthenticationProviderImpl = new LdapAuthenticationProviderImpl( + blurConfiguration); + ldapAuthenticationProviderImpl.authenticate(user, new String(passwd), null); + System.out.println("Valid"); + } else { + System.err.println("No Console."); + System.exit(1); + } + } public LdapAuthenticationProviderImpl(BlurConfiguration configuration) { super(configuration);
