troubleshooting Question

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

Avatar of bcisystems
bcisystems asked on
DatabasesJava EEJava App Servers
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);
	    }

Open in new window

ASKER CERTIFIED SOLUTION
Venabili

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

Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros