Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to connect to LDAP over SSL from within websphere application server using JNDI

Avatar of bcisystems
bcisystems asked on
DatabasesJava App ServersJava EE
13 Comments1 Solution3412 ViewsLast Modified:
Hi Experts,

I am trying to connect to LDAPS using JNDI. I am getting the following exception.

javax.naming.CommunicationException: 192.168.*.***:636 [Root exception is java.net.SocketException]

Pl. see the code snippet to see if i am doing anything wrong. Code is run within websphere app server 6.1

Thanks
S
private DirContext getInitialContext(
      String protocol, 
      String hostname, 
      int port,
      String username, 
      String password, 
      String keystore)
	        throws NamingException {

	        String providerURL =
	            new StringBuffer("")
	        		.append(protocol)
	        		.append("://")
	                .append(hostname)
	                .append(":")
	                .append(port)
	                .toString();
	        
	        System.setProperty("javax.net.ssl.keyStore", keystore); 

	        Properties props = new Properties();
	        props.put(Context.INITIAL_CONTEXT_FACTORY,
	                  "com.sun.jndi.ldap.LdapCtxFactory");
	        props.put(Context.PROVIDER_URL, providerURL);

	        if ((username != null) && (!username.equals(""))) {
	            props.put(Context.SECURITY_AUTHENTICATION, "simple");
	            props.put(Context.SECURITY_PRINCIPAL, username);
	            props.put(Context.REFERRAL, "ignore");
	            if(SSLEnabled.equalsIgnoreCase("1"))
	            	props.put(Context.SECURITY_PROTOCOL, "SSL");
	            props.put(Context.SECURITY_CREDENTIALS,
	                ((password == null) ? "" : password));
	        }

	        return new InitialDirContext(props);
	    }
ASKER CERTIFIED SOLUTION
Avatar of Venabili
VenabiliFlag of Bulgaria image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answers