break;
}
System.out.println(EOL + "entered passwords differ. Try again...");
}
final UserAider user = new UserAider(args[1]);
user.setPassword(p1);
final String groups = console.readLine("enter groups: ");
final StringTokenizer tok = new StringTokenizer(groups, " ,");
while (tok.hasMoreTokens()) {
final String group = tok.nextToken();
if (group.length() > 0) {
user.addGroup(group);
}
}
mgtService.addAccount(user);
System.out.println("user " + user + " created.");
} catch (final Exception e) {
System.out.println("ERROR: " + e.getMessage());
e.printStackTrace();
}
} else if (args[0].equalsIgnoreCase("users")) {
final UserManagementService mgtService = (UserManagementService) current
.getService("UserManagementService", "1.0");
final Account users[] = mgtService.getAccounts();
System.out.println("User\t\tGroups");
System.out.println("-----------------------------------------");
for (int i = 0; i < users.length; i++) {
System.out.print(users[i].getName() + "\t\t");
final String[] groups = users[i].getGroups();
for (int j = 0; j < groups.length; j++) {
System.out.print(groups[j]);
if (j + 1< groups.length) {
System.out.print(", ");
}
}
System.out.println();
}
} else if (args[0].equalsIgnoreCase("passwd")) {
if (startGUI) {
messageln("command not supported in GUI mode. Please use the \"Edit users\" menu option.");
return true;
}
if (args.length < 2) {
System.out.println("Usage: passwd username");
return true;
}
try {
final UserManagementService mgtService = (UserManagementService) current
.getService("UserManagementService", "1.0");
final Account user = mgtService.getAccount(args[1]);
if (user == null) {
System.out.println("no such user.");
return true;
}
String p1;
String p2;
while (true) {
p1 = console.readLine("password: ", Character.valueOf('*'));
p2 = console.readLine("re-enter password: ", Character.valueOf('*'));
if (p1.equals(p2)) {
break;
}
System.out.println(EOL + "entered passwords differ. Try again...");
}
user.setPassword(p1);
mgtService.updateAccount(user);
properties.setProperty("password", p1);
} catch (final Exception e) {
System.err.println("ERROR: " + e.getMessage());
}