From 509e43542bd2d6d20dabaf9dc80ff4308a10e7ff 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 ++
 .../src/com/netscape/cms/client/cli/MainCLI.java   |    2 +
 .../com/netscape/cms/client/group/GroupAddCLI.java |   81 +++++++++++++
 .../cms/client/group/GroupAddMemberCLI.java        |   57 ++++++++++
 .../com/netscape/cms/client/group/GroupCLI.java    |  118 ++++++++++++++++++++
 .../netscape/cms/client/group/GroupFindCLI.java    |   98 ++++++++++++++++
 .../cms/client/group/GroupFindMemberCLI.java       |  104 +++++++++++++++++
 .../netscape/cms/client/group/GroupModifyCLI.java  |   80 +++++++++++++
 .../netscape/cms/client/group/GroupRemoveCLI.java  |   54 +++++++++
 .../cms/client/group/GroupRemoveMemberCLI.java     |   54 +++++++++
 .../netscape/cms/client/group/GroupRestClient.java |   92 +++++++++++++++
 .../netscape/cms/client/group/GroupShowCLI.java    |   53 +++++++++
 .../cms/client/group/GroupShowMemberCLI.java       |   54 +++++++++
 13 files changed, 857 insertions(+), 0 deletions(-)
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupAddCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupAddMemberCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupFindCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupFindMemberCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupModifyCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupRemoveCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupRemoveMemberCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupRestClient.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupShowCLI.java
 create mode 100644 base/common/src/com/netscape/cms/client/group/GroupShowMemberCLI.java

diff --git a/base/common/src/CMakeLists.txt b/base/common/src/CMakeLists.txt
index 42a3a54ed43f9a3b5b5e6ef6312d1df0f7985fcf..7b73a8536c1c282e3491122f148cea456cbc4603 100644
--- a/base/common/src/CMakeLists.txt
+++ b/base/common/src/CMakeLists.txt
@@ -459,6 +459,16 @@ set(pki-certsrv_java_SRCS
 set(pki-cms_java_SRCS
     com/netscape/cms/client/cli/CLI.java
     com/netscape/cms/client/cli/MainCLI.java
+    com/netscape/cms/client/group/GroupAddCLI.java
+    com/netscape/cms/client/group/GroupAddMemberCLI.java
+    com/netscape/cms/client/group/GroupFindMemberCLI.java
+    com/netscape/cms/client/group/GroupFindCLI.java
+    com/netscape/cms/client/group/GroupCLI.java
+    com/netscape/cms/client/group/GroupRestClient.java
+    com/netscape/cms/client/group/GroupModifyCLI.java
+    com/netscape/cms/client/group/GroupRemoveCLI.java
+    com/netscape/cms/client/group/GroupRemoveMemberCLI.java
+    com/netscape/cms/client/group/GroupShowCLI.java
     com/netscape/cms/client/user/UserAddCertCLI.java
     com/netscape/cms/client/user/UserAddCLI.java
     com/netscape/cms/client/user/UserCLI.java
diff --git a/base/common/src/com/netscape/cms/client/cli/MainCLI.java b/base/common/src/com/netscape/cms/client/cli/MainCLI.java
index 96e1ea1ee093d0c22a6ab02d5fd5431b435bff27..4932fb183b3bff34c5a61b40b2e221df06124ae0 100644
--- a/base/common/src/com/netscape/cms/client/cli/MainCLI.java
+++ b/base/common/src/com/netscape/cms/client/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.client.group.GroupCLI;
 import com.netscape.cms.client.user.UserCLI;
 
 /**
@@ -48,6 +49,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/client/group/GroupAddCLI.java b/base/common/src/com/netscape/cms/client/group/GroupAddCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..f32fffd5d20aa584ea083c86bd5e05aec1277c0f
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupAddCLI.java
@@ -0,0 +1,81 @@
+// --- 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.client.group;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.group.GroupData;
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupAddCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupAddCLI(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");
+        option.setRequired(true);
+        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"));
+
+        groupData = parent.client.addGroup(groupData);
+
+        MainCLI.printMessage("Added group \""+groupID+"\"");
+
+        GroupCLI.printGroup(groupData);
+    }
+}
diff --git a/base/common/src/com/netscape/cms/client/group/GroupAddMemberCLI.java b/base/common/src/com/netscape/cms/client/group/GroupAddMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..965ad4ee9755d7dd5582f9ec4e42acae6c9172e5
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupAddMemberCLI.java
@@ -0,0 +1,57 @@
+// --- 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.client.group;
+
+import com.netscape.certsrv.group.GroupMemberData;
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupAddMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupAddMemberCLI(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];
+
+        GroupMemberData groupMemberData = parent.client.addGroupMember(groupID, memberID);
+
+        MainCLI.printMessage("Added group member \""+memberID+"\"");
+
+        GroupCLI.printGroupMember(groupMemberData);
+    }
+}
diff --git a/base/common/src/com/netscape/cms/client/group/GroupCLI.java b/base/common/src/com/netscape/cms/client/group/GroupCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..26e2c7123234e6ae0385f6b38816fce8fc54be20
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupCLI.java
@@ -0,0 +1,118 @@
+// --- 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.client.group;
+
+import java.util.Arrays;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.group.GroupData;
+import com.netscape.certsrv.group.GroupMemberData;
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @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 GroupFindCLI(this));
+        addModule(new GroupShowCLI(this));
+        addModule(new GroupAddCLI(this));
+        addModule(new GroupModifyCLI(this));
+        addModule(new GroupRemoveCLI(this));
+
+        addModule(new GroupFindMemberCLI(this));
+        addModule(new GroupShowMemberCLI(this));
+        addModule(new GroupAddMemberCLI(this));
+        addModule(new GroupRemoveMemberCLI(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 + "/pki", parent.certNickname);
+
+        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/client/group/GroupFindCLI.java b/base/common/src/com/netscape/cms/client/group/GroupFindCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..41263c7b92c10b3dbc2516f9d412df7e5b185b77
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupFindCLI.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.client.group;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.group.GroupCollection;
+import com.netscape.certsrv.group.GroupData;
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupFindCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupFindCLI(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/client/group/GroupFindMemberCLI.java b/base/common/src/com/netscape/cms/client/group/GroupFindMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..ca8273270384fd5d7377f2334d1b0e701e121ff7
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupFindMemberCLI.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.client.group;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.group.GroupMemberCollection;
+import com.netscape.certsrv.group.GroupMemberData;
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupFindMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupFindMemberCLI(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/client/group/GroupModifyCLI.java b/base/common/src/com/netscape/cms/client/group/GroupModifyCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..b2b5c8553b19cfb3cf73baa2ebafa611284dc931
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupModifyCLI.java
@@ -0,0 +1,80 @@
+// --- 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.client.group;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.group.GroupData;
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupModifyCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupModifyCLI(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"));
+
+        groupData = parent.client.modifyGroup(groupID, groupData);
+
+        MainCLI.printMessage("Modified group \""+groupID+"\"");
+
+        GroupCLI.printGroup(groupData);
+    }
+}
diff --git a/base/common/src/com/netscape/cms/client/group/GroupRemoveCLI.java b/base/common/src/com/netscape/cms/client/group/GroupRemoveCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..45e779860cedf1640231021e86a8de6bb4bdec57
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupRemoveCLI.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.client.group;
+
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupRemoveCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupRemoveCLI(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/client/group/GroupRemoveMemberCLI.java b/base/common/src/com/netscape/cms/client/group/GroupRemoveMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..25807ae31cb3f04badd46efb90f7a0847cf67fc1
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupRemoveMemberCLI.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.client.group;
+
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupRemoveMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupRemoveMemberCLI(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("Deleted group member \""+memberID+"\"");
+    }
+}
diff --git a/base/common/src/com/netscape/cms/client/group/GroupRestClient.java b/base/common/src/com/netscape/cms/client/group/GroupRestClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5070a447dec5d381d51555c3860f9f832015c36
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupRestClient.java
@@ -0,0 +1,92 @@
+//--- 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.client.group;
+
+import java.net.URISyntaxException;
+
+import org.jboss.resteasy.client.ClientResponse;
+
+import com.netscape.certsrv.group.GroupCollection;
+import com.netscape.certsrv.group.GroupData;
+import com.netscape.certsrv.group.GroupMemberCollection;
+import com.netscape.certsrv.group.GroupMemberData;
+import com.netscape.certsrv.group.GroupMemberResource;
+import com.netscape.certsrv.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 {
+        this(baseUri, null);
+    }
+
+    public GroupRestClient(String baseUri, String nickname) throws URISyntaxException {
+        super(baseUri, nickname);
+
+        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 GroupData addGroup(GroupData groupData) {
+        @SuppressWarnings("unchecked")
+        ClientResponse<GroupData> response = (ClientResponse<GroupData>)groupClient.addGroup(groupData);
+        return response.getEntity();
+    }
+
+    public GroupData modifyGroup(String groupID, GroupData groupData) {
+        @SuppressWarnings("unchecked")
+        ClientResponse<GroupData> response = (ClientResponse<GroupData>)groupClient.modifyGroup(groupID, groupData);
+        return response.getEntity();
+    }
+
+    public void removeGroup(String groupID) {
+        groupClient.removeGroup(groupID);
+    }
+
+    public GroupMemberCollection findGroupMembers(String groupID, Integer start, Integer size) {
+        return groupMemberClient.findGroupMembers(groupID, start, size);
+    }
+
+    public GroupMemberData getGroupMember(String groupID, String memberID) {
+        return groupMemberClient.getGroupMember(groupID, memberID);
+    }
+
+    public GroupMemberData addGroupMember(String groupID, String memberID) {
+        @SuppressWarnings("unchecked")
+        ClientResponse<GroupMemberData> response = (ClientResponse<GroupMemberData>)groupMemberClient.addGroupMember(groupID, memberID);
+        return response.getEntity();
+    }
+
+    public void removeGroupMember(String groupID, String memberID) {
+        groupMemberClient.removeGroupMember(groupID, memberID);
+    }
+}
diff --git a/base/common/src/com/netscape/cms/client/group/GroupShowCLI.java b/base/common/src/com/netscape/cms/client/group/GroupShowCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..59a4a07de44654d5fd390aba81c2e7044983fe34
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupShowCLI.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.client.group;
+
+import com.netscape.certsrv.group.GroupData;
+import com.netscape.cms.client.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupShowCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupShowCLI(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);
+    }
+}
diff --git a/base/common/src/com/netscape/cms/client/group/GroupShowMemberCLI.java b/base/common/src/com/netscape/cms/client/group/GroupShowMemberCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..7490799bd7aa5d233ab7988177a227a8a1920e58
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/group/GroupShowMemberCLI.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.client.group;
+
+import com.netscape.certsrv.group.GroupMemberData;
+import com.netscape.cms.client.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class GroupShowMemberCLI extends CLI {
+
+    public GroupCLI parent;
+
+    public GroupShowMemberCLI(GroupCLI parent) {
+        super("show-member", "Show 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];
+
+        GroupMemberData groupMemberData = parent.client.getGroupMember(groupID, memberID);
+
+        GroupCLI.printGroupMember(groupMemberData);
+    }
+}
-- 
1.7.7.6

