OIM API To Search Users based on USER_UPDATE Column


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.connection.Platform;

import oracle.iam.identity.exception.UserSearchException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.api.UserManagerConstants;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;

public class SearchUsers {

 public static void main(String args[]) throws UserSearchException, AccessDeniedException, ParseException{
  UserManager userManager = (UserManager) Platform.getService(UserManager.class);
   Date date = new Date();
   long DAY_IN_MS = 1000 * 60 * 60 * 24;
      Date date1 = new Date(date.getTime() - (6*DAY_IN_MS));     // Change value of 6 to how many days less you want.
           
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String onlyDate = sdf.format(date1);

      System.out.println(" Date -> "+onlyDate);      
      
  SearchCriteria criteria = new 
    SearchCriteria(UserManagerConstants.AttributeName.USER_UPDATE.getId(),
      onlyDate,      
    SearchCriteria.Operator.LESS_THAN);  // Try with GREATER_THAN,GREATER_EQUAL,LESS_THAN,LESS_EQUAL,NOT_EQUAL,EQUAL
    //Note Equal and Not-EQUAL works for Date only not timestamp even if you pass TimeStamp.
  List<User> users = userManager.search(criteria, null, null); 
  System.out.println("Size of users -> "+users.size());
  for(User user: users){
   System.out.println(user.getAttribute("usr_update"));
  }
 }
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts