|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
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.wsrf.utils.FaultHelper; |
|
18 |
| |
|
19 |
| import org.globus.cas.types.ManageUserGroups; |
|
20 |
| import org.globus.cas.types.ManageObjectGroups; |
|
21 |
| import org.globus.cas.types.ManageServiceActionGroups; |
|
22 |
| |
|
23 |
| import org.globus.cas.faults.CasFault; |
|
24 |
| import org.globus.cas.faults.NoPermissionFault; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| public class AddGroupEntry { |
|
30 |
| |
|
31 |
| static String msg = |
|
32 |
| " Usage: cas-group-add-entry [<options>] <groupType> <groupName> \n" |
|
33 |
| + " <groupMemberDetails> \n " |
|
34 |
| + " Options are -debug Runs with debug trace \n" |
|
35 |
| + " -c <instanceURl> Specify URL for CAS server\n" |
|
36 |
| + " -help Prints this message\n" |
|
37 |
| + " -v Prints version number\n" |
|
38 |
| + " -s Identity of CAS server. If not specified, will \n" |
|
39 |
| + " default to host authorization.\n" |
|
40 |
| + " -m security mechanism. 'msg' for secure message\n" |
|
41 |
| + " or 'conv' for secure conversation or 'trans' for\n" |
|
42 |
| + " transport security. If unspecified, if instance\n" |
|
43 |
| + " url is 'https', then trasport security is used \n" |
|
44 |
| + " else mechanism defaults to secure message\n" |
|
45 |
| + " -p protection type, 'sig' signature and 'enc' \n" |
|
46 |
| + " encryption, defaults to signature\n" |
|
47 |
| + " <groupType> : Type of group to which member needs to be added.\n " |
|
48 |
| + " Should be \"user\" or \"object\" or \"serviceAction" |
|
49 |
| + "\"\n" |
|
50 |
| + " <groupName> : Name of the group to which member needs to be added" |
|
51 |
| + " \n <groupmemberDetails> : \n" |
|
52 |
| + " If \"user\", <nickname> \n" |
|
53 |
| + " <nickname> : Nickname of the user to be added \n" |
|
54 |
| + " If \"object\", <objectSpecDesc> <objectSpec>\n" |
|
55 |
| + " <objectSpecDesc> : Type of object. Should be \"object\" \n" |
|
56 |
| + " or \"user\" or \"userGroup\" or \n" |
|
57 |
| + " \"serviceType\" or \"namespace\" or\n" |
|
58 |
| + " \"trustAnchor\" \n" |
|
59 |
| + " <objectSpec> : Data to uniquely identify the CAS Object. \n" |
|
60 |
| + " <objectNamespace> <objectName>, where \n" |
|
61 |
| + " <objectNamespace> is Namespace the object\n" |
|
62 |
| + " belongs to and <objectName> is name of the\n" |
|
63 |
| + " object (or) nickname of the user (or) name\n" |
|
64 |
| + " of user group (or) service type name (or)\n" |
|
65 |
| + " nickname of the namespace or) nickname of\n" |
|
66 |
| + " trust anchor respectively\n" |
|
67 |
| + " If \"serviceAction\", <serviceTypeName> <actionName> \n" |
|
68 |
| + " <serviceTypeName> : Service type that needs to be added\n" |
|
69 |
| + " <actionName> : Action name "; |
|
70 |
| |
|
71 |
| static boolean debug = false; |
|
72 |
| |
|
73 |
0
| public static void main(String args[]) throws Exception {
|
|
74 |
| |
|
75 |
0
| if (args.length<1) {
|
|
76 |
0
| System.out.println(msg);
|
|
77 |
0
| System.exit(0);
|
|
78 |
| } |
|
79 |
| |
|
80 |
0
| CasClientSetup clientSetup = new CasClientSetup(args, msg);
|
|
81 |
0
| String instanceURL = clientSetup.getInstanceURL();
|
|
82 |
0
| String serverIdentity = clientSetup.getServerIdentity();
|
|
83 |
0
| int startIndex = clientSetup.argsStartIndex;
|
|
84 |
0
| debug = clientSetup.debug;
|
|
85 |
0
| printMessage("CAS client to add a member to a group");
|
|
86 |
| |
|
87 |
0
| if (args.length < startIndex + 2) {
|
|
88 |
0
| System.err.println("Not enough parameters");
|
|
89 |
0
| System.err.println(msg);
|
|
90 |
0
| System.exit(-1);
|
|
91 |
| } |
|
92 |
| |
|
93 |
0
| printMessage("Argument starting index is " + startIndex);
|
|
94 |
0
| String casObject = args[startIndex];
|
|
95 |
| |
|
96 |
0
| try {
|
|
97 |
0
| if (casObject.equals(CasConstants.USER_SPEC)) {
|
|
98 |
0
| CASPortType casPort =
|
|
99 |
| clientSetup.getCASPort(instanceURL, 3, serverIdentity); |
|
100 |
0
| printMessage("User group " + args[startIndex+1] + " "
|
|
101 |
| + args[startIndex+2]); |
|
102 |
0
| ManageUserGroups mngGp = new ManageUserGroups();
|
|
103 |
0
| mngGp.setRequestType(CasConstants.ADD_OPERATION);
|
|
104 |
0
| mngGp.setGroupName(args[startIndex+1]);
|
|
105 |
0
| mngGp.setUserNickname(args[startIndex+2]);
|
|
106 |
0
| casPort.manageUserGroups(mngGp);
|
|
107 |
0
| } else if (casObject.equals(CasConstants.OBJECT_SPEC)) {
|
|
108 |
0
| CASPortType casPort =
|
|
109 |
| clientSetup.getCASPort(instanceURL, 4, serverIdentity); |
|
110 |
| |
|
111 |
0
| printMessage("Object group " + args[startIndex+1] + " "
|
|
112 |
| + args[startIndex+3] + " " + args[startIndex+2]); |
|
113 |
0
| String objectSpec = args[startIndex+3];
|
|
114 |
| |
|
115 |
| |
|
116 |
0
| if (args[startIndex+2].equals(CasConstants.OBJECT_SPEC)) {
|
|
117 |
0
| printMessage("Group type is object group");
|
|
118 |
0
| clientSetup.checkParameters(5);
|
|
119 |
0
| objectSpec = args[startIndex+3]
|
|
120 |
| + CasConstants.OBJECTSPEC_DELIMITER |
|
121 |
| + args[startIndex+4]; |
|
122 |
| } |
|
123 |
0
| ManageObjectGroups mngGp = new ManageObjectGroups();
|
|
124 |
0
| mngGp.setRequestType(CasConstants.ADD_OPERATION);
|
|
125 |
0
| mngGp.setGroupName(args[startIndex+1]);
|
|
126 |
0
| mngGp.setObjectSpec(objectSpec);
|
|
127 |
0
| mngGp.setObjectSpecDesc(args[startIndex+2]);
|
|
128 |
0
| casPort.manageObjectGroups(mngGp);
|
|
129 |
0
| } else if (casObject.equals(CasConstants.SERVICEACTION_SPEC)) {
|
|
130 |
0
| CASPortType casPort =
|
|
131 |
| clientSetup.getCASPort(instanceURL, 4, serverIdentity); |
|
132 |
0
| printMessage("Service Action group " + args[startIndex+1]
|
|
133 |
| + " " + args[startIndex+2] + " " |
|
134 |
| + args[startIndex+3]); |
|
135 |
0
| ManageServiceActionGroups mngGp =
|
|
136 |
| new ManageServiceActionGroups(); |
|
137 |
0
| mngGp.setRequestType(CasConstants.ADD_OPERATION);
|
|
138 |
0
| mngGp.setGroupName(args[startIndex+1]);
|
|
139 |
0
| mngGp.setServiceTypeName(args[startIndex+2]);
|
|
140 |
0
| mngGp.setActionName(args[startIndex+3]);
|
|
141 |
0
| casPort.manageServiceActionGroups(mngGp);
|
|
142 |
| } else { |
|
143 |
0
| System.err.println("Erroneous object type " + casObject);
|
|
144 |
0
| System.err.println(msg);
|
|
145 |
0
| System.exit(-1);
|
|
146 |
| } |
|
147 |
| } catch (NoPermissionFault noPermFault) { |
|
148 |
0
| System.err.println(noPermFault.getDescription());
|
|
149 |
0
| System.exit(-1);
|
|
150 |
| } catch (CasFault casFault) { |
|
151 |
0
| if (!debug) {
|
|
152 |
0
| String desc =
|
|
153 |
| (new FaultHelper(casFault)).getDescriptionAsString(); |
|
154 |
0
| System.err.println(desc);
|
|
155 |
| } else { |
|
156 |
0
| System.err.println((new FaultHelper(casFault))
|
|
157 |
| .getStackTrace()); |
|
158 |
| } |
|
159 |
0
| System.exit(-1);
|
|
160 |
| } catch (Exception exp) { |
|
161 |
0
| if (debug) {
|
|
162 |
0
| System.err.println(exp.toString());
|
|
163 |
| } else { |
|
164 |
0
| System.err.println(CasClientSetup.getErrorMsg(exp));
|
|
165 |
| } |
|
166 |
0
| System.exit(-1);
|
|
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 |
| } |