Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to configure LDAP in JBoss AS 7.1.1

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I configure LDAP server connection in JBoss AS 7.1.1. I won't be using LDAP for authenticating the users logging in to the web application. I need to query the LDAP server configured in JBoss AS 7.1.1 (standalone.xml file is used for this, I guess), using a java class to retrieve the user information.

I have the following code that I use without using JBoss configuration, which works fine:

public class LdapContextCreation {
public static void main(String[] args) {
LdapContextCreation ldapContxCrtn = new LdapContextCreation();
LdapContext ctx = ldapContxCrtn.getLdapContext();
}
public LdapContext getLdapContext(){
LdapContext ctx = null;
try{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager, dc=maxcrc,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "secret");
env.put(Context.PROVIDER_URL, "ldap://localhost:389";);
ctx = new InitialLdapContext(env, null);
System.out.println("Connection Successful.");
String base = "ou=People,dc=maxcrc,dc=com";
SearchControls sc = new SearchControls();
String[] attributeFilter = { "cn", "mail", "givenName", "sn", "initials", "telephoneNumber" };
sc.setReturningAttributes(attributeFilter);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);

String filter = "(&(sn=N*))";

NamingEnumeration results = ctx.search(base, filter, sc);
while (results.hasMore()) {
SearchResult sr = (SearchResult) results.next();
Attributes attrs = sr.getAttributes();

Attribute attr = attrs.get("cn");
System.out.print("Common Name: " + attr.get());
attr = attrs.get("mail");
System.out.print("\nEmail Address: " + attr.get());
attr = attrs.get("givenName");
System.out.print("\nGiven Name: " + attr.get());
attr = attrs.get("sn");
System.out.print("\nSurname: " + attr.get());
attr = attrs.get("initials");
System.out.print("\nInitials: " + attr.get());
attr = attrs.get("telephoneNumber");
System.out.println("\nTelephone Number: " + attr.get());
}

}catch(NamingException nex){
System.out.println("LDAP Connection: FAILED");
nex.printStackTrace();
}
return ctx;
}

}


Can somebody please help me how to configure LDAP server in JBoss AS 7.1.1 and how can that be read by a java class to connect to the LDAP server to retrieve the user information. I also read about 'SecureIdentityLogin' module to encrypt the password. Can somebody please help me in using the encrypted password in the configuration.

Thanks in advance for the help.
Nookala.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic