cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the UME api in order to search the LDAP?

Former Member
0 Kudos

Hello,

I have an application which connects to the LDAP the portal is connecting to and search users according to a certain search criteria.

Here is the relevant piece of code:

Hashtable env = new Hashtable();
...
DirContext ctx = new InitialDirContext(env);
SearchControls controls = new SearchControls();
String filter = "firstName=..."
NamingEnumeration results = ctx.search("OU=OUs", filter, controls);

I would like to do this same search using the UME API.

Can someone please show me the equivalent code to it using the UME API?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Roy,

I used the following code:

IUserFactory ufact = UMFactory.getUserFactory();

IUserSearchFilter usf = ufact.getUserSearchFilter();

usf.setSearchAttribute( "com.sap.security.core.usermanagement",

"lastname",

theNameToBeSearched, ISearchAttribute.LIKE_OPERATOR, false);

ISearchResult sr = ufact.searchUsers(usf);

In some cases you will have to modify the datasource_configuration.xml to able to search for your company specific attributes of the LDAP.

Regards,

Rebecca

Former Member
0 Kudos

10q Rebecca.

Can you please explain regarding the datasource_configuration.xml file: Where do I find it, Ehat does it use for and how do I modify it?

Former Member
0 Kudos

What I am asking basicly is if I have a costum attribute in my LDAP Schema that I've defined (Let's say MyAttr), I can use the datasource_configuration.xml in order to "tell" the Portal to fetch it from the LDAP? If yes, can you please show me how do I do it at the xml file and then pull this attribute using the UME API?

Former Member
0 Kudos

Anyone...?

Former Member
0 Kudos

Hi Roy,

you find the Configuration File you are using in your portal via System Administration -> System Configuration -> UM Configuration -> Data Sources

or in sapume.properties where you can find

##xml file that configures the persistence except roles
ume.persistence.data_source_configuration=YOUR_DATASOURCE_CONFIG_FILE.xml

.

In this xml file, there is the entry

<principal type="user">:

<principal type="user">

<nameSpaces>

<nameSpace name="com.sap.security.core.usermanagement">

<attributes>

<attribute name="firstname" populateInitially="true"/><attribute name="displayname" populateInitially="true"/> <attribute name="lastname" populateInitially="true"/> <attribute name="fax"/> <attribute name="email"/> <attribute name="title"/> <attribute name="department"/> <attribute name="extensionAttribute2"/> <attribute name="mobile"/> <attribute name="telephone"/> <attribute name="streetaddress"/> <attribute name="pobox"/> <attribute name="location"/> <attribute name="telephoneShort"/> </attributes>

</nameSpace>

<nameSpace name="com.sap.security.core.usermanagement.relation">

<attributes>

<attribute name="PRINCIPAL_RELATION_PARENT_ATTRIBUTE"/>

</attributes>

</nameSpace>

</nameSpaces>

</principal>

According to your company LDAP attributes, you will have to extend the above attributes, telephoneShort for example is an attribute within our company.

The UME API does the rest.

All you have to do, is request the right attribute (in my above example it was the last name).

(Sorry for the format, but it is quite cumbersome to format it properly with the available editor )

Kind regards,

Rebecca

Former Member
0 Kudos

Hello Rebecca,

First, thank you very much for the detailed explanation.

I have a question though:

After I apply the changes the UME API will be automaticly be extracted with the new properties? Can you please show me a code example for that?

Former Member
0 Kudos

Hi Roy,

you simply have to restart your portal,

the UME will read in this xml file.

There is no extra code to be done.

usf.setSearchAttribute( "com.sap.security.core.usermanagement",

<b>"lastname",</b>

theNameToBeSearched, ISearchAttribute.LIKE_OPERATOR, false);

This "lastname" has to be replaced with your custom attribute you have entered into the datasource xml file.

Regards,

Rebecca

Former Member
0 Kudos

Oh what I ment a piece of sample code to get this attribute and put it in an arbitrary String. I beleive it is a basic task but I'm a bit new to UME...

Former Member
0 Kudos

Hi Roy,

ahh.. I understood

for sr see my first post

while (sr.hasNext()) {
   dataVec = new Vector();
   userString = (String) sr.next();
   tempuser = ufact.getUser(userString);
    // -- LASTNAME --
  attributes =	tempuser.getAttribute("com.sap.security.core.usermanagement", "lastname");
 if (attributes != null) {
	dataVec.addElement(attributes[0]);
 } else {
	dataVec.addElement("");
 }
}

Hope this helps...

Bye Rebecca

Former Member
0 Kudos

10X alto

Former Member
0 Kudos

Wait, but I thought that after changing the xml file I'll have new get methods for the custom proprerties, like I now have for getFirstName, getLastName ect...

Am I missing something here?

Former Member
0 Kudos

Hi Roy,

no - this method is generic. You pass in the right/new parameter:

user.getAttributes(("com.sap.security.core.usermanagement", "lastname");

Bye

Rebecca