wood burning stoves 2.0*
The moose likes JBoss/WildFly and the fly likes How to configure LDAP in JBoss AS 7.1.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "How to configure LDAP in JBoss AS 7.1.1" Watch "How to configure LDAP in JBoss AS 7.1.1" New topic
Author

How to configure LDAP in JBoss AS 7.1.1

Nagaraju Nookala
Greenhorn

Joined: Mar 19, 2004
Posts: 23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to configure LDAP in JBoss AS 7.1.1
 
Similar Threads
LDAP Connection - The best practice
LDAP
Active Directory Authentication using java
Query for "ACTIVE" users in LDAP server NOT working
Problem with using dirsyn control with active directory