Created On:  21 July 2010

Problem:

Using the SDK, how can I obtain a list of Active Caliber users and their account status? Is it also possible to disabled user accounts using the SDK?

Resolution:

It is possible to list Caliber users and their account status the SDK.  It is also possible to disable and enable accounts using the SDK.

The sample code below shows how to achieve this:

 public static void main( String[] args){
  Session session = null;
  User[] user;
  BufferedReader br;
  String option = "";
  {
  try {
   //login to CaliberRM
   CaliberServer server = new CaliberServer("servername");
   session = server.login( "username", "password");
   System.out.println ("login successful");
   user = session.getUsers();
   
   for(int i = 0; i < user.length; i )
   {
    if(user.isAccountDisabled() == true){
     System.out.println("UserID: " user.getUserIDString());
     System.out.println("Account State: Disabled/Deleted" "\n");
    }
    else{
     System.out.println("UserID: " user.getUserIDString());
     System.out.println("Account State: Active" "\n");
    }
   }
   
   for(int y = 0; y < user.length; y ){
    System.out.println("UserID: " user.getUserIDString());
    System.out.println("Are you sure you want to deactive this users account? y/n : ");
    br = new BufferedReader(new InputStreamReader(System.in));
    
 
    option = br.readLine();
    if (option.equals("y")){
     user.lock();
     user.setAccountDisabled(true);
     user.save();
     user.unlock();
    }
    else if(option.equals("n")){
     user.lock();
     user.setAccountDisabled(false);
     user.save();
     user.unlock();
    }
    else
    {
     System.out.println("Please enter y or n.");
    }
    
    
   }
    
   session.logout();
   System.out.println ("logout successful");
  } catch( Exception e ) {
   e.printStackTrace();
  } finally {
   if ( session != null ) {
    session.logout();
   }
  }

  }
 }
}

Incident #2447024