 |
 |

|
 |
 |
Resources
Using Novell's LDAP Extensions and Controls for JNDI
The LDAP Extensions and Controls for JNDI are LDAP v3-compliant and include support for the virtual list views and server-side sorting controls available on eDirectory. Because it uses LDAP, it has no dependencies on the Novell Client software.
For information on using the controls and extensions with Novell eDirectory, see LDAP Control Support and LDAP Extension Support in the NDS and LDAP Integration Guide at: http://developer.novell.com/ndk/doc/extjndi/index.html?page=/ndk/doc/extjndi/ejndienu/data/a9imlo4.html.
// Sample code file: CreateNamingContext.javaFirst of all, let's look at some // sample code for creating a context: // Warning: This code has been marked up for HTML /*********************************************************************** * Copyright (c) 2002 Novell, Inc. All Rights Reserved. * THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS * AND TREATIES. USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO * THE LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE * DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK. PURSUANT TO * THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO * DEVELOPER A ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE * NOVELL'S SAMPLE CODE IN ITS PRODUCT. NOVELL GRANTS DEVELOPER * WORLDWIDE DISTRIBUTION RIGHTS TO MARKET, DISTRIBUTE, OR SELL * NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S PRODUCTS. * NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR * DEVELOPER'S CUSTOMERS WITH RESPECT TO THIS CODE. * * $name: CreateNamingContext.java * $version: 1.0 * $date_modified: Thr, September 11, 2000 * $owner: * $description: CreateNamingContext.java demonstrates how to create a * naming context. ***********************************************************************/ import java.util.*; import javax.naming.*; import javax.naming.ldap.*; import com.sun.jndi.ldap.*; import com.novell.service.ndssdk.jndi.ldap.ext.*;
public class CreateNamingContext { public static void main(String[] args) {
if (args.length != 4) { System.err.println("Usage : java CreateNamingContext <host name>" + " <login dn> <password> <partition dn>"); System.err.println("Example: java CreateNamingContext Acme.com" + " cn=admin,o=Acme secret ou=sales,o=Acme"); System.exit ( -1 ); } try { int ldapPort = LdapCtx.DEFAULT_PORT; String ldapHost = args[0]; String loginDN = args[1]; String passWord = args[2]; String namingContextDN = args[3];
// create a Hashtable object to put environment variables Hashtable env = new Hashtable(5, 0.75f); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://" + ldapHost +":" + ldapPort); env.put(Context.SECURITY_AUTHENTICATION, "simple" ); env.put(Context.SECURITY_PRINCIPAL, loginDN ); env.put(Context.SECURITY_CREDENTIALS, passWord ); // construct a LdapContext object LdapContext ctx = new InitialLdapContext(env, null); /* * Call extended operation to create the naming context. The * flag used for creating naming context request is: * LDAP_ENSURE_SERVERS_UP = 1 */ CreateNamingContextRequest reqs = new CreateNamingContextRequest( namingContextDN, NamingContextConstants.LDAP_ENSURE_SERVERS_UP ); LDAPExtendedResponse resp = (LDAPExtendedResponse) ctx.extendedOperation(reqs); System.out.println("CreateNamingContext operation succeeded."); } catch (NamingException e) { System.err.println("CreateNamingContext operation failed."); e.printStackTrace(); } finally { System.exit(0); } }
Here is a second piece of sample code using Novell's LDAP Extensions and Controls for JNDI:
// Sample code file: ListReplicas.java // Warning: This code has been marked up for HTML /*********************************************************************** * * Copyright (c) 2002 Novell, Inc. All Rights Reserved. * * THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS * AND TREATIES. USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO * THE LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE * DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK. PURSUANT TO * THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO * DEVELOPER A ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE * NOVELL'S SAMPLE CODE IN ITS PRODUCT. NOVELL GRANTS DEVELOPER * WORLDWIDE DISTRIBUTION RIGHTS TO MARKET, DISTRIBUTE, OR SELL * NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S PRODUCTS. * NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR * DEVELOPER'S CUSTOMERS WITH RESPECT TO THIS CODE. * * $name: ListReplicas.java * $version: 1.0 * $date_modified: Thr, September 11, 2000 * $owner: * $description: ListReplicas.java is used to show all the replicas in * a server object. ***********************************************************************/ import java.util.*; import java.io.*; import javax.naming.*; import javax.naming.ldap.*; import com.sun.jndi.ldap.*; import com.novell.service.ndssdk.jndi.ldap.ext.*; public class ListReplicas { public static void main(String[] args) { if (args.length != 4) { System.err.println("Usage : java GetEffectivePrivileges <host name>" + " <login dn> <password> <server dn>"); System.err.println("Example: java GetEffectivePrivileges Acme.com" + " cn=admin,o=Acme secret cn=myServer,o=Acme"); System.exit ( -1 ); } try { int ldapPort = LdapCtx.DEFAULT_PORT; String ldapHost = args[0]; String loginDN = args[1]; String password = args[2]; String serverDN = args[3]; Vector replicas; // Create a Hashtable object. Hashtable env = new Hashtable(5, 0.75f); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://" + ldapHost +":" + ldapPort); env.put(Context.SECURITY_AUTHENTICATION, "simple" ); env.put(Context.SECURITY_PRINCIPAL, loginDN ); env.put(Context.SECURITY_CREDENTIALS, passWord ); // Construct a LdapContext object. LdapContext ctx = new InitialLdapContext(env, null); // Call extended operation to retrieve replica.s ListReplicasRequest reqs = new ListReplicasRequest( serverDN ); ListReplicasResponse resp = (ListReplicasResponse) ctx.extendedOperation( reqs ); // Printout the replica(s) if there is any. replicas = resp.getReplicas(); if ( replicas.isEmpty()) { System.out.println("\nThe server object '" + serverDN + "' has no any replicas:"); } else { Enumeration enum = replicas.elements(); System.out.println("\nThe server object '" + serverDN + "' has the following replica(s):"); while ( enum.hasMoreElements() ) System.out.println( enum.nextElement()); } System.out.println("\nListReplicas operation succeeded."); } catch (IOException e) { System.err.println( e.toString() ); e.printStackTrace(); } catch (NamingException e) { System.err.println("ListReplicas operation failed."); e.getExplanation(); e.printStackTrace(); } finally { System.exit(0); } }
Reference for Novell LDAP Extensions and Controls for JNDI
To download the Novell LDAP Extensions and Controls for JNDI, applicable documentation and lots more sample code, see: http://developer.novell.com.
|
 |
 |
 |