001: /**
002: * $Id: Gateway2ViewBean.java,v 1.6 2005/11/30 11:27:10 ss150821 Exp $
003: * Copyright 2001 Sun Microsystems, Inc. Some preexisting
004: * portions Copyright 2001 Netscape Communications Corp.
005: * All rights reserved. Use of this product is subject to
006: * license terms. Federal Acquisitions: Commercial Software --
007: * Government Users Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet are
011: * trademarks or registered trademarks of Sun Microsystems, Inc.
012: * in the United States and other countries. Netscape and the
013: * Netscape N logo are registered trademarks of Netscape
014: * Communications Corporation in the U.S. and other countries.
015: * Other Netscape logos, product names, and service names are
016: * also trademarks of Netscape Communications Corporation,
017: * which may be registered in other countries.
018: */package com.sun.portal.rproxy.admin;
019:
020: // JDK classes
021: import java.util.HashMap;
022: import java.util.HashSet;
023: import java.util.Iterator;
024: import java.util.Map;
025: import java.util.NoSuchElementException;
026: import java.util.Set;
027: import java.util.StringTokenizer;
028:
029: import com.iplanet.am.console.components.view.html.IPlanetButton;
030: import com.iplanet.am.util.AMPasswordUtil;
031: import com.iplanet.jato.model.ModelControlException;
032: import com.iplanet.jato.view.View;
033: import com.iplanet.jato.view.event.DisplayEvent;
034: import com.iplanet.jato.view.event.RequestInvocationEvent;
035: import com.iplanet.jato.view.html.CheckBox;
036: import com.iplanet.jato.view.html.ListBox;
037: import com.iplanet.jato.view.html.OptionList;
038: import com.iplanet.jato.view.html.StaticTextField;
039: import com.iplanet.jato.view.html.TextField;
040: import com.iplanet.sso.SSOException;
041: import com.sun.portal.rproxy.admin.model.GatewayModel;
042:
043: public class Gateway2ViewBean extends GatewayViewBeanBase implements
044: GatewayAdminService {
045: public static final String PAGE_NAME = "Gateway2";
046:
047: public static final String DEFAULT_DISPLAY_URL = "/ps/gwadmin/Gateway2.jsp";
048:
049: public static final String CHILD_USEPROXY_LBL = "useProxyLabel";
050:
051: public static final String CHILD_USEPROXY = "useProxy";
052:
053: public static final String CHILD_USEWEBPROXYURL_LBL = "useWebProxyUrlLabel";
054:
055: public static final String CHILD_USEWEBPROXYURL = "useWebProxyUrl";
056:
057: public static final String CHILD_DONTUSEWEBPROXYURL_LBL = "DontUseWebProxyUrlLabel";
058:
059: public static final String CHILD_DONTUSEWEBPROXYURL = "DontUseWebProxyUrl";
060:
061: public static final String CHILD_PACFILEENABLED_LBL = "PACFileEnabledLabel";
062:
063: public static final String CHILD_PACFILEENABLED = "PACFileEnabled";
064:
065: public static final String CHILD_PACFILELOCATION_LBL = "PACFileLocationLabel";
066:
067: public static final String CHILD_PACFILELOCATION = "PACFileLocation";
068:
069: public static final String CHILD_DOMAINANDSUBDOMAINS_LBL = "DomainsAndSubdomainsLabel";
070:
071: public static final String CHILD_DOMAINANDSUBDOMAINS = "DomainsAndSubdomains";
072:
073: public static final String CHILD_PROXYPASSWORDLIST_LBL = "ProxyPasswdListLabel";
074:
075: public static final String CHILD_PROXYPASSWORDLIST = "ProxyPasswdList";
076:
077: public static final String CHILD_NETLETPROXYTUNNEL_LBL = "NetletProxyTunnelLabel";
078:
079: public static final String CHILD_NETLETPROXYTUNNEL = "NetletProxyTunnel";
080:
081: public static final String CHILD_PROXYSERVER_LBL = "proxyServerLabel";
082:
083: public static final String CHILD_PROXYSERVER = "proxyServer";
084:
085: public static final String CHILD_PROXYUSER_LBL = "proxyUserLabel";
086:
087: public static final String CHILD_PROXYUSER = "proxyUser";
088:
089: public static final String CHILD_PROXYPASSWORD_LBL = "proxyPasswordLabel";
090:
091: public static final String CHILD_PROXYPASSWORD = "proxyPassword";
092:
093: public static final String CHILD_ADD_BTN = "addButton";
094:
095: public static final String CHILD_REMOVE_BTN = "removeButton";
096:
097: public static final String CHILD_ADDTOLIST_BTN = "addToListButton";
098:
099: public static final String CHILD_REMOVEFROMLIST_BTN = "removeFromListButton";
100:
101: public static final String ATTR_USEPROXY = "sunPortalGatewayUseProxy";
102:
103: public static final String ATTR_USEWEBPROXYURL = "sunPortalGatewayUseWebProxyURL";
104:
105: public static final String ATTR_DONTUSEWEBPROXYURL = "sunPortalGatewayDontUseWebProxyURL";
106:
107: public static final String ATTR_PACFILEENABLED = "sunPortalGatewayPACFileEnabled";
108:
109: public static final String ATTR_PACFILELOCATION = "sunPortalGatewayPACFileLocation";
110:
111: public static final String ATTR_DOMAINSANDSUBDOMAINS = "sunPortalGatewayDomainsAndSubdomains";
112:
113: public static final String ATTR_PROXYPASSWORDLIST = "sunPortalGatewayProxyPasswdList";
114:
115: public static final String ATTR_NETLETPROXYTUNNEL = "sunPortalGatewayNetletProxyTunnel";
116:
117: private static Map ProxyPasswordValues = new HashMap();
118:
119: /**
120: * Default Constructor
121: */
122: public Gateway2ViewBean(String pageName) {
123: super (pageName);
124: registerChildren();
125: }
126:
127: public Gateway2ViewBean() {
128: super (PAGE_NAME);
129: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
130: registerChildren();
131: }
132:
133: /**
134: * Creates the child view objects for this viewbean.
135: *
136: * @param name
137: * the name of the child view object to be created.
138: * @return the child view object.
139: */
140: protected View createChild(String name) {
141: getGWModelMgr();
142: if (name.equals(CHILD_USEPROXY_LBL)) {
143: model.setCurrentRow(model
144: .getGWAttributeIndex(ATTR_USEPROXY));
145: return new StaticTextField(this , CHILD_USEPROXY_LBL, model
146: .getAttrLabel());
147: } else if (name.equals(CHILD_USEPROXY)) {
148: return new CheckBox(this , CHILD_USEPROXY, "true", "false",
149: false);
150: } else if (name.equals(CHILD_USEWEBPROXYURL_LBL)) {
151: model.setCurrentRow(model
152: .getGWAttributeIndex(ATTR_USEWEBPROXYURL));
153: return new StaticTextField(this , CHILD_USEWEBPROXYURL_LBL,
154: model.getAttrLabel());
155: } else if (name.equals(CHILD_USEWEBPROXYURL)) {
156: return new ListBox(this , CHILD_USEWEBPROXYURL, "");
157: } else if (name.equals(CHILD_DONTUSEWEBPROXYURL_LBL)) {
158: model.setCurrentRow(model
159: .getGWAttributeIndex(ATTR_DONTUSEWEBPROXYURL));
160: return new StaticTextField(this ,
161: CHILD_DONTUSEWEBPROXYURL_LBL, model.getAttrLabel());
162: } else if (name.equals(CHILD_DONTUSEWEBPROXYURL)) {
163: return new ListBox(this , CHILD_DONTUSEWEBPROXYURL, "");
164: } else if (name.equals(CHILD_PACFILEENABLED_LBL)) {
165: model.setCurrentRow(model
166: .getGWAttributeIndex(ATTR_PACFILEENABLED));
167: return new StaticTextField(this , CHILD_PACFILEENABLED_LBL,
168: model.getAttrLabel());
169: } else if (name.equals(CHILD_PACFILEENABLED)) {
170: return new CheckBox(this , CHILD_PACFILEENABLED, "true",
171: "false", false);
172: } else if (name.equals(CHILD_PACFILELOCATION_LBL)) {
173: model.setCurrentRow(model
174: .getGWAttributeIndex(ATTR_PACFILELOCATION));
175: return new StaticTextField(this , CHILD_PACFILELOCATION_LBL,
176: model.getAttrLabel());
177: } else if (name.equals(CHILD_PACFILELOCATION)) {
178: return new TextField(this , CHILD_PACFILELOCATION, "");
179: } else if (name.equals(CHILD_DOMAINANDSUBDOMAINS_LBL)) {
180: model.setCurrentRow(model
181: .getGWAttributeIndex(ATTR_DOMAINSANDSUBDOMAINS));
182: return new StaticTextField(this ,
183: CHILD_DOMAINANDSUBDOMAINS_LBL, model.getAttrLabel());
184: } else if (name.equals(CHILD_DOMAINANDSUBDOMAINS)) {
185: return new ListBox(this , CHILD_DOMAINANDSUBDOMAINS, "");
186: } else if (name.equals(CHILD_PROXYPASSWORDLIST_LBL)) {
187: model.setCurrentRow(model
188: .getGWAttributeIndex(ATTR_PROXYPASSWORDLIST));
189: return new StaticTextField(this ,
190: CHILD_PROXYPASSWORDLIST_LBL, model.getAttrLabel());
191: } else if (name.equals(CHILD_PROXYPASSWORDLIST)) {
192: return new ListBox(this , CHILD_PROXYPASSWORDLIST, "");
193: } else if (name.equals(CHILD_NETLETPROXYTUNNEL_LBL)) {
194: model.setCurrentRow(model
195: .getGWAttributeIndex(ATTR_NETLETPROXYTUNNEL));
196: return new StaticTextField(this ,
197: CHILD_NETLETPROXYTUNNEL_LBL, model.getAttrLabel());
198: } else if (name.equals(CHILD_NETLETPROXYTUNNEL)) {
199: return new CheckBox(this , CHILD_NETLETPROXYTUNNEL, "true",
200: "false", false);
201: } else if (name.equals(CHILD_PROXYSERVER_LBL)) {
202: return new StaticTextField(this , CHILD_PROXYSERVER_LBL,
203: "Server");
204: } else if (name.equals(CHILD_PROXYSERVER)) {
205: return new TextField(this , CHILD_PROXYSERVER, "");
206: } else if (name.equals(CHILD_PROXYUSER_LBL)) {
207: return new StaticTextField(this , CHILD_PROXYUSER_LBL,
208: "User Name");
209: } else if (name.equals(CHILD_PROXYUSER)) {
210: return new TextField(this , CHILD_PROXYUSER, "");
211: } else if (name.equals(CHILD_PROXYPASSWORD_LBL)) {
212: return new StaticTextField(this , CHILD_PROXYPASSWORD_LBL,
213: "Password");
214: } else if (name.equals(CHILD_PROXYPASSWORD)) {
215: return new TextField(this , CHILD_PROXYPASSWORD, "");
216: } else if (name.equals(CHILD_GWPROFILEFOR)) {
217: return new StaticTextField(this , CHILD_GWPROFILEFOR,
218: modelManager.getString("props.2") + " "
219: + modelManager.getString("for.label"));
220: } else if (name.equals(CHILD_ADD_BTN)) {
221: return new IPlanetButton(this , CHILD_ADD_BTN, modelManager
222: .getString("add.button"));
223: } else if (name.equals(CHILD_REMOVE_BTN)) {
224: return new IPlanetButton(this , CHILD_REMOVE_BTN,
225: modelManager.getString("remove.button"));
226: } else if (name.equals(CHILD_ADDTOLIST_BTN)) {
227: return new IPlanetButton(this , CHILD_ADDTOLIST_BTN,
228: modelManager.getString("add.button"));
229: } else if (name.equals(CHILD_REMOVEFROMLIST_BTN)) {
230: return new IPlanetButton(this , CHILD_REMOVEFROMLIST_BTN,
231: modelManager.getString("remove.button"));
232: } else {
233: return super .createChild(name);
234: }
235: }
236:
237: /**
238: * To register all the child view objects and their classes.
239: */
240: protected void registerChildren() {
241: super .registerChildren();
242: registerChild(CHILD_USEPROXY_LBL, StaticTextField.class);
243: registerChild(CHILD_USEPROXY, CheckBox.class);
244: registerChild(CHILD_USEWEBPROXYURL_LBL, StaticTextField.class);
245: registerChild(CHILD_USEWEBPROXYURL, ListBox.class);
246: registerChild(CHILD_DONTUSEWEBPROXYURL_LBL,
247: StaticTextField.class);
248: registerChild(CHILD_DONTUSEWEBPROXYURL, ListBox.class);
249: registerChild(CHILD_PACFILEENABLED_LBL, StaticTextField.class);
250: registerChild(CHILD_PACFILEENABLED, CheckBox.class);
251: registerChild(CHILD_PACFILELOCATION_LBL, StaticTextField.class);
252: registerChild(CHILD_PACFILELOCATION, TextField.class);
253: registerChild(CHILD_DOMAINANDSUBDOMAINS_LBL,
254: StaticTextField.class);
255: registerChild(CHILD_DOMAINANDSUBDOMAINS, ListBox.class);
256: registerChild(CHILD_PROXYPASSWORDLIST_LBL,
257: StaticTextField.class);
258: registerChild(CHILD_PROXYPASSWORDLIST, ListBox.class);
259: registerChild(CHILD_NETLETPROXYTUNNEL_LBL,
260: StaticTextField.class);
261: registerChild(CHILD_NETLETPROXYTUNNEL, CheckBox.class);
262: registerChild(CHILD_PROXYSERVER_LBL, StaticTextField.class);
263: registerChild(CHILD_PROXYSERVER, TextField.class);
264: registerChild(CHILD_PROXYUSER_LBL, StaticTextField.class);
265: registerChild(CHILD_PROXYUSER, TextField.class);
266: registerChild(CHILD_PROXYPASSWORD_LBL, StaticTextField.class);
267: registerChild(CHILD_PROXYPASSWORD, TextField.class);
268: registerChild(CHILD_ADD_BTN, IPlanetButton.class);
269: registerChild(CHILD_REMOVE_BTN, IPlanetButton.class);
270: registerChild(CHILD_ADDTOLIST_BTN, IPlanetButton.class);
271: registerChild(CHILD_REMOVEFROMLIST_BTN, IPlanetButton.class);
272: }
273:
274: private void setCheckBoxInitialValue(String attributeName,
275: String childName) {
276: model.setCurrentRow(model.getGWAttributeIndex(attributeName));
277: CheckBox checkBox = (CheckBox) getDisplayField(childName);
278: Set valueSet = model.getAttrValues();
279: String value = null;
280: if (valueSet != null && valueSet.iterator().hasNext()) {
281: value = (String) valueSet.iterator().next();
282: }
283: if (value != null && value.equals("true"))
284: checkBox.setValue(value);
285: }
286:
287: private void setListBoxInitialValue(String attributeName,
288: String childName) {
289: model.setCurrentRow(model.getGWAttributeIndex(attributeName));
290: Set valueSet = model.getAttrValues();
291: String value = null;
292: OptionList optList = new OptionList();
293: ListBox lb = (ListBox) getChild(childName);
294: if (valueSet != null) {
295: Iterator iter = valueSet.iterator();
296:
297: while (iter.hasNext()) {
298: value = (String) iter.next();
299: optList.add(value, value);
300: }
301: }
302: optList.add("_______________________________________", "");
303: lb.setOptions(optList);
304: }
305:
306: private void setPasswdListBoxInitialValue(String attributeName,
307: String childName) {
308: model.setCurrentRow(model.getGWAttributeIndex(attributeName));
309: Set valueSet = model.getAttrValues();
310: String value = null;
311: OptionList optList = new OptionList();
312: ListBox lb = (ListBox) getChild(childName);
313:
314: if (valueSet != null) {
315: Iterator iter = valueSet.iterator();
316:
317: while (iter.hasNext()) {
318: value = (String) iter.next();
319: String s1 = "";
320: String s2 = "";
321: String s3 = "";
322: StringTokenizer st1 = new StringTokenizer(value, "|");
323: if (st1.hasMoreTokens()) {
324: s1 = st1.nextToken();
325: }
326: if (st1.hasMoreTokens()) {
327: s2 = st1.nextToken();
328: }
329: try {
330: if (st1.hasMoreTokens()) {
331: s3 = st1.nextToken();
332: }
333: } catch (NoSuchElementException nsee) {
334: s3 = "";
335: }
336: try {
337: optList.add(s1 + "|" + s2, s1 + "|" + s2 + "|"
338: + AMPasswordUtil.encrypt(s3));
339: } catch (Exception e) {
340: // Debug Error
341: }
342: addPasswordEntry(s1 + "|" + s2, s3);
343: }
344: }
345: optList.add("_______________________________________", "");
346: lb.setOptions(optList);
347: }
348:
349: public void beginDisplay(DisplayEvent event)
350: throws ModelControlException {
351: super .beginDisplay(event);
352: getModel();
353: setChildValues(model);
354: getGWModelMgr();
355: if (model != null) {
356: if (model.hasSchema()) {
357: setCheckBoxInitialValue(ATTR_USEPROXY, CHILD_USEPROXY);
358: setListBoxInitialValue(ATTR_USEWEBPROXYURL,
359: CHILD_USEWEBPROXYURL);
360: setListBoxInitialValue(ATTR_DONTUSEWEBPROXYURL,
361: CHILD_DONTUSEWEBPROXYURL);
362: setListBoxInitialValue(ATTR_DOMAINSANDSUBDOMAINS,
363: CHILD_DOMAINANDSUBDOMAINS);
364: setCheckBoxInitialValue(ATTR_PACFILEENABLED,
365: CHILD_PACFILEENABLED);
366: model.setCurrentRow(model
367: .getGWAttributeIndex(ATTR_PACFILELOCATION));
368: Set valueSet = model.getAttrValues();
369: String value = null;
370: if (valueSet != null && valueSet.iterator().hasNext()) {
371: value = (String) valueSet.iterator().next();
372: }
373: setDisplayFieldValue(CHILD_PACFILELOCATION, value);
374: setPasswdListBoxInitialValue(ATTR_PROXYPASSWORDLIST,
375: CHILD_PROXYPASSWORDLIST);
376: setCheckBoxInitialValue(ATTR_NETLETPROXYTUNNEL,
377: CHILD_NETLETPROXYTUNNEL);
378: setDisplayFieldValue(CHILD_ADDTOLIST_BTN, modelManager
379: .getString("add.button"));
380: setDisplayFieldValue(CHILD_REMOVEFROMLIST_BTN,
381: modelManager.getString("remove.button"));
382: }
383: }
384: }
385:
386: private Set getListValue(String childName) {
387: ListBox lb = (ListBox) getDisplayField(childName);
388: Object[] objValues = (Object[]) lb.getValues();
389: Set newSet = new HashSet();
390: StringBuffer sb = new StringBuffer();
391: if ((objValues == null) || (objValues.length == 0)) {
392: // Empty values not allowed
393: return newSet;
394: }
395: int size = objValues.length;
396: for (int i = 0; i < size; i++) {
397: String proxyentry = (String) objValues[i];
398: newSet.add(proxyentry);
399: }
400: return newSet;
401: }
402:
403: private void addPasswordEntry(String key, String value) {
404: try {
405: // Decrypting a non-encrypted string always returns the same string
406: // By this, we detect new password and old password
407: if (AMPasswordUtil.decrypt(value) == value)
408: ProxyPasswordValues.put(key, value);
409: else
410: ProxyPasswordValues.put(key, AMPasswordUtil
411: .decrypt(value));
412: } catch (Exception e) {
413: // Debug Error
414: }
415: }
416:
417: private void removePasswordEntry(String key) {
418: ProxyPasswordValues.remove(key);
419: }
420:
421: private void storePasswordEntry() {
422: StringBuffer sb = new StringBuffer();
423: Set newSet = new HashSet();
424: for (Iterator it = ProxyPasswordValues.entrySet().iterator(); it
425: .hasNext();) {
426: Map.Entry entry = (Map.Entry) it.next();
427: Object key = entry.getKey();
428: Object value = entry.getValue();
429: String str = key + "|" + value;
430: sb.append(str);
431: newSet.add(sb.toString());
432: sb = new StringBuffer();
433: }
434: String configName = (String) getDisplayFieldValue(HIDDEN_CONFIG_NAME);
435: GatewayModel m = getModel();
436: m.process(configName);
437: Map map = new HashMap(10);
438: map.put(ATTR_PROXYPASSWORDLIST, newSet);
439: if (!map.isEmpty()) {
440: try {
441: m.store(configName, map);
442: } catch (Exception e) {
443: // Debug Error
444: }
445: }
446: }
447:
448: public void handleSubmitButtonRequest(RequestInvocationEvent event)
449: throws ModelControlException, SSOException {
450: String configName = (String) getDisplayFieldValue(HIDDEN_CONFIG_NAME);
451: GatewayModel m = getModel();
452: m.process(configName);
453: Map map = new HashMap(10);
454: Set newSet = new HashSet();
455:
456: newSet.add((String) getDisplayFieldValue(CHILD_USEPROXY));
457: map.put(ATTR_USEPROXY, newSet);
458:
459: map
460: .put(ATTR_USEWEBPROXYURL,
461: getListValue(CHILD_USEWEBPROXYURL));
462:
463: map.put(ATTR_DONTUSEWEBPROXYURL,
464: getListValue(CHILD_DONTUSEWEBPROXYURL));
465:
466: map.put(ATTR_DOMAINSANDSUBDOMAINS,
467: getListValue(CHILD_DOMAINANDSUBDOMAINS));
468:
469: /*
470: * newSet = new HashSet();
471: * newSet.add(getListValue(CHILD_PROXYPASSWORDLIST));
472: * map.put(ATTR_PROXYPASSWORDLIST, newSet);
473: */
474:
475: newSet = new HashSet();
476: newSet.add((String) getDisplayFieldValue(CHILD_PACFILEENABLED));
477: map.put(ATTR_PACFILEENABLED, newSet);
478:
479: newSet = new HashSet();
480: newSet
481: .add((String) getDisplayFieldValue(CHILD_PACFILELOCATION));
482: map.put(ATTR_PACFILELOCATION, newSet);
483:
484: newSet = new HashSet();
485: newSet
486: .add((String) getDisplayFieldValue(CHILD_NETLETPROXYTUNNEL));
487: map.put(ATTR_NETLETPROXYTUNNEL, newSet);
488:
489: if (!map.isEmpty()) {
490: try {
491: m.store(configName, map);
492: } catch (Exception e) {
493: // Debug Error
494: }
495: }
496: forwardTo();
497: }
498:
499: public void handleAddToListButtonRequest(
500: RequestInvocationEvent event) throws ModelControlException,
501: SSOException {
502: String s1 = (String) getDisplayFieldValue(CHILD_PROXYSERVER);
503: String s2 = (String) getDisplayFieldValue(CHILD_PROXYUSER);
504: String s3 = (String) getDisplayFieldValue(CHILD_PROXYPASSWORD);
505: addPasswordEntry(s1 + "|" + s2, s3);
506: storePasswordEntry();
507: forwardTo();
508: }
509:
510: public void handleRemoveFromListButtonRequest(
511: RequestInvocationEvent event) throws ModelControlException,
512: SSOException {
513: String s1 = (String) getDisplayFieldValue(CHILD_PROXYSERVER);
514: String s2 = (String) getDisplayFieldValue(CHILD_PROXYUSER);
515: String sb = s1 + "|" + s2;
516: removePasswordEntry(sb);
517: storePasswordEntry();
518: forwardTo();
519: }
520:
521: }
|