Single LDAP java login on Liberty server

I want to implement Single Sign on a Websphere-Liberty server using Java. I want to authenticate users using LDAP.

I searched a lot, but could not find an exact example. I also checked every available stack overflow example. but no luck.

It would be great if you could provide demo or sample code for it.

Thanks in advance.

update: I was able to implement the same with waffle .. but waffle does not work with Linux / Unix ... can someone help me?

+6
source share
3 answers

waffle dosent * nix. JASS ( Java SE 8) Krb5LoginModule, .

+3

LDAP, Basic. , "" " base64_token".

base64 - , base64 username: password. . , . SPNEGO.

LDAP JAVA:

public class Main
{
  public static void main(String[] args)
  {
    //Replace username and password with your username and password
    token = Base64.getEncoder().encodeToString((username + ":" + password).getBytes())
    conn = (HttpURLConnection) endpoint.openConnection();

    // Set the necessary header fields, which in this case is Basic
    conn.addRequestProperty("Authorization", "Basic " + token);

   //Continue to do what you want to do after this. This should authenticate 
  // you to the server
  }
}
+1

. , .

Ldap spring mvc java :

    String username = login.getUsername();// "ancb";
    String password = login.getPassword();// "*****";
    String base = "OU=******,DC=InfoDir,DC=DEV,DC=****";
    String dn = "CN=" + username + "," + base;
    String ldapURL = "ldaps://****.systems.**.****:3269";

    // Setup environment for authenticating
    Hashtable<String, String> environment = new Hashtable<String, String>();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    environment.put(Context.PROVIDER_URL, ldapURL);
    environment.put(Context.SECURITY_AUTHENTICATION, "simple");
    environment.put(Context.SECURITY_PRINCIPAL, dn);
    environment.put(Context.SECURITY_CREDENTIALS, password);

    String dynamicLdapaccount = "(CN="+ username +")" ;

        DirContext authContext = new InitialDirContext(environment);

:

U need to configure Kerberos and Spnego at the server level. for a freedom server, its server.xml needs to be modified.

+1
source

All Articles