javax.naming.ServiceUnavailableException: socket closed

I try to authorize user via LDAP.

public Authentication authenticate(Authentication auth) throws AuthenticationException {
        String username = getUserNameFromAuth(auth);
        String password = auth.getCredentials().toString();
        HelpDescUser userDetails = (HelpDescUser) userDetailsService.loadUserByUsername(username);
        String email = userDetails.getEmail();
        String url = "ldap://" + ldapHost + ":" + port + "/";
        ActiveDirectoryLdapAuthenticationProvider ldapProvider =
                    new ActiveDirectoryLdapAuthenticationProvider(null, url, rootDn);
        ldapProvider.setSearchFilter(filter);
        Authentication authenticate = ldapProvider.authenticate(new UsernamePasswordAuthenticationToken(email, password));
        if (authenticate.isAuthenticated()) {
            return new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities());
        }
}

I receive this:

Caused by: javax.naming.ServiceUnavailableException: okmarket.ru:636; socket closed at java.naming/com.sun.jndi.ldap.Connection.readReply(Connection.java:426) at java.naming/com.sun.jndi.ldap.LdapClient.ldapBind(LdapClient.java:365) at java.naming/com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:214) at java.naming/com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2795) at java.naming/com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:320) at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:192) at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:210) at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:153) at java.naming/com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:83) at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:730) at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305) at java.naming/javax.naming.InitialContext.init(InitialContext.java:236) at java.naming/javax.naming.ldap.InitialLdapContext.(InitialLdapContext.java:154)

What wrong? Is problem in my side, or on LDAP side?

Upvotes: 3

Views: 11763

Answers (3)

Don't worry, I just tried to connect with ldap:// and port 636. Correct way is to make ldaps:// request or to set port 389.

Upvotes: 3

user3438583
user3438583

Reputation: 155

Check whether the LDAP is up or not. Seems like LDAP is Down.

Upvotes: 0

A Harun S
A Harun S

Reputation: 1

Check the server details.Are you able to ping to the server.

Upvotes: 0

Related Questions