sdk.xml revision 5398
5398N/A<?xml version="1.0" encoding="UTF-8" standalone="no"?>
5398N/A<!DOCTYPE stax SYSTEM "/stax.dtd">
5398N/A<!--
5398N/A ! CDDL HEADER START
5398N/A !
5398N/A ! The contents of this file are subject to the terms of the
5398N/A ! Common Development and Distribution License, Version 1.0 only
5398N/A ! (the "License"). You may not use this file except in compliance
5398N/A ! with the License.
5398N/A !
5398N/A ! You can obtain a copy of the license at
5398N/A ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
5398N/A ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
5398N/A ! See the License for the specific language governing permissions
5398N/A ! and limitations under the License.
5398N/A !
5398N/A ! When distributing Covered Code, include this CDDL HEADER in each
5398N/A ! file and include the License file at
5398N/A ! trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
5398N/A ! add the following below this CDDL HEADER, with the fields enclosed
5398N/A ! by brackets "[]" replaced with your own identifying information:
5398N/A ! Portions Copyright [yyyy] [name of copyright owner]
5398N/A !
5398N/A ! CDDL HEADER END
5398N/A !
5398N/A ! Copyright 2011 ForgeRock AS
5398N/A ! -->
5398N/A<stax>
5398N/A <!-- SDK ldapsearch Function -->
5398N/A <function name="SDKldapSearch">
5398N/A <function-prolog>
5398N/A This function performs an ldapsearch using the SDK java API
5398N/A </function-prolog>
5398N/A <function-map-args>
5398N/A <function-arg-def name="dsInstanceHost" type="optional">
5398N/A <function-arg-description>
5398N/A Directory server hostname or IP address
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="hostname"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsInstancePort" type="optional">
5398N/A <function-arg-description>
5398N/A Directory server port number
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="Port number"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsInstanceDn" type="optional">
5398N/A <function-arg-description>
5398N/A Bind DN
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="DN"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsInstancePswd" type="optional">
5398N/A <function-arg-description>
5398N/A Bind password
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="string"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsScope" type="optional">
5398N/A <function-arg-description>
5398N/A The scope of the search operation
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="string"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsBaseDN" type="optional">
5398N/A <function-arg-description>
5398N/A The baseDN for the search operation
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="dn"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsFilter" type="optional">
5398N/A <function-arg-description>
5398N/A The filter for the search operation
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="filter"/>
5398N/A </function-arg-def>
5398N/A <function-arg-def name="dsAttributes" type="optional">
5398N/A <function-arg-description>
5398N/A Only return these attributes
5398N/A </function-arg-description>
5398N/A <function-arg-property name="type" value="string"/>
5398N/A </function-arg-def>
5398N/A </function-map-args>
5398N/A
5398N/A <sequence>
5398N/A
5398N/A <!-- Build the Command -->
5398N/A <script>
5398N/A from org.forgerock.opendj.ldap import *
5398N/A from org.forgerock.opendj.ldap.responses import *
5398N/A from org.forgerock.opendj.ldif import *
5398N/A
5398N/A myHost=String(dsInstanceHost)
5398N/A myPort=int(dsInstancePort)
5398N/A myBaseDn=String(dsBaseDN)
5398N/A myDn=String(dsInstanceDn)
5398N/A myPassword=String(dsInstancePswd).toCharArray()
5398N/A
5398N/A if dsScope == 'base':
5398N/A myScope = SearchScope.BASE_OBJECT
5398N/A elif dsScope == 'one':
5398N/A myScope = SearchScope.SINGLE_LEVEL
5398N/A elif dsScope == 'sub':
5398N/A myScope = SearchScope.WHOLE_SUBTREE
5398N/A else:
5398N/A myScope = SearchScope.WHOLE_SUBTREE
5398N/A
5398N/A if dsFilter:
5398N/A myFilter = dsFilter
5398N/A else:
5398N/A myFilter = '(objectClass=*)'
5398N/A
5398N/A if dsAttributes:
5398N/A myAttrs = dsAttributes
5398N/A else:
5398N/A myAttrs = []
5398N/A
5398N/A writer = LDIFEntryWriter(System.out)
5398N/A factory = LDAPConnectionFactory(myHost,myPort)
5398N/A connection = None
5398N/A
5398N/A try:
5398N/A try:
5398N/A connection = factory.getConnection()
5398N/A
5398N/A connection.bind(myDn, myPassword)
5398N/A
5398N/A reader = connection.search(myBaseDn, myScope, myFilter, myAttrs)
5398N/A
5398N/A #TODO: handle search result references
5398N/A #TODO: not really a need to use writer to write to stdout
5398N/A while (reader.hasNext()):
5398N/A if not reader.isReference():
5398N/A entry = reader.readEntry()
5398N/A writer.writeComment("Search result entry: %s" % entry.getName().toString())
5398N/A writer.writeEntry(entry)
5398N/A else:
5398N/A ref = reader.readReference()
5398N/A writer.writeComment("Search result reference: %s " % ref.getURIs().toString())
5398N/A
5398N/A writer.flush()
5398N/A
5398N/A except ErrorResultException, e:
5398N/A System.err.println(e.getMessage())
5398N/A System.exit(e.getResult().getResultCode().intValue())
5398N/A
5398N/A except ErrorResultIOException, e:
5398N/A System.err.println(e.getMessage())
5398N/A System.exit(e.getCause().getResult().getResultCode().intValue())
5398N/A
5398N/A except InterruptedException, e:
5398N/A System.err.println(e.getMessage())
5398N/A System.exit(ResultCode.CLIENT_SIDE_USER_CANCELLED.intValue())
5398N/A
5398N/A except IOException, e:
5398N/A System.err.println(e.getMessage())
5398N/A System.exit(ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue())
5398N/A
5398N/A finally:
5398N/A connection.close()
5398N/A
5398N/A SDKResult = [[0,'%s' % entry.getAllAttributes().toString()]]
5398N/A </script>
5398N/A <message>
5398N/A 'Result = %s' % entry.getAllAttributes().toString()
5398N/A </message>
5398N/A <return>
5398N/A SDKResult
5398N/A </return>
5398N/A </sequence>
5398N/A </function>
5688N/A</stax>