import com.novell.ldap.*;
import java.util.Enumeration;
import java.util.Iterator;
import java.io.UnsupportedEncodingException;
public class Searchas
{
public static void main( String[] args )
{
if (args.length != 5) {
System.err.println("Usage: java Searchas <host name> <login dn>"
+ " <password> <search base>\n"
+ " <search filter>");
System.err.println("Example: java Searchas Acme.com"
+ " \"cn=admin,o=Acme\""
+ " secret \"ou=sales,o=Acme\"\n"
+ " \"objectclass=*\"");
System.exit(1);
}
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;
String attrs[] ={ "cn", "sn" };
LDAPConnection lc = new LDAPConnection();
String ldapHost = args[0];
String loginDN = args[1];
String password = args[2];
String searchBase = args[3];
String searchFilter= args[4];
try {
// connect to the server
lc.connect( ldapHost, ldapPort );
// authenticate to the server
lc.bind(ldapVersion, loginDN, password.getBytes("UTF8") );
// asynchronous search
LDAPSearchQueue queue =
lc.search( searchBase, // container to search
LDAPConnection.SCOPE_ONE// search container only
searchFilter, // search filter
attrs, // return cn and sn
false, // return attrs and values
(LDAPSearchQueue)null,
// use default search queue
(LDAPSearchConstraints)null);
// use default search constraints
LDAPMessage message;
while (( message = queue.getResponse()) != null ) {
// the message is a search result reference
if ( message instanceof LDAPSearchResultReference ) {
String urls[] =
((LDAPSearchResultReference)message).getReferrals();
System.out.println("Search result references:");
for ( int i = 0; i < urls.length; i++ )
System.out.println(urls[i]);
}
// the message is a search result
else if ( message instanceof LDAPSearchResult ) {
LDAPEntry entry = ((LDAPSearchResult)message).getEntry();
System.out.println("\n" + entry.getDN());
System.out.println("\tAttributes: ");
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
while(allAttributes.hasNext()) {
LDAPAttribute attribute =
(LDAPAttribute)allAttributes.next();
String attributeName = attribute.getName();
System.out.println("\t\t" + attributeName);
Enumeration allValues = attribute.getStringValues();
if( allValues != null) {
while(allValues.hasMoreElements()) {
String Value =
(String) allValues.nextElement();
System.out.println("\t\t\t" + Value);
}
}
}
}
// the message is a search response
else {
LDAPResponse response = (LDAPResponse)message;
int status = response.getResultCode();
// the return code is LDAP success
if ( status == LDAPException.SUCCESS ) {
System.out.println("Asynchronous search succeeded.");
}
// the reutrn code is referral exception
else if ( status == LDAPException.REFERRAL ) {
String urls[]=((LDAPResponse)message).getReferrals();
System.out.println("Referrals:");
for ( int i = 0; i < urls.length; i++ )
System.out.println(urls[i]);
}
else {
System.out.println("Asynchronous search failed.");
throw new LDAPException( response.getErrorMessage(),
status,
response.getMatchedDN());
}
}
}
// disconnect with the server
lc.disconnect();
}
catch( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
catch( UnsupportedEncodingException e ) {
System.out.println( "Error: " + e.toString() );
}
System.exit(0);
}
}
分享到:
相关推荐
通过将异步操作以同步的方式呈现,async/await极大地提高了代码的可读性和可维护性,使得异步编程不再那么复杂和难以理解。随着ES7标准的确立,async/await已经广泛应用于现代JavaScript开发中,成为了开发者必须...
正在安装 yarn add @tanuel/async-queue# ornpm install @tanuel/async-queue --save用法 import { AsyncQueue } from "@tanuel/async-queue" ;( async ( ) => { const queue = new AsyncQueue ( ) ; queue . on ( ...
通过import * as asyncArrayUtils from '@wojtekmaj/async-array-utils'添加import * as asyncArrayUtils from '@wojtekmaj/async-array-utils' 。 用它做东西! const asyncMappedArr = await asyncMap ( [ 1 , 2...
require ( [ 'async' ] , function ( async ) { } ) ; 承诺和异步/等待 我建议使用 。 它针对Promise处理进行了优化,并且具有与neo-async几乎相同的功能。 Node.js 标准 $ npm install neo-async var async = ...
Node.js 7.6 已经支持 async/await 了,如果你还没有试过,这篇博客将告诉你为什么要用它。 Async/Await 简介 对于从未听说过 async/await 的朋友,下面是简介: async/await 是写异步代码的新方式,以前的方法有回...
为了简化这一过程,我们可以利用第三方库如`spatie/async`来更好地利用`PCNTL`进行异步和并行操作。 `spatie/async`库为PHP的`PCNTL`扩展提供了一个简洁易用的包装器,使得开发者可以更容易地实现并行执行任务。这...
【Android 组件化】使用 ARoute 实现组件化 ( 完整组件化项目示例 ) https://hanshuliang.blog.csdn.net/article/details/117294139 博客源码
$ yarn open 05-code-splitting/async-chunk 内容 01开始 02输入输出 输出路径(TODO) output-publicPath(TODO) output-chunkFilename(TODO) 03装载机 svg-inline-loader(TODO) 04手柄样式 05代码分割 产品...
- 调整`max_async_ports`参数,它限制了可同时使用`/dev/async`设备的最大进程数,应大于等于数据库初始化参数文件`init<sid>.ora`中的`processes`值加上后台进程数。 - 调整`aio_max_ops`参数,它定义了任何时刻...
类 Unix 机器上的示例常见位置包括 /usr/local/cad、/opt/cad、/opt/async。您也可以将它们安装在任何其他目录中(例如 $HOME/async) 将环境变量 ACT_HOME 设置为指向安装目录。 将环境变量 VLSI_TOOLS_SRC 设置为...
C#: EPSON Robot Remote TCP/IP Control,Motion Control(GoogolTech/LeadShine),Advantech(PCI1752/PCI1754),Keyence Laser,RS232C,RS485,TCP/IP Server/Client(Sync/Async),OPC Client/Server,CAN, EtherCAT,XML,...
功能异步示例这是一个回购,其中提供了一些示例,说明如何在功能范式中限制和制作异步功能。 该软件包需要python 3.7,并且requirements.txt在“ examples”文件夹下提供了运行示例所需的要求列表。
AsyncAPI游乐场在本地使用跑: npm install和npm start并转到 。建立Docker映像docker build -t asyncapi-playground .运行docker镜像docker run -d --name asyncapi-playground -p 83:5000 asyncapi-playground:...
`async/await`是ES2017引入的一种更优雅、更易读的异步编程方式,它极大地改善了传统的回调函数和Promise链式调用的复杂性。下面我们将深入探讨`async/await`的原理、用法以及如何在实际项目中应用。 `async`关键字...
该实施主要基于的工作安装$ npm install --save @creditkarma/async-hooks用法createHook 使用提供的回调创建一个新的AsyncHook对象 import * as AsyncHooks from '@creditkarma/async-hooks'AsyncHooks ....
https://github.com/caolan/async/tree/master/dist async提供了很多函数用于异步流程控制,下面是async核心的几个函数,完整的函数请看async官方DOC async.map(['file1','file2','file3'], fs.stat, function(err,...
Build Status ...https://github.com/loopj/android-async-http/blob/1.4.9/CHANGELOG.md Javadoc Latest Javadoc for 1.4.9 release are available here (also included in Maven repository): ...
执行扩展 AsyncJob 类并定义 syncjob() 方法以输出字符串或文件类型的对象。 AsyncJob 会将此输出上传到 S3,并在进程运行时提供管理监控。 AsyncJob Django 设置: ASYNCJOB_S3_...
异步配置程序执行器端点 该项目包含一个Spring Boot执行器端点实现,该实现充当async-profiler( )的包装。 它允许直接将HTTP配置文件请求发送到配置文件的Spring Boot服务,并在响应中(或以任何其他受支持的格式...