001: /**
002: * $Id: ListConfigurationsByDnBean.java,v 1.6 2005/09/21 15:29:57 fo160993 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.ssoa;
014:
015: import java.util.*;
016: import java.util.logging.Level;
017: import javax.faces.context.FacesContext;
018: import javax.management.MBeanServerConnection;
019: import javax.servlet.http.HttpServletRequest;
020:
021: import com.sun.data.provider.DataProvider;
022: import com.sun.data.provider.impl.ObjectListDataProvider;
023:
024: import com.sun.portal.admin.common.util.AdminClientUtil;
025:
026: // Session-based bean because the dn selector toolbar doesn't always update
027: // the session before the bean is updated
028: public class ListConfigurationsByDnBean extends ListConfigurationsBean {
029:
030: protected String GLOBAL_DN_LABEL = null;
031: private String locationDN = null;
032: private boolean hasService = false;
033:
034: public ListConfigurationsByDnBean() {
035: log(Level.FINEST, "Start ListConfigurationsByDnBean()");
036: resetConfigurations();
037: //locationDN = (String)getCurrentDN();
038: //checkSSOAService();
039: }
040:
041: private boolean isDNChanged() {
042: log(Level.FINEST, "Start isDNChanged");
043: return !locationDN.equals((String) getCurrentDN());
044: }
045:
046: public void resetConfigurations() {
047: log(Level.FINEST, "Start resetConfigurations");
048: locationDN = (String) getCurrentDN();
049: hasService = hasSSOAService(locationDN);
050: if (hasService) {
051: Map configs = null;
052: // String templateName = (String) getSessionAttribute(ATTR_SELECTED_TEMPLATE);
053: //String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
054: // String dn = (String) getCurrentDN();
055: // SSOA templates names are returned by SSOAdapter MBean method resetConfigurationNames
056: log(Level.FINEST, "Getting configurations for "
057: + locationDN);
058: MBeanServerConnection conn = getMBeanServerConnection();
059: try {
060: // This can throw AttributeNotFoundException, MBeanException, InstanceNotFoundException
061: // ReflectionException, RuntimeOperationsException, or IOException
062: String[] signature = { String.class.getName() };
063: Object[] params = { locationDN };
064: MBeanServerConnection connection = getMBeanServerConnection();
065: // This can throw AttributeNotFoundException, MBeanException, InstanceNotFoundException
066: // ReflectionException, RuntimeOperationsException, or IOException
067: configs = (Map) connection.invoke(objectName,
068: "getConfigurationNamesByDn", params, signature);
069: } catch (Exception ex) {
070: log(
071: Level.SEVERE,
072: "ListConfigurationsByDnBean.resetConfigurations(): Exception when trying to get the list of configurations",
073: ex);
074: configs = new HashMap();
075: }
076: ArrayList configList = new ArrayList(configs.size());
077: Set names = configs.keySet();
078: Iterator iter = names.iterator();
079: while (iter.hasNext()) {
080: String name = (String) iter.next();
081: String basis = (String) configs.get(name);
082: ConfigurationBean cb = new ConfigurationBean(
083: locationDN, name, basis);
084: // Cheesy workaround for global DNs
085: if (GLOBAL_LOCATION_DN.equals(locationDN)) {
086: if (GLOBAL_DN_LABEL == null) {
087: GLOBAL_DN_LABEL = (String) rbMap
088: .get("ssoa.global.dn.label");
089: }
090: cb.setLabel(GLOBAL_DN_LABEL);
091: }
092: configList.add(cb);
093: }
094: Collections.sort(configList);
095: configurations = new ObjectListDataProvider(configList);
096: } else {
097: configurations = null;
098: }
099: }
100:
101: public DataProvider getConfigurations() {
102: log(Level.FINEST, "Start getConfigurations");
103: if (getSessionAttribute("resetSSOA") != null) {
104: log(Level.FINEST, "resetSSOA is non-null");
105: resetConfigurations();
106: removeFromSession("resetSSOA");
107: }
108: if (isDNChanged()) {
109: log(Level.FINEST, "DN has changed");
110: resetConfigurations();
111: }
112: return configurations;
113: }
114:
115: public String gotoConfigurationHome() {
116: HttpServletRequest req = (HttpServletRequest) FacesContext
117: .getCurrentInstance().getExternalContext().getRequest();
118: String configName = (String) req
119: .getParameter(ATTR_SELECTED_CONFIG);
120: String configDn = (String) req
121: .getParameter(ATTR_CURRENT_LOCATION_DN);
122: setSessionAttribute(ATTR_SELECTED_CONFIG, configName);
123: setSessionAttribute(ATTR_CURRENT_LOCATION_DN, configDn);
124: log(Level.FINEST,
125: "ListConfigurationsBean.gotoConfigurationHome: go to "
126: + configName + " at " + configDn);
127: return "gotoConfigurationHome";
128: }
129:
130: public String gotoTemplateHome() {
131: HttpServletRequest req = (HttpServletRequest) FacesContext
132: .getCurrentInstance().getExternalContext().getRequest();
133: String templateId = (String) req
134: .getParameter(ATTR_SELECTED_TEMPLATE);
135: setSessionAttribute(ATTR_SELECTED_TEMPLATE, templateId);
136: log(Level.FINEST,
137: "ListConfigurationsBean.gotoTemplateHome: Go to "
138: + templateId);
139: return "gotoTemplateHome";
140: }
141:
142: public String gotoCreateConfiguration() {
143: return "gotoCreateConfiguration";
144: }
145:
146: public String back() {
147: return "back";
148: }
149:
150: public String getCurrentDnLabel() {
151: if (GLOBAL_LOCATION_DN.equals(getCurrentDN())) {
152: return GLOBAL_DN_LABEL;
153: }
154: return (String) getCurrentDN();
155: }
156:
157: // Return true if the current dn has the SSOAdapter service
158: public boolean getHasService() {
159: // log(Level.FINEST, "ListConfigurationsByDnBean.getHasService: Returning "+hasService);
160: return hasService;
161: }
162:
163: // This method will check the current dn for whether the SSOAdapter service
164: // has been assigned. If not, it will set the error message. Looking for
165: // a better way to show the error to the user.
166: public boolean hasSSOAService(Object dn) {
167: // Make sure the dn has the ssoadapter service template
168: log(Level.FINEST,
169: "ListConfigurationsByDnBean.hasSSOAService: Start check for dn "
170: + dn);
171: boolean available = false;
172: try {
173: String[] signature = { String.class.getName() };
174: Object[] params = { dn };
175: MBeanServerConnection connection = getMBeanServerConnection();
176: // This can throw AttributeNotFoundException, MBeanException, InstanceNotFoundException
177: // ReflectionException, RuntimeOperationsException, or IOException
178: Boolean hasServiceBool = (Boolean) connection.invoke(
179: objectName, "hasSSOAdapterService", params,
180: signature);
181: available = hasServiceBool.booleanValue();
182: if (!available) {
183: log(
184: Level.SEVERE,
185: "ListConfigurationsByDnBean.checkSSOAService: dn "
186: + dn
187: + " does not have the SSOAdapter service registered.");
188: }
189: } catch (Exception ex) {
190: log(
191: Level.SEVERE,
192: "ListConfigurationsByDnBean.checkSSOAService: Exception when attempting to check ssoadapter service for dn "
193: + dn, ex);
194: available = false;
195: }
196: return available;
197: }
198:
199: }
|