cancel
Showing results for 
Search instead for 
Did you mean: 

Access Active Directory

Former Member
0 Kudos

Hi Experts,

I am having a webdynpro application that is used to send mails. Now I want to have a dropdown list for the 'To' input field. This will have the list of all email addresses in the active directory. Can any body suggest me how do i go about it. A code sample will be really helpful

Regards

Abdullah

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you should connect the UME of the SAP J2EE Engine to your ADS if you have not already done this. How to do this is shown here:

http://help.sap.com/saphelp_nw04s/helpdata/en/12/7678123c96814bada2c8632d825443/frameset.htm

Then you can access the UME and do a search for a user and request the e-mail adresses directly from the objects in the UME.


// Input for search
String input= "Ismail";

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();
   //...
}

Hope it helps, best regards,

Stefan Brauneis

Former Member
0 Kudos

Yes, I forgot to mention that my method is the right choice in case your portal is not connected to the LDAP through UME.

In case it is, use Stefan's suggestions.

Roy

former_member312910
Participant
0 Kudos

Hi all

I have configured my LDAP as a read only data source. I tried the method suggested by Stefan and i got the users. It displays all the users from UME and LDAP. Is it possible to filter out the users of LDAP only from the superset?

thanks in advance

Deepu

Former Member
0 Kudos

hi Deepu,

You can differentiate the users by checking their unique id. UME users will have an id like

USER.PRIVATE_DATASOURCE.un:<userid> as compared to LDAP users USER.CORP_LDAP.<userid>.

You can further filter the user list by checking the pattern of either of them and create a new list of LDAP users.

Regards

Prakash

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Abdullah,

Here is a code sample of how to connect to an LDAP server:


// 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);

You will need of course to adjust to code according to your server parameter and needs, this is just to give you an idea of how to do it.

Also, have a look at these useful tutorials and code samples:

http://java.sun.com/products/jndi/tutorial/ldap/

http://www.javaworld.com/jw-03-2000/ldap/DifferentSearches.java.html

Hope it helps,

Roy

Message was edited by:

Roy Cohen