001: /**
002: * $Id: NewConfiguredProducerBean.java,v 1.10 2006/01/03 18:20:36 yue Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.wsrp.consumer;
014:
015: import java.net.MalformedURLException;
016: import java.net.URL;
017: import java.util.ArrayList;
018: import java.util.Arrays;
019: import java.util.Collections;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.LinkedList;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Properties;
026: import java.util.Set;
027: import java.util.logging.Level;
028:
029: import javax.faces.application.FacesMessage;
030: import javax.faces.component.UIComponent;
031: import javax.faces.context.FacesContext;
032: import javax.faces.event.ValueChangeEvent;
033: import javax.faces.validator.ValidatorException;
034: import javax.management.ObjectName;
035:
036: import com.sun.data.provider.impl.ObjectListDataProvider;
037: import com.sun.portal.admin.common.util.AdminUtil;
038: import com.sun.web.ui.event.WizardEvent;
039: import com.sun.web.ui.event.WizardEventListener;
040: import com.sun.web.ui.model.Option;
041:
042: public class NewConfiguredProducerBean extends ConsumerBaseBean
043: implements WizardEventListener {
044:
045: public static final String NO_IDENTITY_PROPAGATION = "com.sun.portal.wsrp.identity.none";
046:
047: public static final String SSOTOKEN_IDENTITY_PROPAGATION = "com.sun.portal.wsrp.identity.ssotoken";
048:
049: public static final String OASIS_WSS_USERNAME_ONLY_PROPAGATION = "org.oasis.wss.username.token.profile.usernameonly";
050:
051: public static final String OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION = "org.oasis.wss.username.token.profile.passworddigest";
052:
053: public static final String OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION = "org.oasis.wss.username.token.profile.passwordtext";
054:
055: public static final String REGISTRY_SEARCH = "RegistrySearch";
056:
057: public static final String REGISTRY_SEARCH_TYPE = AdminUtil.PORTAL_MBEAN_TYPE
058: + "." + REGISTRY_SEARCH;
059:
060: public static final String PRODUCER = "Producer";
061: public static final String PORTLET = "Portlet";
062: public static final String IN_BAND = "InBand";
063: public static final String OUT_OF_BAND = "OutOfBand";
064: private String name = "";
065: private Option[] identityPropagationTypes = null;
066: private String identityPropagationType = NO_IDENTITY_PROPAGATION;
067: private String wsdlURL = "";
068: private String searchBasedOn = PRODUCER;
069: private String producerName = "";
070: private String producerDesc = "";
071: private String portletHandle = "";
072: private String portletDesc = "";
073: private ObjectListDataProvider searchResults = null;
074: private boolean registrationRequired = false;
075: private boolean inbandSupported = false;
076: private Option[] chooseBandOptions = null;
077: private String chooseBand = IN_BAND;
078: private ObjectListDataProvider registrationProperties = null;
079: private String handle = "";
080: private Option[] allRoles = null;
081: private ObjectListDataProvider userCategoryMapping = null;
082:
083: public String getName() {
084: return name;
085: }
086:
087: public void setName(String name) {
088: this .name = name;
089: }
090:
091: public Option[] getIdentityPropagationTypes() {
092: if (identityPropagationTypes == null) {
093: identityPropagationTypes = new Option[] {
094: new Option(NO_IDENTITY_PROPAGATION, rb
095: .getString(NO_IDENTITY_PROPAGATION)),
096: new Option(SSOTOKEN_IDENTITY_PROPAGATION, rb
097: .getString(SSOTOKEN_IDENTITY_PROPAGATION)),
098: new Option(
099: OASIS_WSS_USERNAME_ONLY_PROPAGATION,
100: rb
101: .getString(OASIS_WSS_USERNAME_ONLY_PROPAGATION)),
102: new Option(
103: OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION,
104: rb
105: .getString(OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION)),
106: new Option(
107: OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION,
108: rb
109: .getString(OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION)) };
110: }
111:
112: return identityPropagationTypes;
113: }
114:
115: public String getIdentityPropagationTypeDisplayName() {
116: return rb.getString(identityPropagationType);
117: }
118:
119: public String getIdentityPropagationType() {
120: return identityPropagationType;
121: }
122:
123: public void setIdentityPropagationType(
124: String identityPropagationType) {
125: this .identityPropagationType = identityPropagationType;
126: }
127:
128: public String getWSDLURL() {
129: return wsdlURL;
130: }
131:
132: public void setWSDLURL(String wsdlURL) {
133: this .wsdlURL = wsdlURL;
134: }
135:
136: public String getProducer() {
137: return PRODUCER.equals(searchBasedOn) ? PRODUCER : null;
138: }
139:
140: public void setProducer(String selected) {
141: if (PRODUCER.equals(selected)) {
142: searchBasedOn = PRODUCER;
143: }
144: }
145:
146: public String getPortlet() {
147: return PORTLET.equals(searchBasedOn) ? PORTLET : null;
148: }
149:
150: public void setPortlet(String selected) {
151: if (PORTLET.equals(selected)) {
152: searchBasedOn = PORTLET;
153: }
154: }
155:
156: public String getProducerName() {
157: return producerName;
158: }
159:
160: public void setProducerName(String producerName) {
161: this .producerName = producerName;
162: }
163:
164: public String getProducerDesc() {
165: return producerDesc;
166: }
167:
168: public void setProducerDesc(String producerDesc) {
169: this .producerDesc = producerDesc;
170: }
171:
172: public String getPortletHandle() {
173: return portletHandle;
174: }
175:
176: public void setPortletHandle(String portletHandle) {
177: this .portletHandle = portletHandle;
178: }
179:
180: public String getPortletDesc() {
181: return portletDesc;
182: }
183:
184: public void setPortletDesc(String portletDesc) {
185: this .portletDesc = portletDesc;
186: }
187:
188: public ObjectListDataProvider getSearchResults() {
189: if (searchResults == null) {
190: searchResults = new ObjectListDataProvider(
191: Collections.EMPTY_LIST);
192: searchResults.setObjectType(SimpleWSDLURLBean.class);
193: }
194:
195: return searchResults;
196: }
197:
198: public void setSearchResults(ObjectListDataProvider searchResults) {
199: this .searchResults = searchResults;
200: }
201:
202: public boolean isRegistrationRequired() {
203: return registrationRequired;
204: }
205:
206: public boolean isInbandSupported() {
207: return inbandSupported;
208: }
209:
210: public Option[] getChooseBandOptions() {
211: if (chooseBandOptions == null) {
212: chooseBandOptions = new Option[] {
213: new Option(
214: IN_BAND,
215: rb
216: .getString("newConfiguredProducer2_1.label.inBand")),
217: new Option(
218: OUT_OF_BAND,
219: rb
220: .getString("newConfiguredProducer2_1.label.outOfBand")) };
221: }
222:
223: return chooseBandOptions;
224: }
225:
226: public String getChooseBand() {
227: return chooseBand;
228: }
229:
230: public void setChooseBand(String chooseBand) {
231: this .chooseBand = chooseBand;
232: }
233:
234: public String getRegistrationInstruction() {
235: if (!inbandSupported) {
236: return rb
237: .getString("newConfiguredProducer2_2.detail.outOfBand");
238: } else if (IN_BAND.equals(chooseBand)) {
239: return rb
240: .getString("newConfiguredProducer2_2.detail.regProp");
241: } else if (OUT_OF_BAND.equals(chooseBand)) {
242: return rb
243: .getString("newConfiguredProducer2_2.detail.regHandle");
244: } else {
245: return "";
246: }
247: }
248:
249: public ObjectListDataProvider getRegistrationProperties() {
250: if (registrationProperties != null) {
251: registrationProperties.commitChanges();
252: }
253:
254: return registrationProperties;
255: }
256:
257: public void setRegistrationProperties(
258: ObjectListDataProvider registrationProperties) {
259: this .registrationProperties = registrationProperties;
260: }
261:
262: public String getHandle() {
263: return handle;
264: }
265:
266: public void setHandle(String handle) {
267: this .handle = handle;
268: }
269:
270: public Option[] getAllRoles() {
271: return allRoles;
272: }
273:
274: public int getListBoxRows() {
275: int rows = 0;
276:
277: if (allRoles != null) {
278: rows = allRoles.length;
279: }
280:
281: if (rows > 12) {
282: rows = 12;
283: }
284:
285: return rows;
286: }
287:
288: public ObjectListDataProvider getUserCategoryMapping() {
289: if (userCategoryMapping == null) {
290: userCategoryMapping = new ObjectListDataProvider(
291: Collections.EMPTY_LIST);
292: userCategoryMapping.setObjectType(SimpleUCMBean.class);
293: }
294:
295: userCategoryMapping.commitChanges();
296: return userCategoryMapping;
297: }
298:
299: public void setUserCategoryMapping(
300: ObjectListDataProvider userCategoryMapping) {
301: this .userCategoryMapping = userCategoryMapping;
302: }
303:
304: public boolean getHasUserCategories() {
305: return getUserCategoryMapping().getRowCount() > 0;
306: }
307:
308: public void validate(FacesContext context, UIComponent component,
309: Object value) throws ValidatorException {
310:
311: clearAlert();
312: String id = component.getId();
313: String val = ((String) value).trim();
314:
315: if (id.equals("WSDLURL")) {
316: try {
317: URL url = new URL(val);
318: } catch (MalformedURLException e) {
319: showAlert();
320: setAlertSummary(rb
321: .getString("newConfiguredProducer2.label.invalid.WSDLURL"));
322: setAlertDetail(getAlertSummary() + " '" + value + "'");
323: }
324: }
325:
326: if (isAlert()) {
327: throw new ValidatorException(new FacesMessage(
328: FacesMessage.SEVERITY_ERROR,
329: "WizardValidator error", getAlertDetail()));
330: }
331: }
332:
333: public void producerSelected(ValueChangeEvent event) {
334: setProducer((String) event.getNewValue());
335: }
336:
337: public void producerNameChanged(ValueChangeEvent event) {
338: setProducerName((String) event.getNewValue());
339: }
340:
341: public void producerDescChanged(ValueChangeEvent event) {
342: setProducerDesc((String) event.getNewValue());
343: }
344:
345: public void portletSelected(ValueChangeEvent event) {
346: setPortlet((String) event.getNewValue());
347: }
348:
349: public void portletHandleChanged(ValueChangeEvent event) {
350: setPortletHandle((String) event.getNewValue());
351: }
352:
353: public void portletDescChanged(ValueChangeEvent event) {
354: setPortletDesc((String) event.getNewValue());
355: }
356:
357: public void search() {
358: List urls = new ArrayList();
359: LinkedList path = new LinkedList();
360: path.addFirst(getDomain());
361: path.addFirst(getSessionAttribute(ATTR_SELECTED_PORTAL));
362: path.addFirst(REGISTRY_SEARCH);
363: String searchMethod = null;
364: Properties searchCriteria = new Properties();
365: String producerURL = null;
366: String[] signature = { Properties.class.getName() };
367: Object[] params = { searchCriteria };
368:
369: if (PRODUCER.equals(searchBasedOn)) {
370: searchMethod = "searchProducer";
371: searchCriteria.setProperty("producer.name", producerName);
372: searchCriteria.setProperty("producer.description",
373: producerDesc);
374: producerURL = "producer.urls";
375: } else {
376: searchMethod = "searchPortlet";
377: searchCriteria.setProperty("portlet.name", portletHandle);
378: searchCriteria.setProperty("portlet.description",
379: portletDesc);
380: producerURL = "portlet.producer.urls";
381: }
382:
383: try {
384: // Object name of RegistrySearch.
385: ObjectName objectName = AdminUtil
386: .getResourceMBeanObjectName(REGISTRY_SEARCH_TYPE,
387: path);
388:
389: Set results = (Set) getMBeanServerConnection().invoke(
390: objectName, searchMethod, params, signature);
391:
392: for (Iterator i = results.iterator(); i.hasNext();) {
393: Map result = (Map) i.next();
394: String urlsString = (String) result.get(producerURL);
395:
396: // Remove "[" at the beginning and "]" at the end.
397: urlsString = urlsString.substring(1, urlsString
398: .length() - 1);
399:
400: // Remove ", " in between, if there are more than one URL.
401: String[] pURLs = urlsString.split(", ");
402:
403: for (int j = 0; j < pURLs.length; j++) {
404: SimpleWSDLURLBean url = new SimpleWSDLURLBean();
405: url.setWSDLURL(pURLs[j]);
406:
407: if (!urls.contains(url)) {
408: urls.add(url);
409: }
410: }
411: }
412:
413: clearAlert();
414: } catch (Exception e) {
415: log(Level.SEVERE, "NewConfiguredProducerBean.search()", e);
416: showAlert();
417: setAlertSummary(rb
418: .getString("newConfiguredProducer2.search.alert.summary"));
419: setAlertDetail(rb
420: .getString("newConfiguredProducer2.search.alert.detail"));
421: }
422:
423: searchResults = new ObjectListDataProvider(urls);
424: searchResults.setObjectType(SimpleWSDLURLBean.class);
425: }
426:
427: public boolean handleEvent(WizardEvent event) {
428: clearAlert();
429:
430: switch (event.getNavigationEvent()) {
431: case WizardEvent.NEXT:
432: String id = event.getWizard().getCurrentStep().getId();
433:
434: if (id.equals("step2")) {
435: loadProducerInfo();
436: }
437:
438: break;
439: case WizardEvent.CANCEL:
440: case WizardEvent.CLOSE:
441: clearData();
442: break;
443: case WizardEvent.FINISH:
444: createConfiguredProducer();
445: break;
446: default:
447: break;
448: }
449:
450: return !isAlert();
451: }
452:
453: public boolean isTransient() {
454: return false;
455: }
456:
457: public void setTransient(boolean flag) {
458: }
459:
460: public Object saveState(FacesContext context) {
461: return null;
462: }
463:
464: public void restoreState(FacesContext context, Object state) {
465: }
466:
467: public void clearData() {
468: clearAlert();
469: name = "";
470: identityPropagationType = NO_IDENTITY_PROPAGATION;
471: wsdlURL = "";
472: searchBasedOn = PRODUCER;
473: producerName = "";
474: producerDesc = "";
475: portletHandle = "";
476: portletDesc = "";
477: searchResults = null;
478: registrationRequired = false;
479: inbandSupported = false;
480: chooseBand = IN_BAND;
481: registrationProperties = null;
482: handle = "";
483: allRoles = null;
484: userCategoryMapping = null;
485: }
486:
487: private void loadProducerInfo() {
488: // MBean path of Consumer.
489: List path = getConsumerPath();
490:
491: try {
492: // Object name of Consumer.
493: ObjectName objectName = AdminUtil
494: .getResourceMBeanObjectName(CONSUMER_TYPE, path);
495:
496: String[] signature = { String.class.getName(),
497: String.class.getName() };
498:
499: Object[] params = { getCurrentDN(), wsdlURL };
500:
501: Map info = (Map) getMBeanServerConnection().invoke(
502: objectName, "getProducerInfo", params, signature);
503:
504: Boolean required = (Boolean) info
505: .get("RegistrationRequired");
506: registrationRequired = required.booleanValue();
507: Boolean supported = (Boolean) info.get("InbandSupported");
508: inbandSupported = supported.booleanValue();
509:
510: if (!inbandSupported) {
511: chooseBand = OUT_OF_BAND;
512: }
513:
514: Map rpds = (Map) info
515: .get("RegistrationPropertyDescription");
516: Set entrySet = rpds.entrySet();
517: List rpList = new ArrayList(rpds.size());
518:
519: for (Iterator i = entrySet.iterator(); i.hasNext();) {
520: Map.Entry entry = (Map.Entry) i.next();
521: String name = (String) entry.getKey();
522: String description = (String) entry.getValue();
523: SimpleRPBean registrationProperty = new SimpleRPBean();
524: registrationProperty.setName(name);
525: registrationProperty.setDescription(description);
526: registrationProperty.setPropValue("");
527: rpList.add(registrationProperty);
528: }
529:
530: registrationProperties = new ObjectListDataProvider(rpList);
531: registrationProperties.setObjectType(SimpleRPBean.class);
532: Map ucds = (Map) info.get("userCategoryDescriptions");
533: entrySet = ucds.entrySet();
534: List ucList = new ArrayList(ucds.size());
535:
536: for (Iterator i = entrySet.iterator(); i.hasNext();) {
537: Map.Entry entry = (Map.Entry) i.next();
538: String itemName = (String) entry.getKey();
539: String description = (String) entry.getValue();
540: SimpleUCMBean userCategory = new SimpleUCMBean();
541: userCategory.setUserCategory(itemName);
542: userCategory.setRoles(new String[0]);
543: userCategory.setDescription(description);
544: ucList.add(userCategory);
545: }
546:
547: userCategoryMapping = new ObjectListDataProvider(ucList);
548: userCategoryMapping.setObjectType(SimpleUCMBean.class);
549: Map roleMap = (Map) info.get("AllRoles");
550: entrySet = roleMap.entrySet();
551: allRoles = new Option[roleMap.size()];
552: int j = 0;
553:
554: for (Iterator i = entrySet.iterator(); i.hasNext(); j++) {
555: Map.Entry entry = (Map.Entry) i.next();
556: String roleDN = (String) entry.getKey();
557: String roleDNDisplayString = (String) entry.getValue();
558: allRoles[j] = new Option(roleDN, roleDNDisplayString);
559: }
560: } catch (Exception e) {
561: log(Level.SEVERE,
562: "NewConfiguredProducerBean.loadProducerInfo()", e);
563: showAlert();
564: setAlertSummary(rb
565: .getString("newConfiguredProducer2.loadProducerInfo.alert.summary"));
566: setAlertDetail(rb
567: .getString("newConfiguredProducer2.loadProducerInfo.alert.detail"));
568: }
569: }
570:
571: private void createConfiguredProducer() {
572: name = (name == null) ? "" : name.trim();
573: handle = (handle == null) ? "" : handle.trim();
574: Properties prop = new Properties();
575: registrationProperties.commitChanges();
576: List rpList = registrationProperties.getList();
577:
578: for (int i = 0; i < rpList.size(); i++) {
579: SimpleRPBean registrationProperty = (SimpleRPBean) rpList
580: .get(i);
581: String name = registrationProperty.getName();
582: String value = registrationProperty.getPropValue();
583: prop.setProperty(name, (value == null) ? "" : value.trim());
584: }
585:
586: Map ucMap = null;
587:
588: if (getHasUserCategories()) {
589: ucMap = new HashMap();
590: userCategoryMapping.commitChanges();
591: List ucList = userCategoryMapping.getList();
592:
593: for (int i = 0; i < ucList.size(); i++) {
594: SimpleUCMBean ucm = (SimpleUCMBean) ucList.get(i);
595: ucMap.put(ucm.getUserCategory(), Arrays.asList(ucm
596: .getRoles()));
597: }
598: }
599:
600: // MBean path of Consumer.
601: List path = getConsumerPath();
602:
603: try {
604: // Object name of Consumer.
605: ObjectName objectName = AdminUtil
606: .getResourceMBeanObjectName(CONSUMER_TYPE, path);
607:
608: String lastParamType = Properties.class.getName();
609: Object lastParam = (Object) prop;
610:
611: if (registrationRequired && !IN_BAND.equals(chooseBand)) {
612: lastParamType = String.class.getName();
613: lastParam = (Object) handle;
614: }
615:
616: String[] signature = { String.class.getName(),
617: String.class.getName(), String.class.getName(),
618: String.class.getName(), Map.class.getName(),
619: lastParamType };
620:
621: Object[] params = { getCurrentDN(), name, wsdlURL,
622: identityPropagationType, ucMap, lastParam };
623:
624: getMBeanServerConnection().invoke(objectName,
625: "createConfiguredProducer", params, signature);
626:
627: setAlertType(INFORMATION);
628: setAlertSummary(rb
629: .getString("newConfiguredProducerResult.success.summary"));
630: setAlertDetail(rb
631: .getString("newConfiguredProducerResult.success.detail"));
632: } catch (Exception e) {
633: log(
634: Level.SEVERE,
635: "NewConfiguredProducerBean.createConfiguredProducer()",
636: e);
637: setAlertType(ERROR);
638: setAlertSummary(rb
639: .getString("newConfiguredProducerResult.failed.summary"));
640: setAlertDetail(rb
641: .getString("newConfiguredProducerResult.failed.detail"));
642: }
643: }
644: }
|