引用:http://www.experts-exchange.com/Programming/Languages/Java/New_to_Java/Q_24254611.html
package beans;
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.InitialLdapContext;
public class TestLdapScript {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Hashtable env = new Hashtable();
String userName = "username";
String passWord = "password";
String ldap = "ldap://xx.xxxxx.net:636";
String keystore = "Program Files (x86)/Java/jre1.6.0_06/lib/security";
System.setProperty("javax.net.ssl.trustStroe", keystore);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION,"simple"); //No other SALS worked with me
env.put(Context.SECURITY_PRINCIPAL,userName); // specify the username ONLY to let Microsoft Happy
env.put(Context.SECURITY_CREDENTIALS, passWord); //the password
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.PROVIDER_URL,ldap);
try {
DirContext ctx = new InitialLdapContext(env,null);
//Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the attributes to return
String returnedAtts[]={"sn","givenName"};
searchCtls.setReturningAttributes(returnedAtts);
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//specify the LDAP search filter
//String searchFilter = "(&(ObjectClass=Person)(!(ObjectClass=user)))";
//String searchFilter = "(&(objectClass=user)(&(objectClass=Person)(!(userAccountControl=514))))";
String searchFilter = "(&(objectClass=user)(mail=*))";
//Specify the Base for the search
String searchBase = "DC=xx,DC=net";
//initialize counter to total the results
int totalResults = 0;
// Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
//Loop through the search results
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
totalResults++;
System.out.println(">>>" + "Test>>" + sr );
// Print out some of the attributes, catch the exception if the attributes have no values
/* Attributes attrs = sr.getAttributes();
if (attrs != null) {
try {
System.out.println(" surname: " + attrs.get("cn").get());
System.out.println(" firstname: " + attrs.get("DisplayName").get());
}
catch (NullPointerException e) {
System.out.println("Errors listing attributes: " + e);
}
}*/
}
ctx.close();
} catch(NamingException e)
{
System.err.println(e);
return;
} //if no exception, the user is already authenticated.
System.out.println("OK, successfully authenticating user");
}
}
分享到:
相关推荐
【Ubuntu+svn+ssl+ldap】的安装及集成是一个复杂的过程,涉及到Ubuntu操作系统、Subversion (SVN) 版本控制系统、SSL安全套接层以及Lightweight Directory Access Protocol (LDAP) 用户认证。以下是对这些技术的详细...
本文将深入探讨如何使用Java通过LDAP(轻量级目录访问协议)和SSL(安全套接层)来实现用户和组织(部门)的增删改查操作,并结合证书确保通信的安全性。这些功能通常用于大型企业的用户管理,例如Active Directory...
**LDAP加密访问AD(通过SSL,即LDAPS)在C++中的实现** LDAP(轻量级目录访问协议)是一种用于访问目录服务的标准网络协议,常用于管理用户身份验证和授权。在安全通信方面,LDAP over SSL(LDAPS)提供了一种加密...
在这篇文章中,我们将探讨使用 JAVA 实现 LDAP 的 AD 域免证书查询、修改、删除、新增、启用、禁用和修改密码的操作。 首先,让我们了解什么是 LDAP 和 AD 域。LDAP(Lightweight Directory Access Protocol)是一...
adLDAP - LDAP Authentication with PHP for Active Directory adLDAP is a ...Intelligent Active Directory integration with PHP was a holy grail for most intranet developers for a long time. This project is really to help others with getting over the same hurdles that we've experienced in getting the whole LDAP SSL Active Directory puzzle working natively on Linux....
基于SSL的LDAP安全访问AD认证 基于SSL的LDAP安全访问AD认证是指使用SSL(Secure Sockets Layer)协议来保护LDAP(Lightweight Directory Access Protocol)协议与AD(Active Directory)的通信,使得密码在网络中...
- 设置 `/etc/dovecot/conf.d/10-auth.conf`,启用外部认证方式,比如LDAP。 - 开启Dovecot服务并设置开机自启。 **3. OpenLDAP** OpenLDAP提供了一个集中式的用户管理和认证系统。 - 安装OpenLDAP:`# yum ...
SSL/TLS 基于 PKI (Public Key Infrastructure) 机制,包括证书认证、密钥交换、非对称加密和对称加密等几个关键环节: 1. **证书认证**:SSL/TLS 采用 CA 作为服务端和客户端都信赖的权威组织。证书的颁发和认证都...
### Windows环境下Collabnet Subversion Edge与Trac集成安装方法详解 #### 一、概述 在软件开发过程中,源代码的版本控制与项目追踪是非常重要的环节。Collabnet Subversion (SVN) 和 Trac 是两个广泛使用的工具,...
ldap ssl sasl,论文,描述得很好,有兴趣的来看看吧
根据给定的信息,本文将详细解释如何在CentOS 7上搭建一个集成Postfix、Dovecot、OpenLDAP以及SSL支持的邮件服务器,并且包括群发配置与禁止群发的相关设置。 ### 一、Postfix简介及配置 **Postfix** 是一种用于...
- 使用TLS或SSL加密连接,增强通信安全。 - 实现缓存策略,减少频繁的LDAP查询。 - 考虑性能优化,如批量查询或异步处理。 文件`vuLnDAP-master`可能是一个示例项目,包含了实现上述功能的代码。你可以通过查看源码...
4. **安全管理**:LdapBrowser支持连接到使用不同安全级别的服务器,如匿名连接、简单认证、SSL/TLS 加密等。 5. **导入与导出**:可以将目录数据导入或导出为不同的格式,方便数据迁移或备份。 6. **日志记录与调试...
这个主题涉及几个关键知识点,包括Java LDAP API、SSL安全连接以及如何通过代码操作LDAP目录。 首先,LDAP是一个开放标准的协议,用于存储和检索用户、组、计算机等对象的数据。这些数据通常分布在多台服务器上,...
6. **安全特性**:支持SSL/TLS加密,确保数据传输的安全性。 7. **日志记录**:记录操作日志,便于故障排查和审计。 **二、OpenLDAP简介** OpenLDAP是开源的LDAP实现,它提供了一个灵活、可扩展的目录服务框架,可...
**LDAP简介** LDAP,全称为轻量级目录访问协议(Lightweight Directory Access Protocol),是一种用于访问和管理分布式目录服务的标准网络协议。它主要用于存储和检索用户、组织、资源等信息,广泛应用于身份验证...
**LDAP(轻量级目录访问协议)是一种网络协议,用于访问和管理分布式目录服务。它在各种操作系统上广泛使用,包括Windows。本文将详细介绍在Windows环境下安装LDAP服务器以及使用 LDAP 客户端工具 LdapAdmin 的步骤...
6. **安全连接**:LdapAdmin支持SSL/TLS加密,确保在传输敏感数据时的数据安全。 7. **导出和导入**:可以将目录信息导出为文本或XML格式,便于备份或与其他系统交换数据,同时也支持导入数据,方便迁移或恢复。 ##...
5. **安全连接**:可能支持SSL/TLS加密,确保数据传输的安全性。 6. **导出/导入**:提供数据导出为LDIF格式,以便于备份或在不同服务器间迁移数据。 7. **权限控制**:根据需要设置访问权限,限制用户对目录信息的...
4. **SSL/TLS安全连接**:支持通过安全的SSL/TLS协议连接到LDAP服务器,确保数据传输的安全性。 5. **JDK环境依赖**:LdapBrowser282运行需要Java Development Kit(JDK)环境,确保Java语言的支持。 6. **导出与...