简体   繁体   English

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

[英]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.

相关问题 在我们的应用程序中保留/验证用户登录凭据的最佳方法是什么 - What is the best way to keep/validate user login credentials in our application 如何以编程方式验证 web 表单的登录凭据? - How to programmatically verify login credentials for a web form? 如何使用系统凭据自动登录该站点? - How to automatically login to the site using system credentials? 在xml下面阅读的最简单,最好的方法是什么? - What is the easy and best way to read below xml? 什么是使可选适用于 blackberry 的简单方法? - What is an easy way to make a selectable uitable for blackberry? 是否有一种(简单的)方法来确定GC正在“移除”哪些对象? - Is there an (easy) way to determine what objects the GC is “removing”? 在所有“活动”按钮上设置setOnClickListener()的简单方法是什么 - What is the easy way to setOnClickListener() on all Activity Buttons 登录表单用户凭据,而不是LDAP Spring Security中的硬编码UserDn和密码 - Login form user credentials instead of hard-coded UserDn and Password in LDAP Spring Security 您将如何在Java中实现安全的静态登录凭据系统? - How would you implement a secure static login credentials system in Java? 我的登录系统出了什么问题? - What is wrong with my login system?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM