Forum Discussion
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 java.net.URL(m_endpoint));
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";
Regards,
Mark
- 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.
- MarkM_63051NimbostratusI 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.
- MarkM_63051Nimbostratus
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:
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.out.println(" System Information");
System.out.println("------------------------------------------------------");
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.
-Joe
- MarkM_63051Nimbostratus
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
- Great, glad I could help and glad I helped clean up your codebase!
- MarkM_63051NimbostratusI 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.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com