CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 148   Methods: 2
NCLOC: 117   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
GroupHandler.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Portions of this file Copyright 1999-2005 University of Chicago
 3    * Portions of this file Copyright 1999-2005 The University of Southern California.
 4    *
 5    * This file or a portion of this file is licensed under the
 6    * terms of the Globus Toolkit Public License, found at
 7    * http://www.globus.org/toolkit/download/license.html.
 8    * If you redistribute this file, with or without
 9    * modifications, you must include this notice in the file.
 10    */
 11    package org.globus.cas.impl.client;
 12   
 13    import org.globus.cas.CASPortType;
 14   
 15    import org.globus.cas.impl.CasConstants;
 16   
 17    import org.globus.cas.types.CreateGroup;
 18    import org.globus.cas.types.DeleteGroup;
 19   
 20    import org.globus.cas.faults.CasFault;
 21    import org.globus.cas.faults.NoPermissionFault;
 22   
 23    import org.globus.wsrf.utils.FaultHelper;
 24    /**
 25    * Command line client to create or delete from a user, object or
 26    * serviceAction group
 27    */
 28    public class GroupHandler {
 29   
 30    static String msg =
 31    " Usage : cas-group-admin [<options>] <groupType> <operationType> \n"
 32    + " [<userGpName>] <groupName>\n"
 33    + " Options are -debug Runs with debug trace \n"
 34    + " -c <instanceURl> Specify URL for CAS server\n"
 35    + " -help Prints this message\n"
 36    + " -v Prints version number\n"
 37    + " -s Identity of CAS server. If not specified, will \n"
 38    + " defualt to host authorization.\n"
 39    + " -m security mechanism. 'msg' for secure message\n"
 40    + " or 'conv' for secure conversation or 'trans' for\n"
 41    + " transport security. If unspecified, if instance\n"
 42    + " url is 'https', then trasport security is used \n"
 43    + " else mechanism defaults to secure message\n"
 44    + " -p protection type, 'sig' signature and 'enc' \n"
 45    + " encryption, defaults to signature\n"
 46    + " <groupType> : Type of group this operation is on. Should be \n"
 47    + " \"user\" or \"object\" or \"serviceAction\"\n"
 48    + " <operationType> : Type of operation on the group. Should be \n"
 49    + " \"create\" or \"delete\"\n"
 50    + " <userGpName> : Needed only when the <operationType> is \"create\""
 51    + "\n Name of the user group to which to give all \n"
 52    + " rights on the created group.\n"
 53    + " <groupName> : Name of the group that needs to be created or \n"
 54    + " deleted.\n";
 55   
 56    static boolean debug = false;
 57   
 58  0 public static void main(String args[]) throws Exception {
 59   
 60  0 if (args.length<1) {
 61  0 System.out.println(msg);
 62  0 System.exit(0);
 63    }
 64   
 65  0 CasClientSetup clientSetup = new CasClientSetup(args, msg);
 66  0 String instanceURL = clientSetup.getInstanceURL();
 67  0 String serverIdentity = clientSetup.getServerIdentity();
 68  0 int startIndex = clientSetup.argsStartIndex;
 69  0 debug = clientSetup.debug;
 70   
 71  0 printMessage("CAS client to create or delete a group.");
 72   
 73  0 if (args.length < startIndex + 2) {
 74  0 System.err.println("Not enough parameters");
 75  0 System.err.println(msg);
 76  0 System.exit(-1);
 77    }
 78   
 79  0 String groupType = args[startIndex];
 80  0 String operation = args[startIndex+1];
 81   
 82  0 if ((!groupType.equals(CasConstants.USER_SPEC)) &&
 83    (!groupType.equals(CasConstants.OBJECT_SPEC)) &&
 84    (!groupType.equals(CasConstants.SERVICEACTION_SPEC))) {
 85  0 System.err.println("Erraneous groupType type " + groupType);
 86  0 System.err.println(msg);
 87  0 System.exit(-1);
 88    }
 89   
 90  0 if ((!operation.equals(CasConstants.CREATE_OPERATION)) &&
 91    (!operation.equals(CasConstants.DELETE_OPERATION))) {
 92  0 System.err.println("Erraneous operation type " + operation);
 93  0 System.err.println(msg);
 94  0 System.exit(-1);
 95    }
 96   
 97  0 try {
 98  0 if (operation.equals(CasConstants.CREATE_OPERATION)) {
 99  0 CASPortType casPort =
 100    clientSetup.getCASPort(instanceURL, 4, serverIdentity);
 101  0 printMessage("Create operation " + groupType + " " +
 102    args[startIndex+2] + " " + args[startIndex+3]);
 103  0 CreateGroup createGroup = new CreateGroup();
 104  0 createGroup.setGroupType(groupType);
 105  0 createGroup.setUserGpName(args[startIndex+2]);
 106  0 createGroup.setGroupName(args[startIndex+3]);
 107  0 casPort.createGroup(createGroup);
 108  0 } else if (operation.equals(CasConstants.DELETE_OPERATION)) {
 109  0 CASPortType casPort =
 110    clientSetup.getCASPort(instanceURL, 3, serverIdentity);
 111  0 printMessage("Deletion operation " + groupType + " "
 112    + args[startIndex+2]);
 113  0 DeleteGroup deleteGroup = new DeleteGroup();
 114  0 deleteGroup.setGroupType(groupType);
 115  0 deleteGroup.setGroupName(args[startIndex+2]);
 116  0 casPort.deleteGroup(deleteGroup);
 117    }
 118    } catch (NoPermissionFault noPermFault) {
 119  0 System.err.println(noPermFault.getDescription());
 120  0 System.exit(-1);
 121    } catch (CasFault casFault) {
 122  0 if (!debug) {
 123  0 String desc =
 124    (new FaultHelper(casFault)).getDescriptionAsString();
 125  0 System.err.println(desc);
 126    } else {
 127  0 System.err.println((new FaultHelper(casFault))
 128    .getStackTrace());
 129    }
 130  0 System.exit(-1);
 131    } catch (Exception exp) {
 132  0 if (debug) {
 133  0 exp.printStackTrace();
 134  0 System.err.println(exp.toString());
 135    } else {
 136  0 System.err.println(CasClientSetup.getErrorMsg(exp));
 137    }
 138  0 System.exit(-1);
 139    }
 140  0 System.out.println("Completed successfully");
 141    }
 142   
 143  0 private static void printMessage(String msg) {
 144  0 if (debug) {
 145  0 System.out.println(msg);
 146    }
 147    }
 148    }