CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 186   Methods: 2
NCLOC: 157   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Enroll.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.AddUser;
 18    import org.globus.cas.types.AddTrustAnchor;
 19    import org.globus.cas.types.CreateServiceType;
 20    import org.globus.cas.types.CreateObject;
 21    import org.globus.cas.types.CreateObjectNamespace;
 22   
 23    import org.globus.cas.faults.CasFault;
 24    import org.globus.cas.faults.NoPermissionFault;
 25   
 26    import org.globus.wsrf.utils.FaultHelper;
 27   
 28    /**
 29    * Command client used to enroll trust anchor, user, namespace, service type
 30    */
 31    public class Enroll {
 32   
 33    static String msg =
 34    " Usage: cas-enroll [<options>] <objectType> <userGroup> "
 35    + " <objectDetails>\n"
 36    + " Options are -debug Runs with debug trace \n"
 37    + " -c <instanceURL> Specify URL for CAS server\n"
 38    + " -help Prints this message\n"
 39    + " -v Prints version number\n"
 40    + " -s Identity of CAS server. If not specified, will \n"
 41    + " defualt to host authorization.\n"
 42    + " -m security mechanism. 'msg' for secure message\n"
 43    + " or 'conv' for secure conversation or 'trans' for\n"
 44    + " transport security. If unspecified, if instance\n"
 45    + " url is 'https', then trasport security is used \n"
 46    + " else mechanism defaults to secure message\n"
 47    + " -p protection type, 'sig' signature and 'enc' \n"
 48    + " encryption, defaults to signature\n"
 49    + " <objectType> : Type of data that needs to be enrolled. Should be\n"
 50    + " \"trustAnchor\" or \"user\" or \"object\" or \n"
 51    + " \"namespace\" or \"serviceType\" \n"
 52    + " <userGroup> : User group name to which all rights on this object\n"
 53    + " should be granted \n"
 54    + " <objectDetails> : \n"
 55    + " If \"trustAnchor\", <nickname> <authMethod> <authData>\n"
 56    + " <nickname> : The trust anchor nickname\n"
 57    + " <authMethod> : Authorization method used by the trust anchor"
 58    + "\n <authData> : Authorization data \n"
 59    + " If \"user\", <nickname> <subjectName> <trustAnchorNick> \n"
 60    + " <nickname> : Nickname of the user \n"
 61    + " <subjectName> : DN of the user\n"
 62    + " <trustAnchorNick> : Nickname of the trust anchor used to \n"
 63    + " ratify user\n "
 64    + " If \"object\", <objectName> <objectNamespace> \n"
 65    + " <objectName> Name of the object that needs to be added \n"
 66    + " <objectNamespace> Namespace the object belongs to\n"
 67    + " If \"namespace\", <nickname> <basename> <comparisonAlg>\n"
 68    + " <nickname> : Nickname for the object namespace \n"
 69    + " <basename> : basename for the namesape\n"
 70    + " <comparisonAlg> : Comparison algorithm used for objects \n"
 71    + " that belongs to this namespace \n"
 72    + " If \"serviceType\", <serviceTypeName> \n"
 73    + " <serviceTypeName> : Name of the service type that needs to \n"
 74    + " be added \n";
 75   
 76    static boolean debug = false;
 77   
 78  0 public static void main(String args[]) throws Exception {
 79   
 80  0 System.out.println("Called");
 81  0 if (args.length<1) {
 82  0 System.out.println(msg);
 83  0 System.exit(0);
 84    }
 85   
 86  0 CasClientSetup clientSetup = new CasClientSetup(args, msg);
 87  0 String instanceURL = clientSetup.getInstanceURL();
 88  0 String serverIdentity = clientSetup.getServerIdentity();
 89  0 int startIndex = clientSetup.argsStartIndex;
 90  0 debug = clientSetup.debug;
 91  0 printMessage("CAS client to enroll CAS entities");
 92   
 93  0 if (args.length < startIndex + 1) {
 94  0 System.err.println("Not enough parameters");
 95  0 System.err.println(msg);
 96  0 System.exit(-1);
 97    }
 98   
 99  0 String casObject = args[startIndex];
 100   
 101  0 try {
 102    // Trust anchor or user
 103  0 if (casObject.equals(CasConstants.TRUSTANCHOR_SPEC)) {
 104  0 printMessage("Enroll Trust anchor");
 105  0 CASPortType casPort =
 106    clientSetup.getCASPort(instanceURL, 5, serverIdentity);
 107  0 AddTrustAnchor addTrust = new AddTrustAnchor();
 108  0 addTrust.setUserGpName(args[startIndex+1]);
 109  0 addTrust.setNickname(args[startIndex+2]);
 110  0 addTrust.setAuthMethod(args[startIndex+3]);
 111  0 addTrust.setAuthData(args[startIndex+4]);
 112  0 casPort.addTrustAnchor(addTrust);
 113  0 } else if (casObject.equals(CasConstants.USER_SPEC)) {
 114  0 printMessage("Enroll User");
 115  0 CASPortType casPort =
 116    clientSetup.getCASPort(instanceURL, 5, serverIdentity);
 117  0 AddUser addUser = new AddUser();
 118  0 addUser.setUserGpName(args[startIndex+1]);
 119  0 addUser.setNickname(args[startIndex+2]);
 120  0 addUser.setSubjectDN(args[startIndex+3]);
 121  0 addUser.setTrustAnchorNickname(args[startIndex+4]);
 122  0 casPort.addUser(addUser);
 123  0 } else if (casObject.equals(CasConstants.NAMESPACE_SPEC)) {
 124  0 printMessage("Enroll namespace");
 125  0 CASPortType casPort =
 126    clientSetup.getCASPort(instanceURL, 5, serverIdentity);
 127  0 CreateObjectNamespace createObjNS =
 128    new CreateObjectNamespace();
 129  0 createObjNS.setUserGpName(args[startIndex+1]);
 130  0 createObjNS.setNickname(args[startIndex+2]);
 131  0 createObjNS.setBaseName(args[startIndex+3]);
 132  0 createObjNS.setComparisonAlg(args[startIndex+4]);
 133  0 casPort.createObjectNamespace(createObjNS);
 134  0 } else if (casObject.equals(CasConstants.OBJECT_SPEC)) {
 135  0 printMessage("Enroll object");
 136  0 CASPortType casPort =
 137    clientSetup.getCASPort(instanceURL, 4, serverIdentity);
 138  0 CreateObject createObj = new CreateObject();
 139  0 createObj.setUserGpName(args[startIndex+1]);
 140  0 createObj.setObjectName(args[startIndex+2]);
 141  0 createObj.setObjectNamespace(args[startIndex+3]);
 142  0 casPort.createObject(createObj);
 143  0 } else if (casObject.equals(CasConstants.SERVICETYPE_SPEC)) {
 144  0 printMessage("Enroll service type");
 145  0 CASPortType casPort =
 146    clientSetup.getCASPort(instanceURL, 3, serverIdentity);
 147  0 CreateServiceType createServiceType =
 148    new CreateServiceType();
 149  0 createServiceType.setUserGpName(args[startIndex+1]);
 150  0 createServiceType.setServiceTypeName(args[startIndex+2]);
 151  0 casPort.createServiceType(createServiceType);
 152    } else {
 153  0 System.err.println("Erroneous object type " + casObject);
 154  0 System.err.println(msg);
 155  0 System.exit(-1);
 156    }
 157    } catch (NoPermissionFault noPermFault) {
 158  0 System.err.println(noPermFault.getDescription());
 159  0 System.exit(-1);
 160    } catch (CasFault casFault) {
 161  0 if (!debug) {
 162  0 String desc =
 163    (new FaultHelper(casFault)).getDescriptionAsString();
 164  0 System.err.println(desc);
 165    } else {
 166  0 System.err.println((new FaultHelper(casFault))
 167    .getStackTrace());
 168    }
 169  0 System.exit(-1);
 170    } catch (Exception exp) {
 171  0 if (debug) {
 172  0 System.err.println(exp.toString());
 173    } else {
 174  0 System.err.println(CasClientSetup.getErrorMsg(exp));
 175    }
 176  0 System.exit(-1);
 177    }
 178  0 System.out.println("Completed successfully");
 179    }
 180   
 181  0 private static void printMessage(String msg) {
 182  0 if (debug) {
 183  0 System.out.println(msg);
 184    }
 185    }
 186    }