CAS Unit Tests
Clover coverage report - CAS Unit Tests
Coverage timestamp: Mon Jul 4 2005 18:13:17 CDT
file stats: LOC: 176   Methods: 2
NCLOC: 141   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FindApplicablePolicy.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.utils.CasStringUtils;
 16   
 17    import org.globus.cas.types.CasObjectDesc;
 18    import org.globus.cas.types.CasObjectData;
 19    import org.globus.cas.types.PolicyData;
 20    import org.globus.cas.types.ArrayOfCasObjectData;
 21   
 22    import org.globus.cas.faults.CasFault;
 23    import org.globus.cas.faults.NoPermissionFault;
 24   
 25    import org.globus.wsrf.utils.FaultHelper;
 26   
 27    import org.globus.cas.impl.CasConstants;
 28   
 29    /**
 30    * Command line client to get all applicable policy for trustAnchor/namespace/
 31    * user/userGroup/object/objectGroup/serviceType/serviceTypeAction/
 32    * serviceActionGroup.
 33    */
 34    public class FindApplicablePolicy {
 35   
 36    static final String msg =
 37    " Usage : cas-find-policy [<options>] <objectType> <objectDetails>\n"
 38    + " Options are -debug Runs with debug trace \n"
 39    + " -c <instanceURl> Specify URL for CAS server\n"
 40    + " -help Prints this message\n"
 41    + " -v Prints version number\n"
 42    + " -s Identity of CAS server. If not specified, will \n"
 43    + " default to host authorization.\n"
 44    + " -m security mechanism. 'msg' for secure message\n"
 45    + " or 'conv' for secure conversation or 'trans' for\n"
 46    + " transport security. If unspecified, if instance\n"
 47    + " url is 'https', then trasport security is used \n"
 48    + " else mechanism defaults to secure message\n"
 49    + " -p protection type, 'sig' signature and 'enc' \n"
 50    + " encryption, defaults to signature\n"
 51    + " <objectType> : Type of object to retrieve policies for. Should \n"
 52    + " be \"trustAnchor\" or \"user\" or \"object\" or \n"
 53    + " \"userGroup\" or \"objectGroup\" or \"namespace\" "
 54    + "\n or \"serviceType\" or \"serviceAction\" or \n"
 55    + " \"serviceActionGroup\" \n"
 56    + " <objectDetails> : \n"
 57    + " If \"trustAnchor\", <nickname>\n"
 58    + " <nickname> : Nickname of trust anchor\n"
 59    + " If \"user\", <nickname>\n"
 60    + " <nickname> : Nickname of user\n"
 61    + " If \"object\", <objectNamespace> <object>\n"
 62    + " <objectNamespace> : Namespace of the object\n"
 63    + " <objectName> : Name of object\n"
 64    + " If \"userGroup\", <groupName>\n"
 65    + " <groupName> : Name of the user group\n"
 66    + " If \"objectGroup\", <groupName>\n"
 67    + " <groupName> : Name of the object group\n"
 68    + " If \"namespace\", <nickanme>\n"
 69    + " <nickname> : Nickname of namespace\n"
 70    + " If \"serviceType\", <serviceType>\n"
 71    + " <serviceType> : name of the service type\n"
 72    + " If \"serviceActionGroup\", <groupName>\n"
 73    + " <groupName> : Name of service action group\n";
 74   
 75    static boolean debug =false;
 76   
 77  0 public static void main(String args[]) {
 78   
 79  0 if (args.length<1) {
 80  0 System.out.println(msg);
 81  0 System.exit(0);
 82    }
 83   
 84  0 CasClientSetup clientSetup = new CasClientSetup(args, msg);
 85  0 String instanceURL = clientSetup.getInstanceURL();
 86  0 String serverIdentity = clientSetup.getServerIdentity();
 87  0 int startIndex = clientSetup.argsStartIndex;
 88  0 debug = clientSetup.debug;
 89   
 90  0 printMessage("CAS to list all applicable policy.");
 91   
 92  0 if (args.length < startIndex + 1) {
 93  0 System.err.println("Not enough parameters");
 94  0 System.err.println(msg);
 95  0 System.exit(-1);
 96    }
 97   
 98  0 String type = args[startIndex].trim();
 99  0 if ( !(type.equals(CasConstants.TRUSTANCHOR_SPEC) ||
 100    type.equals(CasConstants.USER_SPEC) ||
 101    type.equals(CasConstants.OBJECT_SPEC) ||
 102    type.equals(CasConstants.USERGP_SPEC) ||
 103    type.equals(CasConstants.OBJECTGP_SPEC) ||
 104    type.equals(CasConstants.NAMESPACE_SPEC) ||
 105    type.equals(CasConstants.SERVICETYPE_SPEC) ||
 106    type.equals(CasConstants.SERVICEACTION_SPEC) ||
 107    type.equals(CasConstants.SERVICEACTIONGP_SPEC))) {
 108  0 System.err.println("Erroneous type " + type);
 109  0 System.err.println(msg);
 110  0 System.exit(-1);
 111    }
 112   
 113  0 String identifier = null;
 114  0 CASPortType casPort = null;
 115  0 if (type.equals(CasConstants.OBJECT_SPEC)) {
 116  0 casPort = clientSetup.getCASPort(instanceURL, 3, serverIdentity);
 117  0 identifier = args[startIndex+1] + CasConstants.OBJECTSPEC_DELIMITER
 118    + args[startIndex+2];
 119    } else {
 120  0 casPort = clientSetup.getCASPort(instanceURL, 2, serverIdentity);
 121  0 identifier = args[startIndex+1];
 122    }
 123   
 124  0 CasObjectData[] casObj = null;
 125   
 126  0 printMessage("Parameters are " + type + " " + identifier);
 127  0 try {
 128  0 CasObjectDesc tmp = new CasObjectDesc();
 129  0 tmp.setNameOfCasObject(identifier);
 130  0 tmp.setTypeOfCasObject(type);
 131  0 ArrayOfCasObjectData retArray =
 132    casPort.findApplicablePolicy(tmp);
 133  0 if (retArray != null) {
 134  0 casObj = retArray.getCasObjects();
 135    }
 136    } catch (NoPermissionFault noPermFault) {
 137  0 System.err.println(noPermFault.getDescription());
 138  0 System.exit(-1);
 139    } catch (CasFault casFault) {
 140  0 if (!debug) {
 141  0 String desc =
 142    (new FaultHelper(casFault)).getDescriptionAsString();
 143  0 System.err.println(desc);
 144    } else {
 145  0 System.err.println((new FaultHelper(casFault))
 146    .getStackTrace());
 147    }
 148  0 System.exit(-1);
 149    } catch (Exception exp) {
 150  0 if (debug) {
 151  0 System.err.println(exp.toString());
 152    } else {
 153  0 System.err.println(CasClientSetup.getErrorMsg(exp));
 154    }
 155  0 System.exit(-1);
 156    }
 157   
 158  0 if (casObj == null) {
 159  0 System.out.println("No applicable policies found");
 160    }
 161    else {
 162  0 System.out.println("Applicable policies:");
 163  0 for (int i=0; i<casObj.length; i++) {
 164  0 System.out.println(CasStringUtils.policyToString(
 165    (PolicyData)casObj[i]));
 166    }
 167    }
 168  0 System.out.println("Completed successfully");
 169    }
 170   
 171  0 private static void printMessage(String msg) {
 172  0 if (debug) {
 173  0 System.out.println(msg);
 174    }
 175    }
 176    }