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());
}
} else if (args[0].equalsIgnoreCase("chmod")) {
if (args.length < 2) {
System.out.println("Usage: chmod [resource] mode");
return true;
}
final Collection temp;
if (args.length == 3) {
System.out.println("trying collection: " + args[1]);
temp = current.getChildCollection(args[1]);
if (temp == null) {
System.out.println(EOL + "trying resource: " + args[1]);
final Resource r = current.getResource(args[1]);
if (r != null) {
final UserManagementService mgtService = (UserManagementService) current
.getService("UserManagementService", "1.0");
mgtService.chmod(r, args[2]);
} else {
System.err.println("Resource " + args[1]
+ " not found.");
}
} else {
final UserManagementService mgtService = (UserManagementService) temp
.getService("UserManagementService", "1.0");
mgtService.chmod(args[2]);
}
} else {
final UserManagementService mgtService = (UserManagementService) current
.getService("UserManagementService", "1.0");
mgtService.chmod(args[1]);
}
// re-read current collection
current = DatabaseManager.getCollection(properties
.getProperty("uri")
+ path, properties.getProperty("user"), properties
.getProperty("password"));
getResources();
} else if (args[0].equalsIgnoreCase("chown")) {
if (args.length < 3) {
System.out
.println("Usage: chown username group [resource]");
return true;
}
final Collection temp;
if (args.length == 4) {
temp = current.getChildCollection(args[3]);
} else {
temp = current;
}
if (temp != null) {
final UserManagementService mgtService = (UserManagementService) temp
.getService("UserManagementService", "1.0");
final Account u = mgtService.getAccount(args[1]);
if (u == null) {
System.out.println("unknown user");
return true;
}
mgtService.chown(u, args[2]);
System.out.println("owner changed.");
getResources();
return true;
}
final Resource res = current.getResource(args[3]);
if (res != null) {
final UserManagementService mgtService = (UserManagementService) current
.getService("UserManagementService", "1.0");
final Account u = mgtService.getAccount(args[1]);
if (u == null) {
System.out.println("unknown user");
return true;
}
mgtService.chown(res, u, args[2]);
getResources();
return true;
}
System.err.println("Resource " + args[3] + " not found.");
} else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
if(args.length < 2) {
messageln("Usage: lock resource");
return true;
}
final Resource res = current.getResource(args[1]);
if (res != null) {
final UserManagementService mgtService = (UserManagementService)
current.getService("UserManagementService", "1.0");
final Account user = mgtService.getAccount(properties.getProperty("user", "guest"));
if(args[0].equalsIgnoreCase("lock")) {
mgtService.lockResource(res, user);
} else {
mgtService.unlockResource(res);
}