private static final String ACTION_LSROLE = "LSROLE";
public void process() throws dbXMLException {
CollectionClient col = (CollectionClient)cl.getProperty(CommandLine.COLLECTION);
if ( col == null )
throw new dbXMLException("Collection context required");
AccessManagerClient manager = new AccessManagerClient(cl.getClient());
PrintWriter pw = cl.getWriter();
if ( !cl.hasMoreTokens() )
throw new dbXMLException("User ID is required");
String userID = cl.getNextToken();
if ( !cl.hasMoreTokens() )
throw new dbXMLException("A User action must be specified");
String action = cl.getNextToken().toUpperCase();
if ( action.equals(ACTION_PASSWORD) ) {
if ( !cl.hasMoreTokens() )
throw new dbXMLException("A new password must be specified");
String password = cl.getNextToken();
manager.setUserPassword(userID, password);
pw.println("Password set for '"+userID+"'");
}
else if ( action.equals(ACTION_ADDROLE) ) {
if ( !cl.hasMoreTokens() )
throw new dbXMLException("A Role ID must be specified");
String roleID = cl.getNextToken();
manager.addRoleToUser(userID, roleID);
pw.println("Role '"+roleID+"' added to User '"+userID+"'");
}
else if ( action.equals(ACTION_RMROLE) ) {
if ( !cl.hasMoreTokens() )
throw new dbXMLException("A Role ID must be specified");
String roleID = cl.getNextToken();
manager.removeRoleFromUser(userID, roleID);
pw.println("Role '"+roleID+"' removed from User '"+userID+"'");
}
else if ( action.equals(ACTION_LSROLE) ) {
String[] list = manager.listRolesForUser(userID);
int count = 0;
for ( int i = 0; i < list.length; i++ ) {
pw.println(list[i]);
count++;
}
if ( cl.isPropertyTrue(CommandLine.TOTALS) ) {
if ( count > 0 )
pw.println("-----------------------");
if ( count != 1 )
pw.println(count + " Roles");
else
pw.println(count + " Role");
}
}
else
throw new dbXMLException("Unknown action '"+action+"'");
}