Results 1 to 9 of 9
  1. #1
    msk20171 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Connect To LDAP Via Proxy

    I currently have the following code to connect to a directory server. I have been told that I need to have the code go through a proxy server (specifically a Squid proxy, if that's relevant). I can't figure out what to change or add in this code to get it to route through the proxy. Any/ all thoughts are welcome.

    String url = "ldap://" + IP + ":" + Port;
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "none");
    env.put(Context.SECURITY_PRINCIPAL, UserID);
    env.put(Context.SECURITY_CREDENTIALS, Password);
    InitialLdapContext ilc = new InitialLdapContext(env,null);

    Thank you

  2. #2
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    //First
    PHP Code:
    Properties system= System.getProperties();
    system.setProperty("http.proxyHost",IP);
    system.setProperty("http.proxyPort",Port);
    //After
    String url = "ldap://" + IP + ":" + Port;
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "none");
    env.put(Context.SECURITY_PRINCIPAL, UserID);
    env.put(Context.SECURITY_CREDENTIALS, Password);
    InitialLdapContext ilc = new InitialLdapContext(env,null);

  3. #3
    msk20171 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    Thank you. I will try this immediately and see how it goes. Thanks for the quick response!

    -M

  4. #4
    msk20171 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    This appears to work, but the problem is that it appears to be forcing all of my code that's running within the JVM to use the proxy. However, I only need to use the proxy for this one function. Is there a way to either restrict the scope of the affected code? Or is there a way to set up a blacklist or whitelist for proxy? Something along the lines of: Every connection to server X or Y goes through the proxy or Every connection to server A or B bypasses the proxy?

  5. #5
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    When finished using the proxy put
    PHP Code:
    System.setProperty("http.proxyHost", null);

  6. #6
    msk20171 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    I thought about that, but I have so many pieces of code running concurrently within that JVM that there's no way to know if something else is trying to connect to another server while this section of the code still has the proxy set. If I code it right, I could minimize the window where that value is set, but I don't think that I'll ever get it so tight that something won't slip through at some point and cause all kinds of confusion.

  7. #7
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    try it and tell us

  8. #8
    arielb is offline Member
    Join Date
    Jan 2012
    Location
    Panamá
    Posts
    41
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    You can check this
    Java Networking and Proxies

  9. #9
    msk20171 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Connect To LDAP Via Proxy

    It looks like the problem is moot. The requirements just changed and it looks like they are going to give me direct access through the firewall. Thanks, Arielb, for your help.

Similar Threads

  1. openConnection(Proxy proxy) question
    By Dark in forum New To Java
    Replies: 8
    Last Post: 12-31-2011, 02:15 PM
  2. do any one has any idea about ldap please help me
    By javastuden in forum Advanced Java
    Replies: 0
    Last Post: 10-08-2011, 02:20 PM
  3. ldap server
    By 435.mahesh in forum Java Software
    Replies: 1
    Last Post: 05-07-2009, 04:28 PM
  4. Http - proxy or non-proxy ?
    By Shiv in forum Networking
    Replies: 0
    Last Post: 04-11-2009, 09:07 AM
  5. CompositeName with LDAP URL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-10-2008, 11:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •