Package netscape.ldap

Examples of netscape.ldap.LDAPConnection


    // filter darf nicht "" sein sondern null
    if(filter != null && filter.length() == 0) filter = null;
    this._filter    = filter;
   
   
    connection         = new LDAPConnection();
   
  }
View Full Code Here


      name += ".";
  }

  String[] attrs = split(hr.get("attributes"));

  LDAPConnection ld = new LDAPConnection();
  int i = 0;
  StringBuffer sb = new StringBuffer();
  try {
      ld.connect(host, LDAPv2.DEFAULT_PORT, auth, password);

      String dn = hr.get("dn");
      if (dn != null) {
    LDAPEntry entry = ld.read(dn, attrs);

    /*
     * Empirically: An entry != null may be returned even if no
     * match was found.
     */
    if ((entry != null) && (entry.getDN() != null)) {
        shove(hr.request.props, name, entry, attrs);
    }
    return;
      }

      String base = hr.get("base", null);
      String str = hr.get("scope", null);
      int scope = LDAPv2.SCOPE_SUB;
      if ("base".equals(str)) {
    scope = LDAPv2.SCOPE_BASE;
      } else if ("one".equals(str)) {
    scope = LDAPv2.SCOPE_ONE;
      }

      String search = hr.get("search");

      try {
    ld.setOption(LDAPv2.SIZELIMIT,
      Integer.decode(hr.get("limit","1000")));
      } catch (Exception e) {
    System.out.println("Ldap error: " + e);
      }
     
      LDAPSearchResults results = ld.search(base, scope, search, attrs,
        false);
      for (i = 0; results.hasMoreElements(); i++) {
    shove(hr.request.props, name + i + ".", results.next(), attrs);
    sb.append(i).append(' ');
      }

      ld.disconnect();
  } catch (LDAPException e) {
      hr.request.props.put(name + "error", e.errorCodeToString());
      hr.request.props.put(name + "errorCode", "" +e.getLDAPResultCode());
      System.out.println("LDAP error: " + e);
  } finally {
      hr.request.props.put(name + "rows", sb.toString().trim());
      hr.request.props.put(name + "rowcount", "" + i);
      try {
    ld.disconnect();
      } catch (Exception e) {}
  }
    }
View Full Code Here

        if (name.endsWith(".") == false) {
            name += ".";
        }

        LDAPConnection ld = new LDAPConnection();

        try {
            String dn = hr.get("dn");
      if ( hr.get("verify") != null ) {
              ld = new LDAPConnection();
              /* Connect to server */
               ld.connect( host, LDAPv2.DEFAULT_PORT );
              /* Authenticate to the server */
              ld.authenticate( 3, dn, password );
        return;
      }
            ld.connect(host, LDAPv2.DEFAULT_PORT, auth, password);
     


            if (hr.get("search") != null) {
                String base = hr.get("base", null);
                String str = hr.get("scope", null);
                int scope = LDAPv2.SCOPE_SUB;

                if ("base".equals(str)) {
                    scope = LDAPv2.SCOPE_BASE;
                } else if ("one".equals(str)) {
                    scope = LDAPv2.SCOPE_ONE;
                }

                String[] attrs = split(hr.get("attributes"));

                if (dn != null) {
                    LDAPEntry entry = ld.read(dn, attrs);

                    /*
                    
                     * match was found.
                     */
                    if ((entry != null) && (entry.getDN() != null)) {
                        shove(hr.request.props, name, entry, attrs);
                    }

                    return;
                }

                String search = hr.get("search");

                /*
                 * LDAPSearchConstraints sc = ld.getSearchConstraints();
                 * sc.setMaxResults( 0 );
                 * try {
                 * ld.setOption(LDAPv2.SIZELIMIT,
                 * Integer.decode(hr.get("limit","1000")));
                 * } catch (Exception e) {}
                 */
                StringBuffer sb = new StringBuffer();
                LDAPSearchResults results = ld.search(base, scope, search,
                                                      attrs, false);

                for (int i = 0; results.hasMoreElements(); i++) {
                    sb.append(i).append(' ');
                    shove(hr.request.props, name + i + ".", results.next(),
                          attrs);
                }

                hr.request.props.put(name + "rows", sb.toString().trim());
            } else if (hr.get("modattr") != null) {
        // Support delete, modify and add an attribute in one operation
        // .. nodattrs="cn|uid=x" actions="d r a"
        String actions[] = split( hr.get("actions") );
        if ( actions == null ){
          return;
        }
              LDAPModificationSet attrs = new LDAPModificationSet();
                addattrs(hr.get("modattr"), attrs, actions);
        System.out.println ( attrs );
              ld.modify( dn, attrs );
            } else if (hr.get("delete") != null) {
                ld.delete(dn);
            } else if (hr.get("add") != null) {
                String add = hr.get("add");

                System.out.println(add);

                LDAPAttributeSet attrs = new LDAPAttributeSet();
                LDAPAttribute attr = new LDAPAttribute("objectclass");

                for (int i = 0; i < objectclass_values.length; i++) {
                    attr.addValue(objectclass_values[i]);
                }

                attrs.add(attr);

                // The add string will look like this: cn=x,y|sn=u,z|x3=p...

                addattrs(add, attrs, null);
        //        attrs.add(new LDAPAttribute("uid", "x1"));

                LDAPEntry myEntry = new LDAPEntry(dn, attrs);

                System.out.println(myEntry);
                ld.add(myEntry);
            }

            ld.disconnect();
        } catch (LDAPException e) {
            hr.request.props.put(name + "error", e.errorCodeToString());

            if (e.getLDAPResultCode() != LDAPException.NO_SUCH_OBJECT) {
                e.printStackTrace();
            }
        }
        finally {
            try {
                ld.disconnect();
            } catch (Exception e) {}
        }
    }
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( 80, 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

        LOG.debug( testServer + ".host = " + host );

        int port = Integer.parseInt( System.getProperty( testServer + ".port", Integer.toString( DEFAULT_PORT ) ) );
        LOG.debug( testServer + ".port = " + port );

        LDAPConnection conn = new LDAPConnection();
        conn.connect( 3, host, port, admin, password );
        return conn;
    }
View Full Code Here


    public static LDAPConnection getWiredConnection( LdapServer ldapServer, String principalDn, String password )
        throws Exception
    {
        LDAPConnection conn = new LDAPConnection();
        conn.connect( 3, "localhost", ldapServer.getPort(), principalDn, password );
        return conn;
    }
View Full Code Here

        {
            bindPassword = bindPWParam.getStringValue();
        }

        // Create the LDAPConnection object that we will use to communicate with the directory server.
        LDAPConnection conn = new LDAPConnection();

        // Attempt to establish a connection to the directory server.
        try
        {
            outputMessages.add( "Attempting to establish a connection to " + host + ":" + port + "...." );
            conn.connect( host, port );
            outputMessages.add( "Connected successfully." );
            outputMessages.add( "" );
        }
        catch ( Exception e )
        {
            outputMessages.add( "ERROR:  Unable to connect to the directory " + "server:  " + stackTraceToString( e ) );
            return false;
        }

        // Attempt to bind to the directory server using the bind DN and password.
        try
        {
            outputMessages.add( "Attempting to perform an LDAPv3 bind to the " + "directory server with a DN of '"
                + bindDN + "'...." );
            conn.bind( 3, bindDN, bindPassword );
            outputMessages.add( "Bound successfully." );
            outputMessages.add( "" );
        }
        catch ( Exception e )
        {
            try
            {
                conn.disconnect();
            }
            catch ( Exception e2 )
            {
            }

            outputMessages.add( "ERROR:  Unable to bind to the directory server:  " + stackTraceToString( e ) );
            return false;
        }

        // At this point, all tests have passed.  Close the connection and return true.
        try
        {
            conn.disconnect();
        }
        catch ( Exception e )
        {
        }
View Full Code Here

    public void initializeThread( String clientID, String threadID, int collectionInterval, ParameterList parameters )
        throws UnableToRunException
    {
        if ( shareConnections )
        {
            bindConnection = new LDAPConnection();
   
            try
            {
                bindConnection.connect( 3, directoryHost, directoryPort, "", "" );
            }
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.