Pages

Monday, December 17, 2012

UserManager : Search User Code

Now that we have created users, we can try to search for users.

1) Code

public void searchUser(OIMClient oimclient){
UserManager usrMgr = oimclient.getService(UserManager.class);
Set retAttrs = new HashSet();
retAttrs.add("First Name");
retAttrs.add("Last Name");
retAttrs.add("User Login");
SearchCriteria sc = new SearchCriteria("First Name", "*",Operator.EQUAL);  // Search can use wildcards
List<oracle.iam.identity.usermgmt.vo.User> userList;
try {
userList = usrMgr.search(sc, retAttrs, null);
for(oracle.iam.identity.usermgmt.vo.User user: userList){
System.out.println(user.getAttributes());
}
} catch (UserSearchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

2) Result

Connected
{usr_key=1, User Login=XELSYSADM, Last Name=Administrator, First Name=System}
{usr_key=3, User Login=WEBLOGIC, Last Name=WEBLOGIC, First Name=WEBLOGIC}
{usr_key=4, User Login=OIMINTERNAL, Last Name=OIMINTERNAL, First Name=OIMINTERNAL}
{usr_key=65, User Login=APIUSER1@MAIL.COM, Last Name=APIUser1, First Name=APIUser1}
{usr_key=48, User Login=FNAME1_LNAME1@MAIL.COM, Last Name=LName123, First Name=FName123}
{usr_key=66, User Login=APIUSER0.APIUSER0@ORACLE.COM, Last Name=APIUser0, First Name=APIUser0}
{usr_key=67, User Login=APIUSER@MAIL.COM, Last Name=APIUser, First Name=APIUser}
Disconnected

3) Complex SearchCriteria

If there is a need to create complex searchCriteria, there is a way to combine searchCriteria as below:

SearchCriteria sc1 = new SearchCriteria("First Name", "*",Operator.EQUAL);
SearchCriteria sc2 = new SearchCriteria("Last Name", "*",Operator.EQUAL);
SearchCriteria sc = new SearchCriteria(sc1, sc2, Operator.AND);

1 comment:

  1. Hey hi i am getting error like
    The constructor SearchCriteria(String, String, CatalogSearchCriteria.Operator) is undefined

    ReplyDelete