/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) Ericsson AB, 2004-2008. 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.mbeans.extensions;
import com.sun.enterprise.admin.common.exception.DeploymentException;
import com.sun.enterprise.admin.common.exception.ServerInstanceException;
import java.util.Enumeration;
import java.util.ArrayList;
import java.util.Properties;
import java.io.File;
import javax.management.*;
import com.sun.enterprise.admin.config.MBeanConfigInstanceNotFoundException;
import com.sun.enterprise.admin.config.MBeanConfigException;
import com.sun.enterprise.admin.config.ConfigMBeanHelper;
import com.sun.enterprise.admin.mbeans.ConfigsMBean;
import com.sun.enterprise.admin.target.Target;
import com.sun.enterprise.admin.target.ConfigTarget;
import com.sun.enterprise.admin.servermgmt.RepositoryConfig;
import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout;
import com.sun.enterprise.config.serverbeans.ConfigAPIHelper;
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Configs;
import com.sun.enterprise.config.serverbeans.SecurityService;
import com.sun.enterprise.config.serverbeans.IdentityAssertionTrust;
import com.sun.enterprise.config.serverbeans.TrustHandler;
import com.sun.enterprise.config.serverbeans.TrustedEntity;
import com.sun.enterprise.config.serverbeans.ElementProperty;
import com.sun.enterprise.config.serverbeans.ServerHelper;
import com.sun.enterprise.config.serverbeans.JavaConfig;
import com.sun.enterprise.config.serverbeans.JmsService;
import com.sun.enterprise.config.serverbeans.JmsHost;
import com.sun.enterprise.config.serverbeans.JmxConnector;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Clusters;
import com.sun.enterprise.config.serverbeans.Cluster;
import com.sun.enterprise.config.serverbeans.ResourceRef;
import com.sun.enterprise.config.serverbeans.ApplicationRef;
import com.sun.enterprise.config.serverbeans.ConvergedLbConfigs;
import com.sun.enterprise.config.serverbeans.ConvergedLbConfig;
import com.sun.enterprise.config.serverbeans.ConvergedLbPolicy;
import com.sun.enterprise.config.serverbeans.ConvergedLbClusterRef;
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.backend.DeploymentUtils;
import com.sun.enterprise.instance.AppsManager;
import com.sun.enterprise.instance.InstanceFactory;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.enterprise.admin.common.MBeanServerFactory;
import javax.management.MBeanServer;
import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.admin.util.IAdminConstants;
import com.sun.enterprise.config.ConfigException;
import com.sun.enterprise.config.ConfigContext;
import com.sun.enterprise.config.ConfigFactory;
import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
import com.sun.enterprise.jms.IASJmsUtil;
public class SipConfigMBean extends ConfigsMBean {
private static final StringManager _strMgr = StringManager.getManager(SipConfigMBean.class);
private static final String DEFAULT_TRUST_HANDLER = "org.jvnet.glassfish.comms.security.auth.impl.TrustHandlerImpl";
private static final String DEFAULT_CONFIG = "default-config";
private static final String DEFAULT_CLUSTER_CONFIG = "default-cluster-config";
private static final String DEFAULT_CLUSTER = "default-cluster";
protected String mInstanceName = null;
public SipConfigMBean() {
super();
}
public ObjectName createSipListener(AttributeList attrList,
Properties props, String targetName) throws MBeanException {
final Target target = getTarget(targetName);
// check1ToN(target);
ObjectName sipService = getSipServiceMBean(target);
ObjectName mbean = (ObjectName) invoke1(sipService,
"createSipListener", attrList, AttributeList.class.getName());
setProperties(mbean, props);
return mbean;
}
public boolean deleteSipListener(String listenerId, String targetName)
throws MBeanException {
final Target target = getTarget(targetName);
// check1ToN(target);
final ObjectName sipService = getSipServiceMBean(target);
invoke1(sipService, "removeSipListenerById", listenerId,
String.class.getName());
return true;
}
public ObjectName[] listSipListeners(String targetName)
throws MBeanException {
final Target target = getListTarget(targetName);
ObjectName sipService = getSipServiceMBean(target);
ObjectName[] ret = (ObjectName[]) invoke0(sipService, "getSipListener");
return ret;
}
public ObjectName getSipService(String targetName)
throws MBeanException {
return getChild("sip-service", null, targetName);
}
public ObjectName getSipListener(String listenerName, String targetName)
throws MBeanException {
return getChild("sip-listener", new String[] { listenerName },
targetName);
}
/** The function is used to get the ssl element for the specified listenerName. If the ssl element
* does not exist then an MBeanConfigInstanceNotFoundException is thrown.
*/
public ObjectName getSSL(String listenerName, String targetName)
throws MBeanException {
ObjectName sipListener = getSipListener(listenerName, targetName);
try {
return (ObjectName) invoke0(sipListener, "getSsl");
} catch (MBeanException e) {
if ((e.getTargetException() != null) &&
(e.getTargetException().getCause() instanceof MBeanConfigInstanceNotFoundException)) {
return null;
}
throw e;
}
}
protected ObjectName getSipServiceMBean(Target target)
throws MBeanException {
final ObjectName configMBean = getConfigMBean(target);
ObjectName ret = (ObjectName) invoke0(configMBean, "getSipService");
return ret;
}
/**
* Creates the identity-assertion-trust element under security-service
* Trust config can contain either trust-handler or trusted-entity, not both
* If user doesn't specify any options, then a trust config with a default
* trust handler implementation class will be created.
*/
public ObjectName createIdentityAssertionTrust( AttributeList attrList,
AttributeList entityList,
Properties props,
String targetName)
throws Exception
{
final Target target = getTarget(targetName);
final ConfigTarget configTarget = target.getConfigTarget();
SecurityService securityService = getSecurityServiceConfigBean(configTarget.getName());
return createIdentityAssertionTrust(attrList, entityList, props, configTarget.getName(), securityService);
}
public ObjectName createIdentityAssertionTrust( AttributeList attrList,
AttributeList entityList,
Properties props,
String configName,
SecurityService securityService)
throws Exception
{
String cName = null;
String ipAdd = null;
String hostName = null;
String principal = null;
String trustedAs = null;
String trustId = null;
String entityId = null;
String isDefault = "false";
// get all the values
for (int i = 0; i <attrList.size(); i++) {
Attribute attr = (Attribute)attrList.get(i);
if (isAttrNameMatch(attr, "class-name"))
cName = (String)attr.getValue();
else if (isAttrNameMatch(attr, "id"))
trustId = (String)attr.getValue();
else if (isAttrNameMatch(attr, "is-default"))
isDefault = (String)attr.getValue();
}
// get all the trusted entity info
for (int i = 0; i < entityList.size(); i++) {
Attribute attr1 = (Attribute)entityList.get(i);
if (isAttrNameMatch(attr1, "id"))
entityId = (String)attr1.getValue();
else if (isAttrNameMatch(attr1, "trusted-as"))
trustedAs = (String)attr1.getValue();
else if (isAttrNameMatch(attr1, "ip-address"))
ipAdd = (String)attr1.getValue();
else if (isAttrNameMatch(attr1, "host-name"))
hostName = (String)attr1.getValue();
else if (isAttrNameMatch(attr1, "principal"))
principal = (String)attr1.getValue();
}
// can have either trust handler or trusted entity not both
if (cName != null && (ipAdd != null || hostName != null || principal != null)) {
String msg = _strMgr.getString("EitherTrustHandlerOrTrustedEntity");
throw new MBeanConfigException(msg);
}
if (cName == null && (ipAdd == null && (hostName != null || principal != null || trustedAs != null))) {
String msg = _strMgr.getString("IpAddMustforTrustedEntity");
throw new MBeanConfigException(msg);
}
if (entityId != null && ipAdd == null) {
String msg = _strMgr.getString("IpAddMustforTrustedEntity");
throw new MBeanConfigException(msg);
}
// identity assertion trust
IdentityAssertionTrust trustConfig = securityService.getIdentityAssertionTrustById(trustId);
if (trustConfig != null)
{
String msg = _strMgr.getString("IdentityTrustAlreadyExists", trustId);
throw new MBeanConfigException(msg);
}
// we have to create it
trustConfig = new IdentityAssertionTrust();
if (trustId == null)
trustId = generateTrustId(securityService);
trustConfig.setId(trustId);
trustConfig.setIsDefault(Boolean.parseBoolean(isDefault));
// create the trust handler
if ( cName != null) {
TrustHandler tHandler = new TrustHandler();
tHandler.setClassName(cName);
securityService.addIdentityAssertionTrust(trustConfig);
if (props != null) {
tHandler.setElementProperty(convertPropertiesToElementProperties(props));
}
trustConfig.setTrustHandler(tHandler);
// return trustId;
return getMBeanRegistry().getMbeanObjectName("trust-handler",
new String[]{getDomainName(), configName, trustId});
}
// ip address is must for trusted entity config
if ( ipAdd != null) {
TrustedEntity tEntity = new TrustedEntity();
if (entityId == null)
entityId = "entityid-0";
tEntity.setId(entityId);
if (trustedAs != null)
tEntity.setTrustedAs(trustedAs);
tEntity.setIpAddress(ipAdd);
tEntity.setPrincipal(principal);
tEntity.setHostName(hostName);
trustConfig.addTrustedEntity(tEntity);
securityService.addIdentityAssertionTrust(trustConfig);
// return trustId;
return getMBeanRegistry().getMbeanObjectName("trusted-entity",
new String[]{getDomainName(), configName, trustId, entityId});
}
TrustHandler tHandler = new TrustHandler();
// use the default trust handler implementation
tHandler.setClassName(DEFAULT_TRUST_HANDLER);
trustConfig.setTrustHandler(tHandler);
securityService.addIdentityAssertionTrust(trustConfig);
// return trustId;
return getMBeanRegistry().getMbeanObjectName("trust-handler",
new String[]{getDomainName(), configName, trustId});
}
private static boolean isAttrNameMatch(Attribute attr, String name)
{
// for now we supporting both "dashed" and "underscored" names
return attr.getName().replace('_','-').equals(name.replace('_','-'));
}
private ElementProperty[] convertPropertiesToElementProperties(Properties props)
{
ArrayList list = new ArrayList();
Enumeration keys = props.keys();
while (keys.hasMoreElements())
{
final String key = (String)keys.nextElement();
ElementProperty property = new ElementProperty();
property.setName(key);
property.setValue((String)props.get(key));
list.add(property);
}
return (ElementProperty[])list.toArray(new ElementProperty[list.size()]);
}
/**
* Method to generate trust ids automatically for identity-assertion-trust
*/
public String generateTrustId(SecurityService ss) {
String id = null;
IdentityAssertionTrust trustConfig = null;
for (int i=0; ; i++) {
id = "trustid-" + i;
trustConfig = ss.getIdentityAssertionTrustById(id);
if (trustConfig == null)
break;
}
return id;
}
/**
* Method to generate entity ids automatically for trusted-entity
*/
public String generateEntityId(IdentityAssertionTrust iat) {
String id = null;
TrustedEntity tEntity = null;
for (int i=0; ; i++) {
id = "entityid-" + i;
tEntity = iat.getTrustedEntityById(id);
if (tEntity == null)
break;
}
return id;
}
/**
* Deletes the identity-assertion-trust from security-service
*/
public boolean deleteIdentityAssertionTrust( String id, String targetName )
throws Exception
{
final Target target = getTarget(targetName);
// check1ToN(target);
SecurityService securityService = getSecurityServiceConfigBean(target.getConfigTarget().getName());
IdentityAssertionTrust trustConfig = securityService.getIdentityAssertionTrustById(id);
if (trustConfig == null)
{
String msg = _strMgr.getString("IdentityTrustDoesntExist", id);
throw new MBeanConfigException(msg);
}
securityService.removeIdentityAssertionTrust(trustConfig);
return true;
}
/**
* Method to return the list of trust configs.
* If trustId is specified, then we return all the trusted-entities for it.
*/
public Object[] listIdentityAssertionTrusts( String trustId, String targetName )
throws Exception
{
final Target target = getListTarget(targetName);
SecurityService securityService = getSecurityServiceConfigBean(target.getConfigTarget().getName());
// if trustId is specified, list all trusted entities for that config
if (trustId != null)
{
IdentityAssertionTrust trustConfig =
securityService.getIdentityAssertionTrustById(trustId);
if (trustConfig == null)
{
String msg = _strMgr.getString("IdentityTrustDoesntExist", trustId);
throw new MBeanConfigException(msg);
}
return getTrustedEntities(trustConfig);
}
// trustId is not specified, list all trust configs
IdentityAssertionTrust[] trustConfigs = securityService.getIdentityAssertionTrust();
return ConfigMBeanHelper.getConfigBeansObjectNames(
this.getMBeanRegistry(), this.getDomainName(), trustConfigs);
}
/**
* This will return all the trusted-entities for a given trust config.
*/
public Object[] getTrustedEntities( IdentityAssertionTrust trust )
throws Exception
{
TrustedEntity[] entities = trust.getTrustedEntity();
return ConfigMBeanHelper.getConfigBeansObjectNames(
this.getMBeanRegistry(), this.getDomainName(), entities);
}
/**
* Creates a trusted entity for a trust config
*/
public boolean createTrustedEntity( AttributeList attrList,
String trustId,
String targetName )
throws Exception
{
String id = null;
String trustedAs = null;
String ipAdd = null;
String host = null;
String principal = null;
final Target target = getTarget(targetName);
// check1ToN(target);
SecurityService securityService = getSecurityServiceConfigBean(target.getConfigTarget().getName());
for (int i = 0; i <attrList.size(); i++) {
Attribute attr = (Attribute)attrList.get(i);
if (isAttrNameMatch(attr, "id"))
id = (String)attr.getValue();
else if (isAttrNameMatch(attr, "trusted-as"))
trustedAs = (String)attr.getValue();
else if (isAttrNameMatch(attr, "ip-address"))
ipAdd = (String)attr.getValue();
else if (isAttrNameMatch(attr, "host-name"))
host = (String)attr.getValue();
else if (isAttrNameMatch(attr, "principal"))
principal = (String)attr.getValue();
}
IdentityAssertionTrust trustConfig =
securityService.getIdentityAssertionTrustById(trustId);
// invalid trustId was specified
if (trustConfig == null)
{
String msg = _strMgr.getString("IdentityTrustDoesntExist", trustId);
throw new MBeanConfigException(msg);
}
// check if a trust handler is already configured for this trust config
TrustHandler tHandler = trustConfig.getTrustHandler();
if (tHandler != null) {
String msg = _strMgr.getString("TrustHandlerAlreadyExistsForTrustConfig", trustId);
throw new MBeanConfigException(msg);
}
TrustedEntity tEntity = new TrustedEntity();
if (id == null)
id = generateEntityId(trustConfig);
tEntity.setId(id);
if (trustedAs != null)
tEntity.setTrustedAs(trustedAs);
tEntity.setIpAddress(ipAdd);
if (host != null)
tEntity.setHostName(host);
if (principal != null)
tEntity.setPrincipal(principal);
trustConfig.addTrustedEntity(tEntity);
return true;
}
/**
* Deletes the specified trusted-entity from the trust config
*/
public boolean deleteTrustedEntity( String entityId, String trustId, String targetName )
throws Exception
{
final Target target = getTarget(targetName);
// check1ToN(target);
SecurityService securityService = getSecurityServiceConfigBean(target.getConfigTarget().getName());
IdentityAssertionTrust trustConfig =
securityService.getIdentityAssertionTrustById(trustId);
// invalid trustId was specified
if (trustConfig == null)
{
String msg = _strMgr.getString("IdentityTrustDoesntExist", trustId);
throw new MBeanConfigException(msg);
}
TrustedEntity[] entities = trustConfig.getTrustedEntity();
// if its THE only trusted entity element, we might as well
// remove the trust config itself
if (entities.length==1 && entityId.equals(trustConfig.getTrustedEntity(0).getId()))
{
securityService.removeIdentityAssertionTrust(trustConfig);
return true;
}
// get the trusted entity from the trust config and remove
TrustedEntity tEntity = trustConfig.getTrustedEntityById(entityId);
if (tEntity == null)
{
String msg = _strMgr.getString("TrustedEntityDoesntExist", entityId);
throw new MBeanConfigException(msg);
}
trustConfig.removeTrustedEntity(tEntity);
return true;
}
private SecurityService getSecurityServiceConfigBean(String configName)
throws Exception
{
Config config = ConfigAPIHelper.getConfigByName(getConfigContext(), configName);
return config.getSecurityService();
}
public ObjectName createSsl(AttributeList al,
String id,
String type,
String targetName)
throws Exception
{
if (!type.equals("sip-listener"))
return super.createSsl(al, id, type, targetName);
final Target target = getTarget(targetName);
ObjectName targetON = getSipListenerMBean(target, id);
checkElementDoesnotExist(targetON, "getSsl", _strMgr.getString("SslElementExists"));
ObjectName ret = (ObjectName)invoke1(targetON, "createSsl", al,
AttributeList.class.getName());
return ret;
}
public boolean deleteSsl(String id, String type, String targetName)
throws MBeanException
{
if (!type.equals("sip-listener"))
return super.deleteSsl(id, type, targetName);
final Target target = getTarget(targetName);
final ObjectName targetON = getSipListenerMBean(target, id);
invoke0(targetON, "removeSsl");
return true;
}
private ObjectName getSipListenerMBean(Target target, String id)
throws MBeanException
{
return (ObjectName)invoke1(getSipServiceMBean(target),
"getSipListenerById", id, String.class.getName());
}
/**
* The function creates the Application descriptor for an enterprise application and returns the same.
* @param appName name of the enterprise application
* @return
* @throws com.sun.enterprise.admin.common.exception.ServerInstanceException
*/
public Application getDescrForApplication(String appName)
throws ServerInstanceException {
try {
AppsManager appsMgr = InstanceFactory.createAppsManager(getInstanceName());
return (Application) DeploymentUtils.getDescriptor(appName, appsMgr);
} catch (Exception e) {
throw new ServerInstanceException(e.getLocalizedMessage());
}
}
private String getInstanceName() throws DeploymentException {
if (mInstanceName == null) {
try {
MBeanServer mbs = MBeanServerFactory.getMBeanServer();
ObjectName serversON = new ObjectName(getDomainName() + ":type=servers,category=config");
ObjectName[] serverONArr = (ObjectName[]) mbs.invoke(serversON, "getServer", new Object[]{}, new String[]{});
mInstanceName = (String) mbs.getAttribute(serverONArr[0], "name");
} catch (Exception e) {
throw new DeploymentException("Could not obtain instanceName");
}
}
return mInstanceName;
}
public void addClusteringSupportUsingProfile(final String profile) throws ConfigException {
final ConfigContext acc = MBeanRegistryFactory.getAdminContext().getAdminConfigContext();
if (ServerHelper.isClusterAdminSupported(acc)) {
final String msg = _strMgr.getString("domain.supports.cluster");
throw new ConfigException(msg);
}
try {
final Config defaultConfig = getTemplateConfig(profile, DEFAULT_CONFIG);
final Config defaultClusterConfig = getTemplateConfig(profile, DEFAULT_CLUSTER_CONFIG);
addConfig(acc, defaultConfig, DEFAULT_CONFIG);
addConfig(acc, defaultClusterConfig, DEFAULT_CLUSTER_CONFIG);
addClusterSupportElements(acc);
configureAdminServer(acc);
addDefaultCluster(acc);
addRemainingCLBElements(acc);
createMissingFolders(acc, defaultConfig.getName());
createMissingFolders(acc, defaultClusterConfig.getName());
} catch(final Exception e) {
throw new ConfigException(e);
}
}
private Config getTemplateConfig(final String profile, final String tcn) throws IllegalArgumentException, ConfigException {
final RepositoryConfig myRepos = new RepositoryConfig(); //all system properties are taken care of.
final PEFileLayout layout = new PEFileLayout(myRepos);
final File profileDomainXmlTemplate = new File(layout.getProfileFolder(profile), "sample-domain.xml");
if (! profileDomainXmlTemplate.exists()) {
final String msg = _strMgr.getString("template.domain.xml.not.found",
profileDomainXmlTemplate.getAbsolutePath(), profile);
throw new IllegalArgumentException(msg);
}
final ConfigContext tcc = ConfigFactory.createConfigContext(profileDomainXmlTemplate.getAbsolutePath(), true);
//this created a config context from which we can just borrow the config element.
if (! exists(ConfigAPIHelper.getConfigsInDomain(tcc), tcn)) {
final String msg = _strMgr.getString("template.config.not.found", tcn, profileDomainXmlTemplate.getAbsolutePath());
throw new IllegalArgumentException(msg);
}
final Config tc = ConfigAPIHelper.getConfigByName(tcc, tcn); // this has to exist
return ( (Config)tc.clone() ); //cloning is required
}
private static boolean exists(final Config[] configs, final String configNamed) {
boolean exists = false;
for (final Config c : configs) {
if (c.getName().equals(configNamed)) {
exists = true;
break;
}
}
return ( exists );
}
private static void addConfig(final ConfigContext acc, final Config dc, final String dcName) throws ConfigException {
final Configs configs = ConfigAPIHelper.getDomainConfigBean(acc).getConfigs();
dc.setName(dcName);
configs.addConfig(dc);
configureDefaultJmsHost(dc);
addClientHostNameProperty2SystemJmxConnector(dc);
}
private static void addClusterSupportElements(final ConfigContext acc) throws ConfigException {
final Domain domain = ConfigAPIHelper.getDomainConfigBean(acc);
domain.setClusters(domain.newClusters());
domain.setNodeAgents(domain.newNodeAgents());
domain.setLoadBalancers(domain.newLoadBalancers());
domain.setLbConfigs(domain.newLbConfigs());
}
private static void configureAdminServer(final ConfigContext acc) throws ConfigException {
final Config dasc = ServerHelper.getConfigForServer(acc, SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
final JavaConfig jc = dasc.getJavaConfig();
jc.removeJvmOptions("-Dcom.sun.appserv.pluggable.features=org.jvnet.glassfish.comms.server.pluggable.extensions.sip.SipPEPluggableFeatureImpl");
jc.addJvmOptions("-Dcom.sun.appserv.pluggable.features=org.jvnet.glassfish.comms.server.pluggable.extensions.sip.SipEEPluggableFeatureImpl");
addClientHostNameProperty2SystemJmxConnector(dasc);
}
private static void configureDefaultJmsHost(final Config tc) {
//this configures the default_JMS_Host's attributes
//default JMS Host is pointed to by the default-jms-host attribute of jms-service.
final JmsService js = tc.getJmsService();
final String jmshn = js.getDefaultJmsHost();
final JmsHost jmsh = js.getJmsHostByName(jmshn);
jmsh.setAdminUserName(IASJmsUtil.DEFAULT_USER);
jmsh.setAdminPassword(IASJmsUtil.DEFAULT_PASSWORD);
jmsh.setHost(System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY));
//don't set the port as it is "tokenized" appropriately
}
private static void addClientHostNameProperty2SystemJmxConnector(final Config someConfig) throws ConfigException {
final com.sun.enterprise.config.serverbeans.AdminService as = someConfig.getAdminService();
final JmxConnector jc = as.getJmxConnectorByName(IAdminConstants.SYSTEM_CONNECTOR_NAME);
final String hostValue = System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY);
final String hostName = IAdminConstants.HOST_PROPERTY_NAME;
ElementProperty ep = jc.getElementPropertyByName(hostName);
if (ep == null) {
ep = new ElementProperty();
ep.setName(hostName);
ep.setValue(hostValue);
jc.addElementProperty(ep);
} else {
ep.setValue(hostValue);
}
}
private static void addDefaultCluster(final ConfigContext acc) throws ConfigException {
final Domain domain = ConfigAPIHelper.getDomainConfigBean(acc);
Clusters clusters = domain.getClusters();
Cluster cl = new Cluster();
cl.setName(DEFAULT_CLUSTER);
cl.setConfigRef(DEFAULT_CLUSTER_CONFIG);
cl.setHeartbeatEnabled(true);
cl.setHeartbeatPort(Integer.toString((new Long(Math.round(Math.random()*45556))).intValue()));
cl.setHeartbeatAddress("228.8.7.9");
ResourceRef rref = new ResourceRef();
rref.setEnabled(true);
rref.setRef("jdbc/__CallFlowPool");
ApplicationRef aref = new ApplicationRef();
aref.setEnabled(true);
aref.setDisableTimeoutInMinutes("30");
aref.setLbEnabled(false);
aref.setRef("SipContainerLifecycle");
cl.addResourceRef(rref);
cl.addApplicationRef(aref);
clusters.addCluster(cl);
}
private static void addRemainingCLBElements(final ConfigContext acc) throws ConfigException {
final Domain domain = ConfigAPIHelper.getDomainConfigBean(acc);
ConvergedLbConfigs clbConfigs = new ConvergedLbConfigs();
domain.setConvergedLbConfigs(clbConfigs);
ConvergedLbConfig clbConfig = new ConvergedLbConfig();
clbConfig.setName("converged-lb-config-1");
ConvergedLbPolicy clbPolicy = new ConvergedLbPolicy();
clbPolicy.setHttp("round-robin");
clbPolicy.setSip("from-tag,to-tag,call-id");
ConvergedLbClusterRef clbRef = new ConvergedLbClusterRef();
clbRef.setRef(DEFAULT_CLUSTER);
clbRef.setSelfLoadbalance(true);
clbConfig.setConvergedLbPolicy(clbPolicy);
clbConfig.addConvergedLbClusterRef(clbRef);
clbConfigs.addConvergedLbConfig(clbConfig);
}
private static void createMissingFolders(ConfigContext cc, String folder) {
//this code is supposed to be a copy of EEFileLayout.createConfigurationDirectories
//copying here (bad practice) only because there is not enough time to refactor
//See 6694, 3980 on GlassFish issue tracker
//doing this with a heavy heart - km@dev.java.net 04 Nov 2008
File domainXml = new File(cc.getUrl());
File cfg = domainXml.getParentFile();
File def = new File (cfg, folder);
if (!def.exists()) {
def.mkdir();
new File(def, "docroot").mkdir();
new File(def, "lib").mkdir();
new File(new File(def, "lib"), "ext").mkdir();
}
}
}