cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to LDAP Server

Former Member
0 Kudos

Hi Experts

I am developing a webdynpro application that would contact the LDAP server of my company for the login credentials can u please help out in this issue in need the webdynpro code for this connection

Regards

Noel

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi! Noel,

there are two ways to get connected to LDAP server from your webDynpro application.

1.By Using UME API(right choice in case your portal is connected to the LDAP through UME)

2.By setting some properties of LDAP server in your webdynpro appl.

code sample for first one:--

// Input for search

String input= "sahu";

IUserFactory userFactory = UMFactory.getUserFactory();

IUserSearchFilter searchFilter = userFactory.getUserSearchFilter();

//setting search attributes

searchFilter.setLastname(input,ISearchAttribute.LIKE_OPERATOR,false);

//start search

ISearchResult searchResult = userFactory.searchUsers(searchFilter);

// iterate over search result

while(searchResult.hasNext()) {

//do something

String userID= (String) searchResult.next();

IUser user= userFactory.getUser(userID);

String email= user.getEmail();

//...

}

Code sample for Second One:--

// Connect to server

Hashtable env = new Hashtable();

env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");

env.put("java.naming.provider.url", "ldap://<server_name>");

env.put("java.naming.security.authentication", "simple");

env.put("java.naming.security.principal", "<domain>
<user_name>");

env.put("java.naming.security.credentials", "<password>");

DirContext ctx = new InitialDirContext(env);

// Create search controls

SearchControls controls = new SearchControls();

controls.setCountLimit(0);

controls.setTimeLimit(0);

controls.setSearchScope(SearchControls.SUBTREE_SCOPE);

// Create filter

String filter = "(sAMAccountName= *)"

// Run search

NamingEnumeration results = ctx.search("OU=OUs,DC=mycomp,DC=com", filter, controls);

i got this example from one SDN blog only but forget the link.

regards,

mithileshwar

Former Member
0 Kudos

check this: