在本地 Solaris 系统上验证 LDAP 登录凭据的简单方法是什么?



我有一个应用程序,只有当用户具有可以登录到本地(Solaris(系统的凭据时,才需要执行某些功能。我只需要一种快速的方法来验证凭据。这行不通。它只是执行没有错误,也没有打印输出。

Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
env.put(Context.PROVIDER_URL, "ldap://hostname"); 
env.put(Context.SECURITY_AUTHENTICATION, "simple");
LdapContext ldapContext;
Hashtable<String, String> environment = new Hashtable<String, String>(env); 
environment.put(Context.SECURITY_PRINCIPAL, "username");
environment.put(Context.SECURITY_CREDENTIALS, "");
DirContext context;
try {
context = LdapCtxFactory.getLdapCtxInstance("ldap://HOSTNAME", environment);
System.out.println("Seccess");
} catch (NamingException ex) {
System.out.println("Authentication failed: " + ex);
Logger.getLogger(FAMENewReader.class.getName()).log(Level.SEVERE, null, ex);
}   

最后这奏效了。请注意使用doman\username,而不仅仅是用户名。

Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
env.put(Context.PROVIDER_URL, "ldap://xxx.xxx.xxx.xx"); 
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "domain\username");
env.put(Context.SECURITY_CREDENTIALS, "passwd");
try {
DirContext ctx = new InitialDirContext(env);
System.out.println("Success");
} catch (Throwable ex) {
System.out.println("Authentication failed: " + ex);
}