在本地 Solaris 系统上验证 LDAP 登录凭据的简单方法是什么
What is an easy way to verify LDAP login credentials on a local Solaris system
我有一个应用程序需要执行某些功能只有当用户具有可以登录到本地 (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);
}
我有一个应用程序需要执行某些功能只有当用户具有可以登录到本地 (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);
}