Debian Codegraph @

gss/src/main/java/org/globus/gsi/gssapi/example/GetOpts.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.gsi.gssapi.example;
16
17 import org.ietf.jgss.GSSContext;
18
19 public class GetOpts {
20
21 public boolean conf = true;
22 public int lifetime = GSSContext.DEFAULT_LIFETIME;
23 public boolean gsiMode = true;
24 public boolean deleg = false;
25 public boolean limitedDeleg = true;
26 public boolean rejectLimitedProxy = false;
27 public boolean anonymity = false;
28 public String auth = null;
29
30 protected String usage;
31 protected String helpMsg;
32
33 public GetOpts(String usage, String helpMsg) {
34 this.usage = usage;
35 this.helpMsg = helpMsg;
36 }
37
38 public int parse(String[] args) {
39 int i = 0;
40 for (i=0;i<args.length;i++) {
41 if (args[i].charAt(0) != '-') {
42 // treat as user arg
43 break;
44 }
45 i += parseArg(args, i);
46 }
47 return i;
48 }
49
50 protected int parseArg(String[] args, int i) {
51 int j = 0;
52
53 if (args[i].equalsIgnoreCase("-enable-conf")) {
54 conf = true;
55 } else if (args[i].equalsIgnoreCase("-disable-conf")) {
56 conf = false;
57 } else if (args[i].equalsIgnoreCase("-gss-mode")) {
58 String arg = args[++i];
59 if (arg.equalsIgnoreCase("ssl")) {
60 gsiMode = false;
61 } else if (arg.equalsIgnoreCase("gsi")) {
62 gsiMode = true;
63 } else {
64 error("Invalid -gss-mode argument: " + arg);
65 }
66 j = 1;
67 } else if (args[i].equalsIgnoreCase("-deleg-type")) {
68 String arg = args[++i];
69 if (arg.equalsIgnoreCase("full")) {
70 limitedDeleg = false;
71 deleg = true;
72 } else if (arg.equalsIgnoreCase("limited")) {
73 limitedDeleg = true;
74 deleg = true;
75 } else if (arg.equalsIgnoreCase("none")) {
76 deleg = false;
77 } else {
78 error("Invalid -deleg-type argument: " + arg);
79 }
80 j = 1;
81 } else if (args[i].equalsIgnoreCase("-auth")) {
82 String arg = args[++i];
83 if (arg.equalsIgnoreCase("host")) {
84 auth = "host";
85 } else if (arg.equalsIgnoreCase("self")) {
86 auth = "self";
87 } else {
88 auth = arg;
89 }
90 j = 1;
91 } else if (args[i].equalsIgnoreCase("-lifetime")) {
92 lifetime = Integer.parseInt(args[++i]);
93 j = 1;
94 } else if (args[i].equalsIgnoreCase("-rejectLimitedProxy")) {
95 rejectLimitedProxy = true;
96 } else if (args[i].equalsIgnoreCase("-anonymous")) {
97 anonymity = true;
98 } else if (args[i].equalsIgnoreCase("-help")) {
99 System.err.println(this.usage);
100 System.err.println();
101 System.err.println(this.helpMsg);
102 System.exit(0);
103 } else {
104 System.err.println("Argument not recognized: " + args[i]);
105 System.exit(1);
106 }
107
108 return j;
109 }
110
111 protected static void error(String msg) {
112 System.err.println(msg);
113 System.exit(1);
114 }
115
116 }