Posts

LDAP Code to connect LDAP Server using Java and Retrieve User Groups

  public List<String> getUserGroupsfromLDAP(HttpServletRequest request, String userName) throws GeneralSecurityException { LOG.info("Using LDAP to lookup User Groups. Current connection string - " + LDAP_IP); //Create the env variable to user for the connection to the LDAP server Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, LDAP_IP); LOG.info("Current Authentication string - User " + LDAP_USER + " and Password " + LDAP_PASSWORD); //Add the Authentication to the env variable. if (StringUtils.isNotBlank(LDAP_USER)) { env.put(Context.SECURITY_AUTHENTICATION, LDAP_AUTHENTICATION_TYPE); env.put(Context.SECURITY_PRINCIPAL, LDAP_USER); env.put(Context.SECURITY_CREDENTIALS, LDAP_PASSWORD); } else { LOG.info("No LDAP user property specified.  Authenticator will att...