[英]What is an easy way to verify LDAP login credentials on a local Solaris system
I have an application that needs to execute some functions only if user has credentials that can log into the local (Solaris) system.我有一个应用程序,仅当用户具有可以登录本地(Solaris)系统的凭据时才需要执行某些功能。 I just need a quick way to verify the credentials.我只需要一种快速的方法来验证凭据。 This does not work.这不起作用。 It just executes with no error and no printout.它只是执行而没有错误,也没有打印输出。
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);
}
In the end this worked.最后这奏效了。 Notice the use of doman\username, instead of just 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.