/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.jvnet.glassfish.comms.admin.gui.extensions.handlers;
import com.sun.enterprise.tools.admingui.util.GuiUtil;
import org.jvnet.glassfish.comms.admin.gui.extensions.util.SipUtil;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import com.sun.enterprise.tools.admingui.util.JMXUtil;
import javax.management.AttributeList;
import javax.management.Attribute;
import javax.net.ssl.SSLServerSocketFactory;
import java.util.Vector;
import javax.management.ObjectName;
public class HttpListenerHandler {
public static final String[] listenerAttributeNames = new String[]{
"type"
};
/**
* The handler is called from the SipUtilities file using reflection.
* @param context The HandlerContext.
*
*/
public static void updateSaveHttpListenerValues(HandlerContext handlerCtx) {
String type = (String) handlerCtx.getInputValue("ListenerType");
String httpListenerName = (String) handlerCtx.getInputValue("HttpName");
Boolean edit = (Boolean) handlerCtx.getInputValue("Edit");
HashMap http_Props = (HashMap) handlerCtx.getInputValue("HttpProps");
try {
if (!edit) {
HashMap attributeMap = new HashMap();
Iterator<String> it = http_Props.keySet().iterator();
while (it.hasNext()) {
String propName = it.next();
Object value = http_Props.get(propName);
attributeMap.put(propName, value);
}
attributeMap.put("type", type);
handlerCtx.getFacesContext().getExternalContext().getSessionMap().put("httpProps", attributeMap);
} else {
String configName = (String) handlerCtx.getInputValue("ConfigName");
ObjectName httpListener = SipUtil.getHttpListener(SipUtil.getHttpService(configName),
httpListenerName);
HashMap attributeMap = new HashMap();
attributeMap.put("type", type);
SipUtil.setAttributeValues(httpListener, attributeMap);
}
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
}
public static void updateGetHttpListenerValues(HandlerContext handlerCtx) {
try {
Boolean edit = (Boolean) handlerCtx.getInputValue("Edit");
Boolean fromStep2 = (Boolean) handlerCtx.getInputValue("FromStep2");
if (!edit) {
if ((fromStep2 == null) || (!fromStep2)) {
handlerCtx.getFacesContext().getExternalContext().getSessionMap().put("httpProps", new HashMap());
handlerCtx.setOutputValue("ListenerType", "default");
} else {
Map props = (Map) handlerCtx.getFacesContext().getExternalContext().getSessionMap().get("httpProps");
handlerCtx.setOutputValue("ListenerType", props.get("type"));
}
return;
}
String listenerName = (String) handlerCtx.getInputValue("HttpName");
String configName = (String) handlerCtx.getInputValue("ConfigName");
ObjectName httpListener = SipUtil.getHttpListener(SipUtil.getHttpService(configName),
listenerName);
HashMap listenerProps = SipUtil.getAttributeValues(httpListener,
listenerAttributeNames);
handlerCtx.setOutputValue("ListenerType",
listenerProps.get("type"));
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
}
public static void saveHttpSSLProperties(HandlerContext handlerContext) {
try {
String listenerName = (String) handlerContext.getInputValue("Name");
String configName = (String) handlerContext.getInputValue("ConfigName");
ObjectName httpService = SipUtil.getHttpService(configName);
ObjectName ssl = null;
ObjectName httpListener = null;
String certNickname = (String) handlerContext.getInputValue("CertNickname");
String type = (String) handlerContext.getInputValue("Type");
boolean isEdit = ((Boolean) handlerContext.getInputValue("Edit")).booleanValue();
if (type.equals("http")) {
if (isEdit) {
// remove the ssl element from the listener.
httpListener = SipUtil.getHttpListener(httpService, listenerName);
ssl = (ObjectName) SipUtil.getChildByFunction(httpListener, "getSsl");
if (ssl != null) {
//Remove the SSL element so that it can be recreated below
JMXUtil.invoke(httpListener, "removeSsl", null, null);
ssl = null;
}
} else {
// New Listener. Need to create the listener and then set the SSL props
Map props = (Map) handlerContext.getFacesContext().getExternalContext().getSessionMap().get("httpProps");
AttributeList list = new AttributeList();
httpListener = SipUtil.getHttpListener(httpService, listenerName);
HashMap attributeMap = new HashMap();
attributeMap.put("type", props.get("type"));
SipUtil.setAttributeValues(httpListener, attributeMap);
}
if ((certNickname != null) && (!certNickname.equals(""))) {
HashMap sslProps = new HashMap();
if (ssl == null) {
//SSL Element for this listener does not exist create one
Attribute attribute = new Attribute("cert-nickname",
certNickname);
AttributeList attrList = new AttributeList(1);
attrList.add(attribute);
ssl = (ObjectName) JMXUtil.invoke(httpListener, "createSsl",
new Object[]{attrList},
new String[]{attrList.getClass().getName()});
}
boolean clientAuthEnabled = ((Boolean) handlerContext.getInputValue(
"ClientAuth")).booleanValue();
boolean ssl3Prop = ((Boolean) handlerContext.getInputValue(
"SSL3Prop")).booleanValue();
boolean ssl2Prop = ((Boolean) handlerContext.getInputValue(
"SSL2Prop")).booleanValue();
boolean tlsProp = ((Boolean) handlerContext.getInputValue(
"TLSProp")).booleanValue();
sslProps.put("cert-nickname", certNickname);
sslProps.put("client-auth-enabled", clientAuthEnabled);
sslProps.put("ssl2-enabled", ssl2Prop);
sslProps.put("ssl3-enabled", ssl3Prop);
sslProps.put("tls-enabled", tlsProp);
if (ssl3Prop || tlsProp) {
SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
String[] supportedCiphers = factory.getDefaultCipherSuites();
Vector ciphersVector = SipUtil.getCiphersVector(supportedCiphers);
String[] selectedCiphers = SipUtil.getSelectedCiphersList((String) JMXUtil.getAttribute(
ssl, "ssl3-tls-ciphers"));
String[] selectedCommon = (String[]) handlerContext.getInputValue(
"SelectedCommon");
String[] selectedEph = (String[]) handlerContext.getInputValue(
"SelectedEph");
String[] selectedOther = (String[]) handlerContext.getInputValue(
"SelectedOther");
String[] selectedEcc = (String[]) handlerContext.getInputValue(
"SelectedEcc");
//TODO SSL Ciphers settings has issues. Has errors and does not save
// properly when selections are removed
String ciphers = SipUtil.processSelectedCiphers(selectedCommon, "");
ciphers = SipUtil.processSelectedCiphers(selectedEph, ciphers);
ciphers = SipUtil.processSelectedCiphers(selectedOther, ciphers);
ciphers = SipUtil.processSelectedCiphers(selectedEcc, ciphers);
sslProps.put("ssl3-tls-ciphers", ciphers);
}
SipUtil.setAttributeValues(ssl, sslProps);
}
}
} catch (Exception ex) {
GuiUtil.handleException(handlerContext, ex);
}
}
}