I was working on a custom component in UCM and AD was used as LDAP . There was a need to send emails to multiple users subscribed to a custom query. I used the below code to fetch the user's email address in UCM component -
private String getIndividualUserEmail(String userId) {
String emailAddress = "";
try {
JpsContextFactory ctxf = JpsContextFactory.getContextFactory();
JpsContext ctx = ctxf.getContext();
IdentityStoreService storeService =
ctx.getServiceInstance(IdentityStoreService.class);
IdentityStore idStore = storeService.getIdmStore();
SimpleSearchFilter simpleFilter =
idStore.getSimpleSearchFilter(UserProfile.USER_NAME,
SimpleSearchFilter.TYPE_EQUAL,
userId);
SearchParameters params =
new SearchParameters(simpleFilter, SearchParameters.SEARCH_USERS_ONLY);
SearchResponse sr = idStore.searchProfiles(params);
System.out.println(sr.getResultCount());
while (sr.hasNext()) {
Identity id = sr.next();
UserProfile profile = (UserProfile)id;
emailAddress = profile.getBusinessEmail();
System.out.println("Email :- " + profile.getBusinessEmail());
}
} catch (JpsException e) {
System.out.println("getIndividualUserEmail : JpsException Occured ");
} catch (IMException e) {
System.out.println("getIndividualUserEmail : IMException Occured ");
}
return emailAddress;
}
Enjoy
private String getIndividualUserEmail(String userId) {
String emailAddress = "";
try {
JpsContextFactory ctxf = JpsContextFactory.getContextFactory();
JpsContext ctx = ctxf.getContext();
IdentityStoreService storeService =
ctx.getServiceInstance(IdentityStoreService.class);
IdentityStore idStore = storeService.getIdmStore();
SimpleSearchFilter simpleFilter =
idStore.getSimpleSearchFilter(UserProfile.USER_NAME,
SimpleSearchFilter.TYPE_EQUAL,
userId);
SearchParameters params =
new SearchParameters(simpleFilter, SearchParameters.SEARCH_USERS_ONLY);
SearchResponse sr = idStore.searchProfiles(params);
System.out.println(sr.getResultCount());
while (sr.hasNext()) {
Identity id = sr.next();
UserProfile profile = (UserProfile)id;
emailAddress = profile.getBusinessEmail();
System.out.println("Email :- " + profile.getBusinessEmail());
}
} catch (JpsException e) {
System.out.println("getIndividualUserEmail : JpsException Occured ");
} catch (IMException e) {
System.out.println("getIndividualUserEmail : IMException Occured ");
}
return emailAddress;
}
Enjoy