Forum Discussion

MarkM_63051's avatar
Icon for Nimbostratus rankNimbostratus
Mar 12, 2012

Password Encoding




I am writing to ask what the appropriate way is to encode a password when locating stubs. The following code snippet was pulled out of an F5 sample file:



m_endpoint = "https://" + args[2] + ":" + args[3] + "@" + args[0] + ":" + args[1] + "/iControl/iControlPortal.cgi";


m_pool = (iControl.LocalLBPoolBindingStub) new iControl.LocalLBPoolLocator().getLocalLBPoolPort(new;



This will work fine as long as the password does not contain special characters such as the ":" character. Will the following code work or is there a better way?



String endpoint = "https://" + URLEncoder.encode(username, "UTF-8") + ":" + URLEncoder.encode(password, "UTF-8") + "@" + URLEncoder.encode(hostname, "UTF-8") + ":" + port + "/iControl/iControlPortal.cgi";







8 Replies

  • Passing the credentials in the URL was something we put as a sample a long long time ago before we had the iControl Library for Java. The proper way is to pass in a WWW-Autheticate HTTP header with an encoded version of the username/password. This is basically how forms based authentication works. I would recommend you go that route and not pass credentials in the URL. The iControl library for Java does just that.



    Could you explain what you are trying to do and why you need to pass the credentials in the URL?



  • I am making Java web service connections to the F5 so I can execute the APIs. Would you please send me a link to the example code you mentioned?
  • The iControl Library for Java can be found in the "iControl Assembly" labs project.


  • I have been using the iControl library for several months now. I was hoping you had some sample code using the iControl methods or can you point me in the right direction.



    Were you referring to something more like this:


    LocalLBPoolBindingStub lblPool =












  • The source distribution includes some test code. Here's some code to get the system information.

    iControl.Interfaces m_interfaces = new iControl.Interfaces();

    m_interfaces.initialize("x.x.x.x", 443, "user", "pass");

    iControl.SystemSystemInformation sysInfo = m_interfaces.getSystemSystemInfo().get_system_information();


    System.out.println(" System Information");


    System.out.println("System Name : " + systemInformation.getSystem_name());

    System.out.println("Host name : " + systemInformation.getHost_name());

    System.out.println("OS Release : " + systemInformation.getOs_release());

    System.out.println("OS Machine : " + systemInformation.getOs_machine());

    The iControl.Interfaces class encapsulates all of the interfaces and bindings long with the connection details.







  • Thanks Joe,


    It worked wonderfully. I removed about 20 lines of code per class and JUnit test. Here is a sample of what I ended up with:


    // Get the master F5 Interface connection object/stub


    iControl.Interfaces f5Iinterfaces = getF5Interfaces();


    f5Iinterfaces.initialize(hostname, 443, username, password);



    public void createOrDeletePool(Properties argProps, Interfaces f5Iinterfaces) {



    // Create the F5 stubs necessary to communicate with it


    LocalLBPoolBindingStub lblPoolStub = f5Iinterfaces.getLocalLBPool();





  • Great, glad I could help and glad I helped clean up your codebase!



    The Interfaces class is not part of the API, but a wrapper I wrote to hide all the messy stuff. The source is in the source package if you want to see what's going on in there. Guess I need to document that a little better moving forward B-).



    BTW, don't hesitate to post any questions that come up. I'm not the best at Java, but know enough to help get you out of trouble.



    Also, our CodeShare section is lacking in good Java code samples. If you have any you'd consider sharing, I'd be glad to pretty them up and put them up for others to use...





  • I would like to let the experts beat on my code and make it better, but I need wait to see what our company lawyers have to say.