All you can do is check if there is some user with the same username than the user that is currently logged in your Java application. You won't be able to check anything else without its password. To do this, you'll need the username and password of some ldap user that have permission to list other users. Then you can query the LDAP for your user.
This is an example adapted from something I use, it checks against an active directory, so perhaps it will need some changes:
boolean userFound = user_exits("searchUser",
"searchPassword",
"(sAMAccountName={USERNAME})",
"ldap://ldap.mydomain.com",
"OU=MYOU,dc=mydomain,dc=com");
private boolean user_exits(String searchUser, String searchPassword,
String filter, String url, String baseDn) throws NamingException {
DirContext ctx = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, searchUser);
env.put(Context.SECURITY_CREDENTIALS, searchPassword);
try {
ctx = new InitialDirContext(env);
String[] attributeFilter = {};
SearchControls sc = new SearchControls();
sc.setReturningAttributes(attributeFilter);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> results = ctx.search(baseDn, filter, sc);
return results.hasMore();
} catch (NamingException e) {
throw e;
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {}
}
}
}