From a847bcb7c71836f7c0498163e31238f118740339 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 26 Aug 2013 13:21:58 -0400 Subject: Reorganized TPS classes. The TPS classes have been reorganized as follows: * common: com.netscape.certsrv.tps * CLI: com.netscape.cmstools.tps * server: org.dogtagpki.server.tps TPSConnection and TPSMessage were moved from server package into common package. The build script and configuration files have been modified accordingly. --- .../src/com/netscape/cmstools/cli/TPSCLI.java | 2 +- .../com/netscape/cmstools/token/TokenAddCLI.java | 81 ------------------- .../src/com/netscape/cmstools/token/TokenCLI.java | 90 --------------------- .../com/netscape/cmstools/token/TokenFindCLI.java | 94 ---------------------- .../netscape/cmstools/token/TokenModifyCLI.java | 81 ------------------- .../netscape/cmstools/token/TokenRemoveCLI.java | 53 ------------ .../com/netscape/cmstools/token/TokenShowCLI.java | 56 ------------- .../netscape/cmstools/tps/token/TokenAddCLI.java | 81 +++++++++++++++++++ .../com/netscape/cmstools/tps/token/TokenCLI.java | 90 +++++++++++++++++++++ .../netscape/cmstools/tps/token/TokenFindCLI.java | 94 ++++++++++++++++++++++ .../cmstools/tps/token/TokenModifyCLI.java | 81 +++++++++++++++++++ .../cmstools/tps/token/TokenRemoveCLI.java | 53 ++++++++++++ .../netscape/cmstools/tps/token/TokenShowCLI.java | 56 +++++++++++++ 13 files changed, 456 insertions(+), 456 deletions(-) delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java (limited to 'base/java-tools/src/com') diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java index 8f740662c..2f28ada7d 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java @@ -22,8 +22,8 @@ import com.netscape.certsrv.client.Client; import com.netscape.certsrv.tps.TPSClient; import com.netscape.cmstools.group.GroupCLI; import com.netscape.cmstools.logging.ActivityCLI; -import com.netscape.cmstools.token.TokenCLI; import com.netscape.cmstools.tps.cert.TPSCertCLI; +import com.netscape.cmstools.tps.token.TokenCLI; import com.netscape.cmstools.user.UserCLI; /** diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java deleted file mode 100644 index 10405a906..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java +++ /dev/null @@ -1,81 +0,0 @@ -// --- 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) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.token; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenAddCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenAddCLI(TokenCLI tokenCLI) { - super("add", "Add token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void execute(String[] args) throws Exception { - - Option option = new Option(null, "user", true, "User ID"); - option.setArgName("User ID"); - 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 tokenID = cmdArgs[0]; - - TokenData tokenData = new TokenData(); - tokenData.setID(tokenID); - tokenData.setUserID(cmd.getOptionValue("user")); - - tokenData = tokenCLI.tokenClient.addToken(tokenData); - - MainCLI.printMessage("Added token \"" + tokenID + "\""); - - TokenCLI.printToken(tokenData); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java deleted file mode 100644 index 14e54af3d..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java +++ /dev/null @@ -1,90 +0,0 @@ -// --- 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) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.token; - -import java.util.Arrays; - -import org.jboss.resteasy.plugins.providers.atom.Link; - -import com.netscape.certsrv.token.TokenClient; -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; - -/** - * @author Endi S. Dewata - */ -public class TokenCLI extends CLI { - - public TokenClient tokenClient; - - public TokenCLI(CLI parent) { - super("token", "Token management commands", parent); - - addModule(new TokenAddCLI(this)); - addModule(new TokenFindCLI(this)); - addModule(new TokenModifyCLI(this)); - addModule(new TokenRemoveCLI(this)); - addModule(new TokenShowCLI(this)); - } - - public void execute(String[] args) throws Exception { - - client = parent.getClient(); - tokenClient = (TokenClient)parent.getClient("token"); - - if (args.length == 0) { - printHelp(); - System.exit(1); - } - - 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 printToken(TokenData token) { - System.out.println(" Token ID: " + token.getID()); - if (token.getUserID() != null) System.out.println(" User ID: " + token.getUserID()); - if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus()); - if (token.getReason() != null) System.out.println(" Reason: " + token.getReason()); - if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID()); - if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo()); - if (token.getCreateTimestamp() != null) System.out.println(" Date Created: " + token.getCreateTimestamp()); - if (token.getModifyTimestamp() != null) System.out.println(" Date Modified: " + token.getModifyTimestamp()); - - Link link = token.getLink(); - if (verbose && link != null) { - System.out.println(" Link: " + link.getHref()); - } - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java deleted file mode 100644 index b1fa04f47..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java +++ /dev/null @@ -1,94 +0,0 @@ -// --- 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) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.token; - -import java.util.Collection; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.token.TokenCollection; -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenFindCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenFindCLI(TokenCLI tokenCLI) { - super("find", "Find tokens", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [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 s = cmd.getOptionValue("start"); - Integer start = s == null ? null : Integer.valueOf(s); - - s = cmd.getOptionValue("size"); - Integer size = s == null ? null : Integer.valueOf(s); - - TokenCollection result = tokenCLI.tokenClient.findTokens(start, size); - Collection tokens = result.getEntries(); - - MainCLI.printMessage(tokens.size() + " token(s) matched"); - - boolean first = true; - - for (TokenData tokenData : tokens) { - - if (first) { - first = false; - } else { - System.out.println(); - } - - TokenCLI.printToken(tokenData); - } - - MainCLI.printMessage("Number of entries returned " + tokens.size()); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java deleted file mode 100644 index 29f1a0741..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java +++ /dev/null @@ -1,81 +0,0 @@ -// --- 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) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.token; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenModifyCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenModifyCLI(TokenCLI tokenCLI) { - super("mod", "Modify token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void execute(String[] args) throws Exception { - - Option option = new Option(null, "user", true, "User ID"); - option.setArgName("User ID"); - 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 tokenID = cmdArgs[0]; - - TokenData tokenData = new TokenData(); - tokenData.setID(tokenID); - tokenData.setUserID(cmd.getOptionValue("user")); - - tokenData = tokenCLI.tokenClient.updateToken(tokenID, tokenData); - - MainCLI.printMessage("Modified token \"" + tokenID + "\""); - - TokenCLI.printToken(tokenData); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java deleted file mode 100644 index 4e986313c..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java +++ /dev/null @@ -1,53 +0,0 @@ -// --- 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) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.token; - -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenRemoveCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenRemoveCLI(TokenCLI tokenCLI) { - super("del", "Remove token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " ", options); - } - - public void execute(String[] args) throws Exception { - - if (args.length != 1) { - printHelp(); - System.exit(1); - } - - String tokenID = args[0]; - - tokenCLI.tokenClient.removeToken(tokenID); - - MainCLI.printMessage("Deleted token \"" + tokenID + "\""); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java deleted file mode 100644 index 4f074f60f..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java +++ /dev/null @@ -1,56 +0,0 @@ -// --- 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) 2013 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package com.netscape.cmstools.token; - -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenShowCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenShowCLI(TokenCLI tokenCLI) { - super("show", "Show token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " ", options); - } - - public void execute(String[] args) throws Exception { - - if (args.length != 1) { - printHelp(); - System.exit(1); - } - - String tokenID = args[0]; - - TokenData tokenData = tokenCLI.tokenClient.getToken(tokenID); - - MainCLI.printMessage("Token \"" + tokenID + "\""); - - TokenCLI.printToken(tokenData); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java new file mode 100644 index 000000000..0d495ddc7 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.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) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.tps.token; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenAddCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenAddCLI(TokenCLI tokenCLI) { + super("add", "Add token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "user", true, "User ID"); + option.setArgName("User ID"); + 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 tokenID = cmdArgs[0]; + + TokenData tokenData = new TokenData(); + tokenData.setID(tokenID); + tokenData.setUserID(cmd.getOptionValue("user")); + + tokenData = tokenCLI.tokenClient.addToken(tokenData); + + MainCLI.printMessage("Added token \"" + tokenID + "\""); + + TokenCLI.printToken(tokenData); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java new file mode 100644 index 000000000..16c2b213b --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java @@ -0,0 +1,90 @@ +// --- 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) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.tps.token; + +import java.util.Arrays; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.tps.token.TokenClient; +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; + +/** + * @author Endi S. Dewata + */ +public class TokenCLI extends CLI { + + public TokenClient tokenClient; + + public TokenCLI(CLI parent) { + super("token", "Token management commands", parent); + + addModule(new TokenAddCLI(this)); + addModule(new TokenFindCLI(this)); + addModule(new TokenModifyCLI(this)); + addModule(new TokenRemoveCLI(this)); + addModule(new TokenShowCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + tokenClient = (TokenClient)parent.getClient("token"); + + if (args.length == 0) { + printHelp(); + System.exit(1); + } + + 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 printToken(TokenData token) { + System.out.println(" Token ID: " + token.getID()); + if (token.getUserID() != null) System.out.println(" User ID: " + token.getUserID()); + if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus()); + if (token.getReason() != null) System.out.println(" Reason: " + token.getReason()); + if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID()); + if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo()); + if (token.getCreateTimestamp() != null) System.out.println(" Date Created: " + token.getCreateTimestamp()); + if (token.getModifyTimestamp() != null) System.out.println(" Date Modified: " + token.getModifyTimestamp()); + + Link link = token.getLink(); + if (verbose && link != null) { + System.out.println(" Link: " + link.getHref()); + } + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java new file mode 100644 index 000000000..3ade40bb9 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java @@ -0,0 +1,94 @@ +// --- 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) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.tps.token; + +import java.util.Collection; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.token.TokenCollection; +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenFindCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenFindCLI(TokenCLI tokenCLI) { + super("find", "Find tokens", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [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 s = cmd.getOptionValue("start"); + Integer start = s == null ? null : Integer.valueOf(s); + + s = cmd.getOptionValue("size"); + Integer size = s == null ? null : Integer.valueOf(s); + + TokenCollection result = tokenCLI.tokenClient.findTokens(start, size); + Collection tokens = result.getEntries(); + + MainCLI.printMessage(tokens.size() + " token(s) matched"); + + boolean first = true; + + for (TokenData tokenData : tokens) { + + if (first) { + first = false; + } else { + System.out.println(); + } + + TokenCLI.printToken(tokenData); + } + + MainCLI.printMessage("Number of entries returned " + tokens.size()); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java new file mode 100644 index 000000000..28559e163 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.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) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.tps.token; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenModifyCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenModifyCLI(TokenCLI tokenCLI) { + super("mod", "Modify token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "user", true, "User ID"); + option.setArgName("User ID"); + 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 tokenID = cmdArgs[0]; + + TokenData tokenData = new TokenData(); + tokenData.setID(tokenID); + tokenData.setUserID(cmd.getOptionValue("user")); + + tokenData = tokenCLI.tokenClient.updateToken(tokenID, tokenData); + + MainCLI.printMessage("Modified token \"" + tokenID + "\""); + + TokenCLI.printToken(tokenData); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java new file mode 100644 index 000000000..f522991cb --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.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) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.tps.token; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenRemoveCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenRemoveCLI(TokenCLI tokenCLI) { + super("del", "Remove token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " ", options); + } + + public void execute(String[] args) throws Exception { + + if (args.length != 1) { + printHelp(); + System.exit(1); + } + + String tokenID = args[0]; + + tokenCLI.tokenClient.removeToken(tokenID); + + MainCLI.printMessage("Deleted token \"" + tokenID + "\""); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java new file mode 100644 index 000000000..14190ef01 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java @@ -0,0 +1,56 @@ +// --- 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) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.tps.token; + +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenShowCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenShowCLI(TokenCLI tokenCLI) { + super("show", "Show token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " ", options); + } + + public void execute(String[] args) throws Exception { + + if (args.length != 1) { + printHelp(); + System.exit(1); + } + + String tokenID = args[0]; + + TokenData tokenData = tokenCLI.tokenClient.getToken(tokenID); + + MainCLI.printMessage("Token \"" + tokenID + "\""); + + TokenCLI.printToken(tokenData); + } +} -- cgit