on 05-20-2007 9:30 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.