Package netscape.ldap

Examples of netscape.ldap.LDAPConnection


      System.exit( 1 );
  }

  try {

      LDAPConnection      conn = null;
      Hashtable           env;
      InitialDirContext   ctx = null;
      Importer            importer;
      Exporter            exporter;
      PrintImportListener printer;

      if ( jndi ) {
    env = new Hashtable();
    env.put( Context.INITIAL_CONTEXT_FACTORY, "com.netscape.jndi.ldap.LdapContextFactory" );
    env.put( Context.PROVIDER_URL, "ldap://" + args[ 1 ] );
    env.put( Context.SECURITY_PRINCIPAL, args[ 2 ] );
    env.put( Context.SECURITY_CREDENTIALS, args[ 3 ] );
    ctx = new InitialDirContext( env );
      } else {
    conn = new LDAPConnection();
    conn.connect( args[ 1 ], LDAPv2.DEFAULT_PORT );
    conn.authenticate( args[ 2 ], args[ 3 ] );
      }

      if ( jndi ) {
    importer = new JNDIImporter( ctx );
      } else {
    importer = new MozillaImporter( conn );
      }
      printer = new PrintImportListener( new PrintWriter( System.out, true ) );
      importer.setImportEventListener( printer );
      importer.readImportDescriptor( Test.class.getResourceAsStream( "import.xml" ) );
      importer.importDocument( Test.class.getResourceAsStream( "test.xml" ) );

      if ( jndi ) {
    exporter = new JNDIExporter( ctx );
      } else {
    exporter = new MozillaExporter( conn );
      }
      exporter.readSearchDescriptor( Test.class.getResourceAsStream( "search.xml" ) );
      exporter.setImportDescriptor( importer.getImportDescriptor() );
      exporter.export( System.out, false, true );

      if ( jndi ) {
    ctx.close();
      } else {
    conn.disconnect();
      }

  } catch ( Exception except ) {
      if ( except instanceof ImportExportException ) {
    except = ( (ImportExportException) except).getException();
View Full Code Here


     * Tests delete operation on referral entry with the ManageDsaIT control.
     */
    @Test
    public void testOnReferralWithManageDsaITControl() throws Exception
    {
        LDAPConnection conn = getWiredConnection( ldapServer );
        LDAPConstraints constraints = new LDAPSearchConstraints();
        constraints.setClientControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) );
        constraints.setServerControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) );
        conn.setConstraints( constraints );
       
        // delete success
        conn.delete( "uid=akarasuluref,ou=users,ou=system", constraints );
       
        try
        {
            conn.read( "uid=akarasuluref,ou=users,ou=system", ( LDAPSearchConstraints ) constraints );
            fail( "Should never get here." );
        }
        catch ( LDAPException e )
        {
            assertEquals( ResultCodeEnum.NO_SUCH_OBJECT.getValue(), e.getLDAPResultCode() );
        }
       
        conn.disconnect();
    }
View Full Code Here

     * non-success result code.
     */
    @Test
    public void testOnReferral() throws Exception
    {
        LDAPConnection conn = getWiredConnection( ldapServer );
        LDAPConstraints constraints = new LDAPConstraints();
        constraints.setReferrals( false );
        conn.setConstraints( constraints );
       
        // referrals failure
        LDAPResponseListener listener = null;
        LDAPResponse response = null;

        listener = conn.delete( "uid=akarasuluref,ou=users,ou=system", null, constraints );
        response = listener.getResponse();
        assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() );

        assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] );
        assertEquals( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] );
        assertEquals( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] );

        conn.disconnect();
    }
View Full Code Here

    @Test
    public void testAncestorReferral() throws Exception
    {
        LOG.debug( "" );

        LDAPConnection conn = getWiredConnection( ldapServer );
        LDAPConstraints constraints = new LDAPConstraints();
        conn.setConstraints( constraints );

        // referrals failure
        LDAPResponseListener listener = null;
        LDAPResponse response = null;

        listener = conn.delete( "ou=Computers,uid=akarasuluref,ou=users,ou=system", null, constraints );
        response = listener.getResponse();
        assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() );

        assertEquals( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] );
        assertEquals( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] );
        assertEquals( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] );

        conn.disconnect();
    }
View Full Code Here

     * Tests add operation on referral entry with the ManageDsaIT control.
     */
    @Test
    public void testOnReferralWithManageDsaITControl() throws Exception
    {
        LDAPConnection conn = getWiredConnection( ldapServer );
        LDAPConstraints constraints = new LDAPSearchConstraints();
        constraints.setClientControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) );
        constraints.setServerControls( new LDAPControl( LDAPControl.MANAGEDSAIT, true, new byte[0] ) );
        conn.setConstraints( constraints );
       
        // add success
        LDAPAttributeSet attrSet = new LDAPAttributeSet();
        attrSet.add( new LDAPAttribute( "objectClass", "organizationalUnit" ) );
        attrSet.add( new LDAPAttribute( "ou", "UnderReferral" ) );
        LDAPEntry entry = new LDAPEntry( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system", attrSet );
       
        try
        {
            conn.add( entry, constraints );
            fail();
        }
        catch ( LDAPException le )
        {
            assertEquals( 10, le.getLDAPResultCode() );
        }
       
        try
        {
            conn.read( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system",
                ( LDAPSearchConstraints ) constraints );
            fail();
        }
        catch ( LDAPException le )
        {
           
        }
       
        conn.disconnect();
    }
View Full Code Here

    @Test
    public void testAncestorReferral() throws Exception
    {
        LOG.debug( "" );

        LDAPConnection conn = getWiredConnection( ldapServer );
        LDAPConstraints constraints = new LDAPConstraints();
        conn.setConstraints( constraints );

        // referrals failure
        LDAPAttributeSet attrSet = new LDAPAttributeSet();
        attrSet.add( new LDAPAttribute( "objectClass", "organizationalUnit" ) );
        attrSet.add( new LDAPAttribute( "ou", "UnderReferral" ) );
        LDAPEntry entry = new LDAPEntry( "ou=UnderReferral,ou=Computers,uid=akarasuluref,ou=users,ou=system", attrSet );
       
        LDAPResponseListener listener = conn.add( entry, null, constraints );
        LDAPResponse response = listener.getResponse();
        assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() );

        assertEquals( "ldap://localhost:10389/ou=UnderReferral,ou=Computers,uid=akarasulu,ou=users,ou=system",
            response.getReferrals()[0] );
        assertEquals( "ldap://foo:10389/ou=UnderReferral,ou=Computers,uid=akarasulu,ou=users,ou=system",
            response.getReferrals()[1] );
        assertEquals( "ldap://bar:10389/ou=UnderReferral,ou=Computers,uid=akarasulu,ou=users,ou=system",
            response.getReferrals()[2] );

        conn.disconnect();
    }
View Full Code Here

     * non-success result code.
     */
    @Test
    public void testOnReferral() throws Exception
    {
        LDAPConnection conn = getWiredConnection( ldapServer );
        LDAPConstraints constraints = new LDAPConstraints();
        constraints.setReferrals( false );
        conn.setConstraints( constraints );
       
        // referrals failure

        LDAPAttributeSet attrSet = new LDAPAttributeSet();
        attrSet.add( new LDAPAttribute( "objectClass", "organizationalUnit" ) );
        attrSet.add( new LDAPAttribute( "ou", "UnderReferral" ) );
        LDAPEntry entry = new LDAPEntry( "ou=UnderReferral,uid=akarasuluref,ou=users,ou=system", attrSet );
       
        LDAPResponseListener listener = null;
        LDAPResponse response = null;
        listener = conn.add( entry, null, constraints );
        response = listener.getResponse();

        assertEquals( ResultCodeEnum.REFERRAL.getValue(), response.getResultCode() );

        assertEquals( "ldap://localhost:10389/ou=UnderReferral,uid=akarasulu,ou=users,ou=system", response.getReferrals()[0] );
        assertEquals( "ldap://foo:10389/ou=UnderReferral,uid=akarasulu,ou=users,ou=system", response.getReferrals()[1] );
        assertEquals( "ldap://bar:10389/ou=UnderReferral,uid=akarasulu,ou=users,ou=system", response.getReferrals()[2] );

        conn.disconnect();
    }
View Full Code Here

     *             If something unexpected happens.
     */
    public final void execute()
        throws MojoExecutionException
    {
        final LDAPConnection connection = this.connect();
        try
        {
            final PrintWriter writer = this.getPrintWriter();
            final LDAPWriter ldapWriter = this.openLDAPWriter(writer);
            this.dump(connection, ldapWriter);
            this.closeLDAPWriter(writer, ldapWriter);
            writer.close();
        }
        finally
        {
            try
            {
                connection.disconnect();
            }
            catch (LDAPException e)
            {
                final String message = "Error disconnecting from the LDAP directory server";
                this.getLog().warn(message, e);
View Full Code Here

    public void execute()
        throws MojoExecutionException
    {
        // Connect to the LDAP server

        final LDAPConnection connection = this.connect();

        // Process the LDIF files

        try
        {
            for (int i = 0; i < this.ldapFiles.length; ++i)
            {
                try
                {
                    this.getLog().info("Processing " + this.ldapFiles[i]);
                    final InputStream inputStream = new FileInputStream(
                        this.ldapFiles[i]);
                    final DataInputStream dataInputStream = new DataInputStream(
                        inputStream);
                    final LDIF ldif = new LDIF(dataInputStream);
                    LDIFRecord record = ldif.nextRecord();
                    while (record != null)
                    {
                        this.processRecord(connection, record);
                        record = ldif.nextRecord();
                    }
                }
                catch (LDAPException e)
                {
                    if (!this.continueOnError)
                    {
                        throw new MojoExecutionException("Error processing: "
                            + this.ldapFiles[i], e);
                    }
                    else
                    {
                        this.getLog().warn(
                            "Ignoring error processing: " + this.ldapFiles[i],
                            e);
                    }
                }
                catch (FileNotFoundException e)
                {
                    if (!this.continueOnError)
                    {
                        throw new MojoExecutionException("File not found: "
                            + this.ldapFiles[i], e);
                    }
                    else
                    {
                        this.getLog().warn(
                            "Skipping missing file: " + this.ldapFiles[i], e);
                    }
                }
                catch (IOException e)
                {
                    if (!this.continueOnError)
                    {
                        throw new MojoExecutionException("Error reading from: "
                            + this.ldapFiles[i], e);
                    }
                    else
                    {
                        this.getLog()
                            .warn(
                                "Ignoring error reading from: "
                                    + this.ldapFiles[i], e);
                    }
                }
            }
        }
        finally
        {

            // Disconnect from the LDAP Server

            try
            {
                connection.disconnect();
            }
            catch (LDAPException e)
            {
                this.getLog().warn(
                    "Ignoring error disconnecting from the LDAP server", e);
View Full Code Here

    protected final LDAPConnection connect()
        throws MojoExecutionException
    {
        try
        {
            final LDAPConnection connection = new LDAPConnection();
            connection.connect(this.version, this.host, this.port, this.authDn,
                this.passwd);
            return connection;
        }
        catch (LDAPException e)
        {
View Full Code Here

TOP

Related Classes of netscape.ldap.LDAPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.