From 9d2c41610a2b3fb71c7e7cf62f4ee0abeeca8c4d Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Sat, 19 May 2012 11:19:07 -0500
Subject: [PATCH] Added group CLI.

This patch provides a tool to manage groups and group members via
command line.

Ticket #160
---
 base/common/src/CMakeLists.txt                     |   10 ++
 base/common/src/com/netscape/cms/cli/MainCLI.java  |    2 +
 .../com/netscape/cms/group/client/AddGroupCLI.java |   78 +++++++++++++
 .../cms/group/client/AddGroupMemberCLI.java        |   54 +++++++++
 .../cms/group/client/FindGroupMemberCLI.java       |  104 +++++++++++++++++
 .../netscape/cms/group/client/FindGroupsCLI.java   |   98 ++++++++++++++++
 .../com/netscape/cms/group/client/GroupCLI.java    |  117 ++++++++++++++++++++
 .../netscape/cms/group/client/GroupRestClient.java |   76 +++++++++++++
 .../netscape/cms/group/client/ModifyGroupCLI.java  |   78 +++++++++++++
 .../netscape/cms/group/client/RemoveGroupCLI.java  |   54 +++++++++
 .../cms/group/client/RemoveGroupMemberCLI.java     |   54 +++++++++
 .../netscape/cms/group/client/ShowGroupCLI.java    |   53 +++++++++
 12 files changed, 778 insertions(+), 0 deletions(-)
 create mode 100644 base/common/src/com/netscape/cms/group/client/AddGroupCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/AddGroupMemberCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/FindGroupMemberCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/FindGroupsCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/GroupCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/GroupRestClient.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/ModifyGroupCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/RemoveGroupCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/RemoveGroupMemberCLI.java
 create mode 100644 base/common/src/com/netscape/cms/group/client/ShowGroupCLI.java

diff --git a/base/common/src/CMakeLists.txt b/base/common/src/CMakeLists.txt
index b35fef384226790bbbaf3b20308a15437b1bcae5..45b1eed071a4c60deacc790827562ebfd75a4c9f 100644
--- a/base/common/src/CMakeLists.txt
+++ b/base/common/src/CMakeLists.txt
@@ -454,6 +454,16 @@ set(pki-cms_java_SRCS
     com/netscape/cms/group/GroupMemberData.java
     com/netscape/cms/group/GroupMemberResource.java
     com/netscape/cms/group/GroupResource.java
+    com/netscape/cms/group/client/AddGroupCLI.java
+    com/netscape/cms/group/client/AddGroupMemberCLI.java
+    com/netscape/cms/group/client/FindGroupMemberCLI.java
+    com/netscape/cms/group/client/FindGroupsCLI.java
+    com/netscape/cms/group/client/GroupCLI.java
+    com/netscape/cms/group/client/GroupRestClient.java
+    com/netscape/cms/group/client/ModifyGroupCLI.java
+    com/netscape/cms/group/client/RemoveGroupCLI.java
+    com/netscape/cms/group/client/RemoveGroupMemberCLI.java
+    com/netscape/cms/group/client/ShowGroupCLI.java
     com/netscape/cms/group/server/GroupMemberResourceService.java
     com/netscape/cms/group/server/GroupResourceService.java
     com/netscape/cms/listeners/PinRemovalListener.java
diff --git a/base/common/src/com/netscape/cms/cli/MainCLI.java b/base/common/src/com/netscape/cms/cli/MainCLI.java
index cc65b93b96a9e53bd36fe0b2a97b4a7117564c41..d5dd0333abf7e36c249cabe91576198730f4b703 100644
--- a/base/common/src/com/netscape/cms/cli/MainCLI.java
+++ b/base/common/src/com/netscape/cms/cli/MainCLI.java
@@ -26,6 +26,7 @@ import org.mozilla.jss.crypto.AlreadyInitializedException;
 import org.mozilla.jss.crypto.CryptoToken;
 import org.mozilla.jss.util.Password;
 
+import com.netscape.cms.group.client.GroupCLI;
 import com.netscape.cms.user.client.UserCLI;
 
 
@@ -49,6 +50,7 @@ public class MainCLI extends CLI {
         super("pki", "PKI command-line interface");
 
         addModule(new UserCLI(this));
+        addModule(new GroupCLI(this));
     }
 
     public String getProtocol() {
diff --git a/base/common/src/com/netscape/cms/group/client/AddGroupCLI.java b/base/common/src/com/netscape/cms/group/client/AddGroupCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..c6c7c05a31251a28261370f72b3dd7a369d2e893
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/AddGroupCLI.java
@@ -0,0 +1,78 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+import com.netscape.cms.group.GroupData;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AddGroupCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public AddGroupCLI(GroupCLI parent) {
+        super("add", "Add group");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "description", true, "Description");
+        option.setArgName("description");
+        options.addOption(option);
+
+        CommandLine cmd = null;
+
+        try {
+            cmd = parser.parse(options, args);
+
+        } catch (Exception e) {
+            System.err.println("Error: " + e.getMessage());
+            printHelp();
+            System.exit(1);
+        }
+
+        String[] cmdArgs = cmd.getArgs();
+
+        if (cmdArgs.length != 1) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = cmdArgs[0];
+
+        GroupData groupData = new GroupData();
+        groupData.setID(groupID);
+        groupData.setDescription(cmd.getOptionValue("description"));
+
+        parent.client.addGroup(groupData);
+
+        MainCLI.printMessage("Added group \""+groupID+"\"");
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/AddGroupMemberCLI.java b/base/common/src/com/netscape/cms/group/client/AddGroupMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..81d9a05461f66bdd53a6443943e4f8419a0d0fd6
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/AddGroupMemberCLI.java
@@ -0,0 +1,54 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AddGroupMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public AddGroupMemberCLI(GroupCLI parent) {
+        super("add-member", "Add group member");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> <Member ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        if (args.length != 2) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = args[0];
+        String memberID = args[1];
+
+        parent.client.addGroupMember(groupID, memberID);
+
+        MainCLI.printMessage("Number of members added 1");
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/FindGroupMemberCLI.java b/base/common/src/com/netscape/cms/group/client/FindGroupMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..af43a3361416ac3f5332049ee2b00bc8921464e1
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/FindGroupMemberCLI.java
@@ -0,0 +1,104 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+import com.netscape.cms.group.GroupMemberCollection;
+import com.netscape.cms.group.GroupMemberData;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class FindGroupMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public FindGroupMemberCLI(GroupCLI parent) {
+        super("find-member", "Find group members");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "start", true, "Page start");
+        option.setArgName("start");
+        options.addOption(option);
+
+        option = new Option(null, "size", true, "Page size");
+        option.setArgName("size");
+        options.addOption(option);
+
+        CommandLine cmd = null;
+
+        try {
+            cmd = parser.parse(options, args);
+
+        } catch (Exception e) {
+            System.err.println("Error: " + e.getMessage());
+            printHelp();
+            System.exit(1);
+        }
+
+        String[] cmdArgs = cmd.getArgs();
+
+        if (cmdArgs.length != 1) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = cmdArgs[0];
+
+        String s = cmd.getOptionValue("start");
+        Integer start = s == null ? null : Integer.valueOf(s);
+
+        s = cmd.getOptionValue("size");
+        Integer size = s == null ? null : Integer.valueOf(s);
+
+        GroupMemberCollection response = parent.client.findGroupMembers(groupID, start, size);
+
+        Collection<GroupMemberData> entries = response.getMembers();
+
+        MainCLI.printMessage(entries.size()+" group member(s) matched");
+
+        boolean first = true;
+
+        for (GroupMemberData groupMemberData : entries) {
+
+            if (first) {
+                first = false;
+            } else {
+                System.out.println();
+            }
+
+            GroupCLI.printGroupMember(groupMemberData);
+        }
+
+        MainCLI.printMessage("Number of entries returned "+entries.size());
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/FindGroupsCLI.java b/base/common/src/com/netscape/cms/group/client/FindGroupsCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..c077b6ff9ee8c279e9efffc5d14f5fc7387b77ef
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/FindGroupsCLI.java
@@ -0,0 +1,98 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+import com.netscape.cms.group.GroupCollection;
+import com.netscape.cms.group.GroupData;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class FindGroupsCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public FindGroupsCLI(GroupCLI parent) {
+        super("find", "Find groups");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " [FILTER] [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "start", true, "Page start");
+        option.setArgName("start");
+        options.addOption(option);
+
+        option = new Option(null, "size", true, "Page size");
+        option.setArgName("size");
+        options.addOption(option);
+
+        CommandLine cmd = null;
+
+        try {
+            cmd = parser.parse(options, args);
+
+        } catch (Exception e) {
+            System.err.println("Error: " + e.getMessage());
+            printHelp();
+            System.exit(1);
+        }
+
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
+        String s = cmd.getOptionValue("start");
+        Integer start = s == null ? null : Integer.valueOf(s);
+
+        s = cmd.getOptionValue("size");
+        Integer size = s == null ? null : Integer.valueOf(s);
+
+        GroupCollection response = parent.client.findGroups(filter, start, size);
+
+        Collection<GroupData> entries = response.getGroups();
+
+        MainCLI.printMessage(entries.size()+" group(s) matched");
+
+        boolean first = true;
+
+        for (GroupData groupData : entries) {
+
+            if (first) {
+                first = false;
+            } else {
+                System.out.println();
+            }
+
+            GroupCLI.printGroup(groupData);
+        }
+
+        MainCLI.printMessage("Number of entries returned "+entries.size());
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/GroupCLI.java b/base/common/src/com/netscape/cms/group/client/GroupCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..c3eb89757078cf5632e571e337e0b9bdbee0c087
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/GroupCLI.java
@@ -0,0 +1,117 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import java.util.Arrays;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+import com.netscape.cms.group.GroupData;
+import com.netscape.cms.group.GroupMemberData;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupCLI extends CLI {
+
+    public MainCLI parent;
+    public GroupRestClient client;
+
+    public GroupCLI(MainCLI parent) {
+        super("group", "Group management commands");
+        this.parent = parent;
+
+        addModule(new FindGroupsCLI(this));
+        addModule(new ShowGroupCLI(this));
+        addModule(new AddGroupCLI(this));
+        addModule(new ModifyGroupCLI(this));
+        addModule(new RemoveGroupCLI(this));
+
+        addModule(new FindGroupMemberCLI(this));
+        addModule(new AddGroupMemberCLI(this));
+        addModule(new RemoveGroupMemberCLI(this));
+    }
+
+    public void printHelp() {
+
+        System.out.println("Commands:");
+
+        int leftPadding = 1;
+        int rightPadding = 25;
+
+        for (CLI module : modules.values()) {
+            String label = name+"-"+module.getName();
+
+            int padding = rightPadding - leftPadding - label.length();
+            if (padding < 1) padding = 1;
+
+            System.out.print(StringUtils.repeat(" ", leftPadding));
+            System.out.print(label);
+            System.out.print(StringUtils.repeat(" ", padding));
+            System.out.println(module.getDescription());
+        }
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        client = new GroupRestClient(parent.url);
+
+        String command = args[0];
+        String[] commandArgs = Arrays.copyOfRange(args, 1, args.length);
+
+        if (command == null) {
+            printHelp();
+            System.exit(1);
+        }
+
+        CLI module = getModule(command);
+        if (module != null) {
+            module.execute(commandArgs);
+
+        } else {
+            System.err.println("Error: Invalid command \""+command+"\"");
+            printHelp();
+            System.exit(1);
+        }
+    }
+
+    public static void printGroup(GroupData groupData) {
+        System.out.println("  Group ID: "+groupData.getID());
+
+        String description = groupData.getDescription();
+        if (!StringUtils.isEmpty(description)) System.out.println("  Description: "+description);
+
+        Link link = groupData.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
+        }
+    }
+
+    public static void printGroupMember(GroupMemberData groupMemberData) {
+        System.out.println("  Member: "+groupMemberData.getID());
+
+        Link link = groupMemberData.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
+        }
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/GroupRestClient.java b/base/common/src/com/netscape/cms/group/client/GroupRestClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..5df4448167720f9e18861e72957fe2c6104a2790
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/GroupRestClient.java
@@ -0,0 +1,76 @@
+//--- BEGIN COPYRIGHT BLOCK ---
+//This program is free software; you can redistribute it and/or modify
+//it under the terms of the GNU General Public License as published by
+//the Free Software Foundation; version 2 of the License.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License along
+//with this program; if not, write to the Free Software Foundation, Inc.,
+//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+//(C) 2012 Red Hat, Inc.
+//All rights reserved.
+//--- END COPYRIGHT BLOCK ---
+package com.netscape.cms.group.client;
+
+import java.net.URISyntaxException;
+
+import com.netscape.cms.group.GroupCollection;
+import com.netscape.cms.group.GroupData;
+import com.netscape.cms.group.GroupMemberCollection;
+import com.netscape.cms.group.GroupMemberResource;
+import com.netscape.cms.group.GroupResource;
+import com.netscape.cms.servlet.csadmin.CMSRestClient;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupRestClient extends CMSRestClient {
+
+    public GroupResource groupClient;
+    public GroupMemberResource groupMemberClient;
+
+    public GroupRestClient(String baseUri) throws URISyntaxException {
+
+        super(baseUri);
+
+        groupClient = createProxy(GroupResource.class);
+        groupMemberClient = createProxy(GroupMemberResource.class);
+    }
+
+    public GroupCollection findGroups(String groupIDFilter, Integer start, Integer size) {
+        return groupClient.findGroups(groupIDFilter, start, size);
+    }
+
+    public GroupData getGroup(String groupID) {
+        return groupClient.getGroup(groupID);
+    }
+
+    public void addGroup(GroupData groupData) {
+        groupClient.addGroup(groupData);
+    }
+
+    public void modifyGroup(String groupID, GroupData groupData) {
+        groupClient.modifyGroup(groupID, groupData);
+    }
+
+    public void removeGroup(String groupID) {
+        groupClient.removeGroup(groupID);
+    }
+
+    public GroupMemberCollection findGroupMembers(String groupID, Integer start, Integer size) {
+        return groupMemberClient.findGroupMembers(groupID, start, size);
+    }
+
+    public void addGroupMember(String groupID, String memberID) {
+        groupMemberClient.addGroupMember(groupID, memberID);
+    }
+
+    public void removeGroupMember(String groupID, String memberID) {
+        groupMemberClient.removeGroupMember(groupID, memberID);
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/ModifyGroupCLI.java b/base/common/src/com/netscape/cms/group/client/ModifyGroupCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..9f8222d8b7d8cdc57d68faab48b76cb099e9be27
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/ModifyGroupCLI.java
@@ -0,0 +1,78 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+import com.netscape.cms.group.GroupData;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ModifyGroupCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public ModifyGroupCLI(GroupCLI parent) {
+        super("mod", "Modify group");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "description", true, "Description");
+        option.setArgName("description");
+        options.addOption(option);
+
+        CommandLine cmd = null;
+
+        try {
+            cmd = parser.parse(options, args);
+
+        } catch (Exception e) {
+            System.err.println("Error: " + e.getMessage());
+            printHelp();
+            System.exit(1);
+        }
+
+        String[] cmdArgs = cmd.getArgs();
+
+        if (cmdArgs.length != 1) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = cmdArgs[0];
+
+        GroupData groupData = new GroupData();
+        groupData.setID(groupID);
+        groupData.setDescription(cmd.getOptionValue("description"));
+
+        parent.client.modifyGroup(groupID, groupData);
+
+        MainCLI.printMessage("Modified group \""+groupID+"\"");
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/RemoveGroupCLI.java b/base/common/src/com/netscape/cms/group/client/RemoveGroupCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..6ca21655e14312cdb523d0c16ca53de5130c4525
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/RemoveGroupCLI.java
@@ -0,0 +1,54 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+public class RemoveGroupCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public RemoveGroupCLI(GroupCLI parent) {
+        super("del", "Remove group");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        if (args.length != 1) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = args[0];
+
+        parent.client.removeGroup(groupID);
+
+        MainCLI.printMessage("Deleted group \""+groupID+"\"");
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/RemoveGroupMemberCLI.java b/base/common/src/com/netscape/cms/group/client/RemoveGroupMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..def87002c81e248e39c4a5f0e280a718c9ea5f99
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/RemoveGroupMemberCLI.java
@@ -0,0 +1,54 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class RemoveGroupMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public RemoveGroupMemberCLI(GroupCLI parent) {
+        super("remove-member", "Remove group member");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> <Member ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        if (args.length != 2) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = args[0];
+        String memberID = args[1];
+
+        parent.client.removeGroupMember(groupID, memberID);
+
+        MainCLI.printMessage("Number of members removed 1");
+    }
+}
diff --git a/base/common/src/com/netscape/cms/group/client/ShowGroupCLI.java b/base/common/src/com/netscape/cms/group/client/ShowGroupCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..909aa9ccd479a2a598b87367be53353d5520225d
--- /dev/null
+++ b/base/common/src/com/netscape/cms/group/client/ShowGroupCLI.java
@@ -0,0 +1,53 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.group.client;
+
+import com.netscape.cms.cli.CLI;
+import com.netscape.cms.group.GroupData;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ShowGroupCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public ShowGroupCLI(GroupCLI parent) {
+        super("show", "Show group");
+        this.parent = parent;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(parent.name + "-" + name + " <Group ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        if (args.length != 1) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String groupID = args[0];
+
+        GroupData groupData = parent.client.getGroup(groupID);
+
+        GroupCLI.printGroup(groupData);
+    }
+}
-- 
1.7.7.6

