[wsas-java-dev] svn commit r3441 - in trunk/wsas/java/modules:
core/src/org/wso2/wsas servlet-edition/conf
standalone-edition/conf standalone-edition/src/org/wso2/wsas
standalone-edition/test-resources
svn at wso2.org
svn at wso2.org
Fri Jun 1 01:37:33 PDT 2007
Author: saminda
Date: Fri Jun 1 01:37:04 2007
New Revision: 3441
Added:
trunk/wsas/java/modules/core/src/org/wso2/wsas/DefaultServerInitializer.java
trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerInitializer.java
Modified:
trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java
trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java
trunk/wsas/java/modules/servlet-edition/conf/server.xml
trunk/wsas/java/modules/standalone-edition/conf/server.xml
trunk/wsas/java/modules/standalone-edition/src/org/wso2/wsas/Main.java
trunk/wsas/java/modules/standalone-edition/test-resources/server.xml
Log:
Added
<!--
Server intializing code. DefaultServerInitializer will intialize the WSAS specific
Configurations. It should be the first. All other intializers should come after that.
Use <Initialize/> elements to add new intializers.
-->
<ServerInitializer>
<Initialize>org.wso2.wsas.DefaultServerInitializer</Initialize>
</ServerInitializer>
One could add the intializers after default intializer. Removing the org.wso2.wsas.DefaultServerInitializer is at
users risk.
Added: trunk/wsas/java/modules/core/src/org/wso2/wsas/DefaultServerInitializer.java
==============================================================================
--- (empty file)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/DefaultServerInitializer.java Fri Jun 1 01:37:04 2007
@@ -0,0 +1,461 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsas;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.AxisModule;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.collections.bidimap.TreeBidiMap;
+import org.apache.commons.collections.BidiMap;
+import org.apache.log4j.Logger;
+import org.apache.axiom.om.OMElement;
+import org.wso2.utils.ServerConfiguration;
+import org.wso2.utils.ServerException;
+import org.wso2.utils.security.CryptoUtil;
+import org.wso2.utils.security.CryptoException;
+import org.wso2.wsas.persistence.PersistenceManager;
+import org.wso2.wsas.persistence.exception.UserRoleAlreadyExistsException;
+import org.wso2.wsas.persistence.exception.ServiceUserAlreadyExistsException;
+import org.wso2.wsas.persistence.exception.KeyStoreAlreadyExistsException;
+import org.wso2.wsas.persistence.exception.SecurityScenarioAlreadyExistsException;
+import org.wso2.wsas.persistence.dataobject.ServiceUserRoleDO;
+import org.wso2.wsas.persistence.dataobject.ServiceUserDO;
+import org.wso2.wsas.persistence.dataobject.ModuleDO;
+import org.wso2.wsas.persistence.dataobject.SecurityScenarioDO;
+import org.wso2.wsas.util.*;
+import org.wso2.adminui.UIProcessor;
+import org.wso2.adminui.UIProcessingException;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Timer;
+import java.io.File;
+/*
+ *
+ */
+
+public class DefaultServerInitializer implements ServerInitializer {
+
+ private ConfigurationContext configurationContext;
+ private ServerConfiguration serverConfig;
+ private PersistenceManager pm;
+
+ private String wso2wsasHome;
+
+ private static Log log = LogFactory.getLog(DefaultServerInitializer.class);
+ private static Logger rootLogger = Logger.getRootLogger();
+
+ private boolean isHouseKeepingTaskCreated;
+ private Timer houseKeepingTimer;
+
+ private ServerManager serverManager;
+
+ public DefaultServerInitializer() {
+ this.serverConfig = ServerConfiguration.getInstance();
+ this.serverManager = ServerManager.getInstance();
+ this.pm = new PersistenceManager();
+ }
+
+ public void setConfigurationContext(ConfigurationContext configurationContext) {
+ this.configurationContext = configurationContext;
+ }
+
+ public void init() throws AxisFault, ServerException {
+
+ wso2wsasHome = System.getProperty(ServerConstants.WSO2WSAS_HOME);
+
+ initHouseKeeping();
+
+ initLoggingConfiguration();
+
+ // enabled clustering
+ enableClustering();
+
+ // Create the dynamic pages and save it in the ConfigContext
+ generatePages();
+
+ // Enabling http binding generation
+ Parameter enableHttp = new Parameter("enableHTTP", "true");
+ AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
+ axisConfig.addParameter(enableHttp);
+
+
+ configurationContext.setProperty(ServerConstants.Logging.MEMORY_APPENDER,
+ rootLogger.getAppender(ServerConstants.
+ Logging.WSO2WSAS_MEMORY_APPENDER));
+
+ createDefaultServiceUserRoles();
+
+ createDefaultAdminAccount();
+
+ handleGlobalModuleEngagements(axisConfig);
+
+ initServiceGroupContextTimeout();
+
+ registerHouseKeepingTask();
+
+ persistSecurityKeyStore();
+
+ persistSecurityScenarios();
+
+ initKeystoresDir();
+
+ }
+
+ public void shutdown() throws ServerException {
+ stopHouseKeeping();
+ }
+
+ /**
+ * Reads the data base and check whether log setting already there.
+ * if so update the logger settings with the database settings
+ * else update the data to data base
+ * here we assume user never changes the original log4j.properties file.
+ */
+ private void initLoggingConfiguration() {
+
+ // check whether logging configurations are already persisted
+ String isLoaded = pm.getConfigurationProperty(ServerConstants.Logging.SYSTEM_LOG_IS_LOADED);
+ if (Boolean.valueOf(isLoaded).booleanValue()) {
+ LoggingUtil.loadCustomConfiguration();
+ } else {
+ // parse the logging file and get the information
+ LoggingUtil.loadDefaultConfiguration();
+ }
+ }
+
+ private void enableClustering() throws AxisFault {
+ ClusteringUtil.enableClustering(configurationContext);
+ }
+
+ private void generatePages() {
+ Map files = new Hashtable();
+ try {
+ UIProcessor.createPages(serverManager.adminResourceBase, "ui-extensions-config.xml",
+ files);
+ configurationContext.setProperty(ServerConstants.GENERATED_PAGES, files);
+ } catch (UIProcessingException e) {
+ String msg = "Static page generation failed";
+ log.warn(msg + ": " + e);
+ log.debug(msg, e);
+ }
+ }
+
+ private void createDefaultServiceUserRoles() throws ServerException {
+ OMElement document = serverConfig.getDocumentElement();
+
+ for (Iterator surIte =
+ document.getChildrenWithName(
+ new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "ServiceUserRoles"));
+ surIte.hasNext();) {
+
+ OMElement serviceUserRoles = (OMElement) surIte.next();
+
+ for (Iterator roleIte =
+ serviceUserRoles.getChildrenWithName(
+ new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Role"));
+ roleIte.hasNext();) {
+ OMElement role = (OMElement) roleIte.next();
+ ServiceUserRoleDO serviceUserRole = null;
+ for (Iterator nameIter =
+ role.getChildrenWithName(
+ new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Name"));
+ nameIter.hasNext();) {
+ OMElement name = (OMElement) nameIter.next();
+ serviceUserRole = pm.getServiceUserRole(name.getText());
+ if (serviceUserRole == null) {
+ serviceUserRole = new ServiceUserRoleDO();
+ serviceUserRole.setRole(name.getText());
+ }
+ }
+ for (Iterator nameIter =
+ role.getChildrenWithName(
+ new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Description"));
+ nameIter.hasNext();) {
+ OMElement description = (OMElement) nameIter.next();
+ if (serviceUserRole != null) {
+ serviceUserRole.setDescription(description.getText());
+ } else {
+ throw new ServerException("Description without a Role name is invalid");
+ }
+ }
+ try {
+ pm.addOrUpdateUserRole(serviceUserRole);
+ } catch (UserRoleAlreadyExistsException ignored) {
+ // this exception cannot occur since we've validated it above
+ }
+ }
+ }
+ }
+
+ private void createDefaultAdminAccount() throws ServerException {
+ String adminUsername = "admin";
+ ServiceUserDO admin = pm.getUser(adminUsername);
+ ServerConfiguration config = ServerConfiguration.getInstance();
+ CryptoUtil cryptoUtil =
+ new CryptoUtil(new File(
+ config.getFirstProperty("Security.KeyStore.Location")).getAbsolutePath(),
+ config.getFirstProperty("Security.KeyStore.Password"),
+ config.getFirstProperty("Security.KeyStore.KeyAlias"),
+ config.getFirstProperty("Security.KeyStore.KeyPassword"),
+ config.getFirstProperty("Security.KeyStore.Type"));
+ if (admin == null) {
+
+ // There is no default admin user. WSAS is starting up for the first time
+ // Check whether the default Admin user's password has been changed
+ String adminPassword = getDefaultAdminPassword();
+ String adminDescription = "Default Adminstrator";
+ try {
+ admin = new ServiceUserDO();
+ admin.setUsername(adminUsername);
+ admin.setPassword(cryptoUtil.encryptAndBase64Encode(adminPassword.getBytes()));
+ admin.setDescription(adminDescription);
+ ServiceUserRoleDO role = pm.getUserRole(ServerConstants.ADMIN_ROLE);
+ pm.addUser(admin);
+ pm.addRole(admin.getUsername(), role);
+ } catch (CryptoException e) {
+ String msg = "Cannot encrypt default admin password";
+ log.error(msg, e);
+ throw new ServerException(msg, e);
+ } catch (ServiceUserAlreadyExistsException ignored) {
+ // this exception cannot occur since we've validated it above
+ }
+ } else {
+ try {
+ if (new String(cryptoUtil.base64DecodeAndDecrypt(admin.getPassword())).
+ equals("admin")) {
+ String password = getDefaultAdminPassword();
+ admin.setPassword(cryptoUtil.encryptAndBase64Encode(password.getBytes()));
+ pm.updateUser(admin);
+ }
+ } catch (Exception e) {
+ throw new ServerException(e);
+ }
+ }
+ }
+
+ private void handleGlobalModuleEngagements(AxisConfiguration axisConfig)
+ throws ServerException {
+ try {
+ ModuleDO[] moduleDOs = pm.getAllModules();
+ for (int i = 0; i < moduleDOs.length; i++) {
+ ModuleDO moduleDO = moduleDOs[i];
+ if (moduleDO.getIsGloballyEngaged()) {
+ String moduleId = moduleDO.getModuleIdentifierDO().getName();
+ if (!axisConfig.isEngaged(moduleId)) {
+ axisConfig.engageModule(moduleId);
+ }
+
+ // We should not engage the throttle module to the wso2wsas-administration service group
+ if (moduleId.equals("wso2throttle")) {
+ axisConfig.getServiceGroup(ServerConstants.ADMIN_SERVICE_GROUP).
+ disengageModule(axisConfig.getModule(moduleId));
+ }
+ }
+ }
+ } catch (Exception e) {
+ String msg = Messages.getMessage("CannotConfigureAxis2");
+ log.error(msg);
+ throw new ServerException(msg, e);
+ }
+ }
+
+ private void initServiceGroupContextTimeout() {
+ String serviceGroupContextIdleTimeout =
+ serverConfig.getFirstProperty("Axis2Config.ServiceGroupContextIdleTime");
+
+ if (serviceGroupContextIdleTimeout != null) {
+ configurationContext.
+ setProperty(org.apache.axis2.Constants.Configuration.
+ CONFIG_CONTEXT_TIMOUT_INTERVAL,
+ new Integer(serviceGroupContextIdleTimeout));
+ }
+ }
+
+ private void registerHouseKeepingTask() {
+ if (!isHouseKeepingTaskCreated) {
+ if (Boolean.valueOf(serverConfig.
+ getFirstProperty("HouseKeeping.AutoStart")).booleanValue()) {
+ houseKeepingTimer = new Timer();
+ long houseKeepingInterval =
+ Long.parseLong(serverConfig.
+ getFirstProperty("HouseKeeping.Interval")) * 60 * 1000;
+ Object property =
+ configurationContext.getProperty(ServerConstants.FILE_RESOURCE_MAP);
+ if (property == null) {
+ property = new TreeBidiMap();
+ configurationContext.setProperty(ServerConstants.FILE_RESOURCE_MAP, property);
+ }
+ houseKeepingTimer
+ .scheduleAtFixedRate(new HouseKeepingTask(serverManager.serverWorkDir,
+ (BidiMap) property),
+ houseKeepingInterval,
+ houseKeepingInterval);
+ isHouseKeepingTaskCreated = true;
+ }
+ }
+ }
+
+
+ private void persistSecurityKeyStore() throws ServerException {
+
+ String ksLocation = serverConfig.getFirstProperty("Security.KeyStore.Location");
+ if (!KeyStoreUtil.keyStoreExists(ksLocation)) {
+ try {
+ KeyStoreUtil.persistKeyStore(new File(ksLocation).getAbsolutePath(),
+ serverConfig.
+ getFirstProperty("Security.KeyStore.Password"),
+ serverConfig.
+ getFirstProperty("Security.KeyStore.Type"),
+ "wso2wsas",
+ serverConfig.
+ getFirstProperty(
+ "Security.KeyStore.KeyPassword"),
+ null,
+ true);
+ } catch (KeyStoreAlreadyExistsException e) {
+ throw new ServerException(e);
+ }
+ }
+ }
+
+ private void persistSecurityScenarios() throws ServerException {
+ String scenarioConfigXml = wso2wsasHome + File.separator + "conf" +
+ File.separator + "rampart" +
+ File.separator + "scenario-config.xml";
+ if (!new File(scenarioConfigXml).exists()) {
+ log.info("Security scenario configuration file does not exist");
+ return;
+ }
+ XmlConfiguration xmlConfiguration =
+ new XmlConfiguration(scenarioConfigXml,
+ "http://www.wso2.org/products/wsas/security");
+ OMElement[] secenarioEle = xmlConfiguration.getElements("//ns:Scenario");
+ for (int i = 0; i < secenarioEle.length; i++) {
+ SecurityScenarioDO scenario = new SecurityScenarioDO();
+ OMElement omElement = secenarioEle[i];
+ String scenarioId =
+ omElement.getAttribute(ServerConstants.Security.ID_QN).getAttributeValue();
+ if (pm.getSecurityScenario(scenarioId) != null) {
+ continue;
+ }
+ scenario.setScenarioId(scenarioId);
+ scenario.setSummary(omElement.
+ getFirstChildWithName(ServerConstants.Security.SUMMARY_QN).getText());
+ scenario.setDescription(omElement
+ .getFirstChildWithName(ServerConstants.Security.DESCRIPTION_QN).getText());
+ scenario.setCategory(omElement
+ .getFirstChildWithName(ServerConstants.Security.CATEGORY_QN).getText());
+
+ for (Iterator modules = omElement
+ .getFirstChildWithName(ServerConstants.Security.MODULES_QN).getChildElements();
+ modules.hasNext();) {
+ String module = ((OMElement) modules.next()).getText();
+ AxisModule axisModule =
+ configurationContext.getAxisConfiguration().getModule(module);
+
+ if (axisModule != null) {
+ ModuleDO moduleDO = pm.getModule(ModuleIdUtil.getModuleId(axisModule),
+ ModuleIdUtil.getModuleVersion(axisModule));
+ scenario.addModule(moduleDO);
+ }
+ }
+ try {
+ pm.addSecurityScenario(scenario);
+ } catch (SecurityScenarioAlreadyExistsException ignored) {
+ // will not be able to add an already existing Security Scenario
+ }
+ }
+ }
+
+
+ private void initKeystoresDir() {
+ ServerConfiguration serverConfig = ServerConfiguration.getInstance();
+ String ksDirName = serverConfig.getFirstProperty("Security.KeyStoresDir");
+ serverConfig.setConfigurationProperty("Security.KeyStoresDir",
+ new File(ksDirName).getAbsolutePath());
+ }
+
+
+ private void initHouseKeeping() {
+ if (houseKeepingTimer != null) {
+ houseKeepingTimer.cancel();
+ houseKeepingTimer = null;
+ isHouseKeepingTaskCreated = false;
+ }
+ }
+
+ /**
+ * There is no default admin user. WSAS is starting up for the first time
+ * Check whether the default Admin user's password has been changed
+ *
+ * @return Default admin password
+ */
+ private String getDefaultAdminPassword() {
+ return "admin";
+
+ //TODO: We need to finalize on how we are to handle capturing of the default admin password
+ /*String adminPassword = System.getProperty(ServerConstants.WSO2WSAS_ADMIN_PASSWORD);
+ if (adminPassword != null && !adminPassword.equals("admin")) {
+ return adminPassword;
+ }
+ System.out.println(" Please enter the password of Administrator 'admin'");
+ String passwordRepeat = null;
+ do {
+ while (adminPassword == null || adminPassword.trim().length() == 0) {
+ try {
+ adminPassword = InputReader.readPassword(" New password: ");
+ if (adminPassword.equals("admin")) {
+ adminPassword = null;
+ System.err.println(" This password is not allowed." +
+ " Please enter another password.");
+ }
+ } catch (IOException e) {
+ System.err.println(" Unable to read password : " + e);
+ }
+ }
+ while (passwordRepeat == null || passwordRepeat.trim().length() == 0) {
+ try {
+ passwordRepeat = InputReader.readPassword(" Re-enter new password: ");
+ } catch (IOException e) {
+ System.err.println(" Unable to read re-entered password : " + e);
+ }
+ }
+ if (!adminPassword.equals(passwordRepeat)) {
+ System.err.println(" Password and re-entered password do not match");
+ adminPassword = null;
+ passwordRepeat = null;
+ continue;
+ }
+ System.out.println(" Password for Admin user changed.");
+ break;
+ } while (true);
+ return adminPassword;*/
+ }
+
+ public void stopHouseKeeping() {
+ initHouseKeeping();
+ }
+
+
+}
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerConstants.java Fri Jun 1 01:37:04 2007
@@ -98,6 +98,7 @@
public static final String WEB_RESOURCE_LOCATION = "web.location";
public static final String GENERATED_PAGES = "local_wso2wsas.generated.pages";
public static final String CONFIGURATION_CONTEXT = "CONFIGURATION_CONTEXT";
+ public static final String WSO2WSAS_SERVER_INITIALIZER_LIST = "local_server.intializer.list";
public static class Axis2ParameterNames {
public static final String CONTEXT_ROOT = "contextRoot";
Added: trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerInitializer.java
==============================================================================
--- (empty file)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerInitializer.java Fri Jun 1 01:37:04 2007
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.wsas;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.AxisFault;
+import org.wso2.utils.ServerException;
+/*
+ *
+ */
+
+public interface ServerInitializer {
+ /**
+ * Set the ConfigurationContext
+ * @param configurationContext
+ */
+ public void setConfigurationContext(ConfigurationContext configurationContext);
+
+ /**
+ * Initializing logic
+ */
+ public void init() throws AxisFault, ServerException ;
+
+ /**
+ * Called when server is shutting down
+ * @throws ServerException
+ */
+ public void shutdown() throws ServerException;
+}
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/ServerManager.java Fri Jun 1 01:37:04 2007
@@ -50,10 +50,7 @@
import javax.xml.namespace.QName;
import java.io.File;
import java.net.SocketException;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Timer;
+import java.util.*;
/**
* The delegate used by WSAS standalone edition & servlet edition and contains the
@@ -70,13 +67,7 @@
public String adminResourceBase;
private static Logger log = Logger.getLogger(ServerManager.class);
- private static Logger rootLogger = Logger.getRootLogger();
private ServerConfiguration serverConfig;
- private boolean isHouseKeepingTaskCreated;
-
- private PersistenceManager pm;
- private Timer houseKeepingTimer;
- private String wso2wsasHome;
private static ServerManager instance;
private ListenerManager listenerManager;
@@ -90,22 +81,11 @@
private ServerManager() {
this.serverConfig = ServerConfiguration.getInstance();
- pm = new PersistenceManager();
}
public void start() throws ServerException {
- // ------------------------------------------------------------------------------------------
-
- wso2wsasHome = System.getProperty(ServerConstants.WSO2WSAS_HOME);
-
- // ------------------------------------------------------------------------------------------
-
try {
- initHouseKeeping();
- initLoggingConfiguration();
-
//Setting the codegen configuration properties for try it! functionality
- //TODO Change this to proper one once Maven2 build is fixed.
System.setProperty("org.apache.axis2.codegen.config",
"/codegen-config.properties");
@@ -133,35 +113,11 @@
oldContext.getAxisConfiguration().getClusterManager();
configContext.getAxisConfiguration().setClusterManager(originalClusterManager);
}
-
startListenerManager();
- // Enable clustering if necessary
- enableClustering();
-
- // Create the dynamic pages and save it in the ConfigContext
- generatePages();
-
- // Enabling http binding generation
- Parameter enableHttp = new Parameter("enableHTTP", "true");
- AxisConfiguration axisConfig = configContext.getAxisConfiguration();
- axisConfig.addParameter(enableHttp);
- configContext.
- setProperty(ServerConstants.Logging.MEMORY_APPENDER,
- rootLogger.getAppender(ServerConstants.
- Logging.WSO2WSAS_MEMORY_APPENDER));
-
- createDefaultServiceUserRoles();
- createDefaultAdminAccount();
-
- handleGlobalModuleEngagements(axisConfig);
- initServiceGroupContextTimeout();
- registerHouseKeepingTask();
- persistSecurityKeyStore();
- persistSecurityScenarios();
-
NetworkUtils.init(serverConfig.getFirstProperty("HostName"));
- initKeystoresDir();
+ startServerIntializer();
+
} catch (Exception e) {
String msg = "Cannot start WSO2 WSAS";
log.fatal(msg, e);
@@ -169,328 +125,6 @@
}
}
- private void enableClustering() throws AxisFault {
- ClusteringUtil.enableClustering(configContext);
- }
-
- private void initKeystoresDir() {
- ServerConfiguration serverConfig = ServerConfiguration.getInstance();
- String ksDirName = serverConfig.getFirstProperty("Security.KeyStoresDir");
- serverConfig.setConfigurationProperty("Security.KeyStoresDir",
- new File(ksDirName).getAbsolutePath());
- }
-
- private void persistSecurityScenarios() throws ServerException {
- String scenarioConfigXml = wso2wsasHome + File.separator + "conf" +
- File.separator + "rampart" +
- File.separator + "scenario-config.xml";
- if (!new File(scenarioConfigXml).exists()) {
- log.info("Security scenario configuration file does not exist");
- return;
- }
- XmlConfiguration xmlConfiguration =
- new XmlConfiguration(scenarioConfigXml,
- "http://www.wso2.org/products/wsas/security");
- OMElement[] secenarioEle = xmlConfiguration.getElements("//ns:Scenario");
- for (int i = 0; i < secenarioEle.length; i++) {
- SecurityScenarioDO scenario = new SecurityScenarioDO();
- OMElement omElement = secenarioEle[i];
- String scenarioId =
- omElement.getAttribute(ServerConstants.Security.ID_QN).getAttributeValue();
- if (pm.getSecurityScenario(scenarioId) != null) {
- continue;
- }
- scenario.setScenarioId(scenarioId);
- scenario.setSummary(omElement.
- getFirstChildWithName(ServerConstants.Security.SUMMARY_QN).getText());
- scenario.setDescription(omElement
- .getFirstChildWithName(ServerConstants.Security.DESCRIPTION_QN).getText());
- scenario.setCategory(omElement
- .getFirstChildWithName(ServerConstants.Security.CATEGORY_QN).getText());
-
- for (Iterator modules = omElement
- .getFirstChildWithName(ServerConstants.Security.MODULES_QN).getChildElements();
- modules.hasNext();) {
- String module = ((OMElement) modules.next()).getText();
- AxisModule axisModule =
- configContext.getAxisConfiguration().getModule(module);
-
- if (axisModule != null) {
- ModuleDO moduleDO = pm.getModule(ModuleIdUtil.getModuleId(axisModule),
- ModuleIdUtil.getModuleVersion(axisModule));
- scenario.addModule(moduleDO);
- }
- }
- try {
- pm.addSecurityScenario(scenario);
- } catch (SecurityScenarioAlreadyExistsException ignored) {
- // will not be able to add an already existing Security Scenario
- }
- }
- }
-
- private void persistSecurityKeyStore() throws KeyStoreAlreadyExistsException,
- ServerException {
-
- String ksLocation = serverConfig.getFirstProperty("Security.KeyStore.Location");
- if (!KeyStoreUtil.keyStoreExists(ksLocation)) {
- KeyStoreUtil.persistKeyStore(new File(ksLocation).getAbsolutePath(),
- serverConfig.
- getFirstProperty("Security.KeyStore.Password"),
- serverConfig.
- getFirstProperty("Security.KeyStore.Type"),
- "wso2wsas",
- serverConfig.
- getFirstProperty("Security.KeyStore.KeyPassword"),
- null,
- true);
- }
- }
-
- private void generatePages() {
- Map files = new Hashtable();
- try {
- UIProcessor.createPages(adminResourceBase, "ui-extensions-config.xml", files);
- configContext.setProperty(ServerConstants.GENERATED_PAGES, files);
- } catch (UIProcessingException e) {
- String msg = "Static page generation failed";
- log.warn(msg + ": " + e);
- log.debug(msg, e);
- }
- }
-
- private void initHouseKeeping() {
- if (houseKeepingTimer != null) {
- houseKeepingTimer.cancel();
- houseKeepingTimer = null;
- isHouseKeepingTaskCreated = false;
- }
- }
-
- public void stopHouseKeeping() {
- initHouseKeeping();
- }
-
- private void initServiceGroupContextTimeout() {
- String serviceGroupContextIdleTimeout =
- serverConfig.getFirstProperty("Axis2Config.ServiceGroupContextIdleTime");
-
- if (serviceGroupContextIdleTimeout != null) {
- configContext.
- setProperty(org.apache.axis2.Constants.Configuration.
- CONFIG_CONTEXT_TIMOUT_INTERVAL,
- new Integer(serviceGroupContextIdleTimeout));
- }
- }
-
- /**
- * Reads the data base and check whether log setting already there.
- * if so update the logger settings with the database settings
- * else update the data to data base
- * here we assume user never changes the original log4j.properties file.
- */
- private void initLoggingConfiguration() {
-
- // check whether logging configurations are already persisted
- String isLoaded = pm.getConfigurationProperty(ServerConstants.Logging.SYSTEM_LOG_IS_LOADED);
- if (Boolean.valueOf(isLoaded).booleanValue()) {
- LoggingUtil.loadCustomConfiguration();
- } else {
- // parse the logging file and get the information
- LoggingUtil.loadDefaultConfiguration();
- }
- }
-
- private void createDefaultServiceUserRoles() throws ServerException {
- OMElement document = serverConfig.getDocumentElement();
-
- for (Iterator surIte =
- document.getChildrenWithName(
- new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "ServiceUserRoles"));
- surIte.hasNext();) {
-
- OMElement serviceUserRoles = (OMElement) surIte.next();
-
- for (Iterator roleIte =
- serviceUserRoles.getChildrenWithName(
- new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Role"));
- roleIte.hasNext();) {
- OMElement role = (OMElement) roleIte.next();
- ServiceUserRoleDO serviceUserRole = null;
- for (Iterator nameIter =
- role.getChildrenWithName(
- new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Name"));
- nameIter.hasNext();) {
- OMElement name = (OMElement) nameIter.next();
- serviceUserRole = pm.getServiceUserRole(name.getText());
- if (serviceUserRole == null) {
- serviceUserRole = new ServiceUserRoleDO();
- serviceUserRole.setRole(name.getText());
- }
- }
- for (Iterator nameIter =
- role.getChildrenWithName(
- new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Description"));
- nameIter.hasNext();) {
- OMElement description = (OMElement) nameIter.next();
- if (serviceUserRole != null) {
- serviceUserRole.setDescription(description.getText());
- } else {
- throw new ServerException("Description without a Role name is invalid");
- }
- }
- try {
- pm.addOrUpdateUserRole(serviceUserRole);
- } catch (UserRoleAlreadyExistsException ignored) {
- // this exception cannot occur since we've validated it above
- }
- }
- }
- }
-
- private void createDefaultAdminAccount() throws ServerException {
- String adminUsername = "admin";
- ServiceUserDO admin = pm.getUser(adminUsername);
- ServerConfiguration config = ServerConfiguration.getInstance();
- CryptoUtil cryptoUtil =
- new CryptoUtil(new File(
- config.getFirstProperty("Security.KeyStore.Location")).getAbsolutePath(),
- config.getFirstProperty("Security.KeyStore.Password"),
- config.getFirstProperty("Security.KeyStore.KeyAlias"),
- config.getFirstProperty("Security.KeyStore.KeyPassword"),
- config.getFirstProperty("Security.KeyStore.Type"));
- if (admin == null) {
-
- // There is no default admin user. WSAS is starting up for the first time
- // Check whether the default Admin user's password has been changed
- String adminPassword = getDefaultAdminPassword();
- String adminDescription = "Default Adminstrator";
- try {
- admin = new ServiceUserDO();
- admin.setUsername(adminUsername);
- admin.setPassword(cryptoUtil.encryptAndBase64Encode(adminPassword.getBytes()));
- admin.setDescription(adminDescription);
- ServiceUserRoleDO role = pm.getUserRole(ServerConstants.ADMIN_ROLE);
- pm.addUser(admin);
- pm.addRole(admin.getUsername(), role);
- } catch (CryptoException e) {
- String msg = "Cannot encrypt default admin password";
- log.error(msg, e);
- throw new ServerException(msg, e);
- } catch (ServiceUserAlreadyExistsException ignored) {
- // this exception cannot occur since we've validated it above
- }
- } else {
- try {
- if (new String(cryptoUtil.base64DecodeAndDecrypt(admin.getPassword())).
- equals("admin")) {
- String password = getDefaultAdminPassword();
- admin.setPassword(cryptoUtil.encryptAndBase64Encode(password.getBytes()));
- pm.updateUser(admin);
- }
- } catch (Exception e) {
- throw new ServerException(e);
- }
- }
- }
-
- /**
- * There is no default admin user. WSAS is starting up for the first time
- * Check whether the default Admin user's password has been changed
- *
- * @return Default admin password
- */
- private String getDefaultAdminPassword() {
- return "admin";
-
- //TODO: We need to finalize on how we are to handle capturing of the default admin password
- /*String adminPassword = System.getProperty(ServerConstants.WSO2WSAS_ADMIN_PASSWORD);
- if (adminPassword != null && !adminPassword.equals("admin")) {
- return adminPassword;
- }
- System.out.println(" Please enter the password of Administrator 'admin'");
- String passwordRepeat = null;
- do {
- while (adminPassword == null || adminPassword.trim().length() == 0) {
- try {
- adminPassword = InputReader.readPassword(" New password: ");
- if (adminPassword.equals("admin")) {
- adminPassword = null;
- System.err.println(" This password is not allowed." +
- " Please enter another password.");
- }
- } catch (IOException e) {
- System.err.println(" Unable to read password : " + e);
- }
- }
- while (passwordRepeat == null || passwordRepeat.trim().length() == 0) {
- try {
- passwordRepeat = InputReader.readPassword(" Re-enter new password: ");
- } catch (IOException e) {
- System.err.println(" Unable to read re-entered password : " + e);
- }
- }
- if (!adminPassword.equals(passwordRepeat)) {
- System.err.println(" Password and re-entered password do not match");
- adminPassword = null;
- passwordRepeat = null;
- continue;
- }
- System.out.println(" Password for Admin user changed.");
- break;
- } while (true);
- return adminPassword;*/
- }
-
-
- private void registerHouseKeepingTask() {
- if (!isHouseKeepingTaskCreated) {
- if (Boolean.valueOf(serverConfig.
- getFirstProperty("HouseKeeping.AutoStart")).booleanValue()) {
- houseKeepingTimer = new Timer();
- long houseKeepingInterval =
- Long.parseLong(serverConfig.
- getFirstProperty("HouseKeeping.Interval")) * 60 * 1000;
- Object property =
- configContext.getProperty(ServerConstants.FILE_RESOURCE_MAP);
- if (property == null) {
- property = new TreeBidiMap();
- configContext.setProperty(ServerConstants.FILE_RESOURCE_MAP, property);
- }
- houseKeepingTimer.scheduleAtFixedRate(new HouseKeepingTask(serverWorkDir,
- (BidiMap) property),
- houseKeepingInterval,
- houseKeepingInterval);
- isHouseKeepingTaskCreated = true;
- }
- }
- }
-
- private void handleGlobalModuleEngagements(AxisConfiguration axisConfig)
- throws ServerException {
- try {
- ModuleDO[] moduleDOs = pm.getAllModules();
- for (int i = 0; i < moduleDOs.length; i++) {
- ModuleDO moduleDO = moduleDOs[i];
- if (moduleDO.getIsGloballyEngaged()) {
- String moduleId = moduleDO.getModuleIdentifierDO().getName();
- if (!axisConfig.isEngaged(moduleId)) {
- axisConfig.engageModule(moduleId);
- }
-
- // We should not engage the throttle module to the wso2wsas-administration service group
- if (moduleId.equals("wso2throttle")) {
- axisConfig.getServiceGroup(ServerConstants.ADMIN_SERVICE_GROUP).
- disengageModule(axisConfig.getModule(moduleId));
- }
- }
- }
- } catch (Exception e) {
- String msg = Messages.getMessage("CannotConfigureAxis2");
- log.error(msg);
- throw new ServerException(msg, e);
- }
- }
public void status() {
}
@@ -527,4 +161,69 @@
listenerManager.destroy();
}
}
+
+ private void processServerIntializer() throws ServerException {
+ //TODO better pattern will be the builder
+ OMElement documentEle = this.serverConfig.getDocumentElement();
+ OMElement serverInitEle = documentEle.getFirstChildWithName(
+ new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "ServerInitializer"));
+ if (serverInitEle == null) {
+ String message =
+ ServerManager.class.getName() +
+ " mandatory element ServerInitializer can not be found";
+ log.error(message);
+ throw new ServerException(message);
+ }
+
+ ArrayList serverInitList = new ArrayList();
+
+ for (Iterator iterator = serverInitEle.getChildrenWithName(
+ new QName(ServerConstants.WSO2WSAS_XML_NAMESPACE, "Initialize"));
+ iterator.hasNext();) {
+
+ OMElement e = (OMElement) iterator.next();
+
+ String clazzName = e.getText();
+ if (clazzName == null) {
+ String message = ServerManager.class.getName() + " intializer couldn't be found.";
+ log.error(message);
+ throw new ServerException(message);
+ }
+
+ try {
+ Class clazz = Class.forName(clazzName);
+
+ ServerInitializer serverInitObj = (ServerInitializer) clazz.newInstance();
+ serverInitObj.setConfigurationContext(configContext);
+ serverInitList.add(serverInitObj);
+
+ } catch (ClassNotFoundException e1) {
+ log.error(e1);
+ throw new ServerException(e1);
+ } catch (IllegalAccessException e1) {
+ log.error(e1);
+ throw new ServerException(e1);
+ } catch (InstantiationException e1) {
+ log.error(e1);
+ throw new ServerException(e1);
+ }
+
+ }
+ configContext.setProperty(ServerConstants.WSO2WSAS_SERVER_INITIALIZER_LIST, serverInitList);
+
+ }
+
+ private void startServerIntializer() throws ServerException, AxisFault {
+
+ processServerIntializer();
+
+ ArrayList serverInitList = (ArrayList) configContext
+ .getProperty(ServerConstants.WSO2WSAS_SERVER_INITIALIZER_LIST);
+ for (int i = 0 ; i < serverInitList.size();i++) {
+ ServerInitializer serverInitializer = (ServerInitializer)serverInitList.get(i);
+ log.info("Intializing ServerInitializer " + ServerInitializer.class.getName());
+ serverInitializer.init();
+ }
+
+ }
}
Modified: trunk/wsas/java/modules/servlet-edition/conf/server.xml
==============================================================================
--- trunk/wsas/java/modules/servlet-edition/conf/server.xml (original)
+++ trunk/wsas/java/modules/servlet-edition/conf/server.xml Fri Jun 1 01:37:04 2007
@@ -276,4 +276,13 @@
<Class>org.wso2.wsas.transport.util.CertProcessor</Class>
</Processor>
</HttpGetRequestProcessors>
+
+ <!--
+ Server intializing code. DefaultServerInitializer will intialize the WSAS specific
+ Configurations. It should be the first. All other intializers should come after that.
+ Use <Initialize/> elements to add new intializers.
+ -->
+ <ServerInitializer>
+ <Initialize>org.wso2.wsas.DefaultServerInitializer</Initialize>
+ </ServerInitializer>
</Server>
Modified: trunk/wsas/java/modules/standalone-edition/conf/server.xml
==============================================================================
--- trunk/wsas/java/modules/standalone-edition/conf/server.xml (original)
+++ trunk/wsas/java/modules/standalone-edition/conf/server.xml Fri Jun 1 01:37:04 2007
@@ -195,7 +195,7 @@
<Action>service</Action>
</Actions>
<Class>org.wso2.wsas.transport.fileupload.ServiceFileUploadExecutor</Class>
- </Mapping>
+ </Mapping>
<Mapping>
<Actions>
<Action>ejbinterface</Action>
@@ -262,4 +262,14 @@
<Class>org.wso2.wsas.transport.util.CertProcessor</Class>
</Processor>
</HttpGetRequestProcessors>
+
+ <!--
+ Server intializing code. DefaultServerInitializer will intialize the WSAS specific
+ Configurations. It should be the first. All other intializers should come after that.
+ Use <Initialize/> elements to add new intializers.
+ -->
+ <ServerInitializer>
+ <Initialize>org.wso2.wsas.DefaultServerInitializer</Initialize>
+ </ServerInitializer>
+
</Server>
Modified: trunk/wsas/java/modules/standalone-edition/src/org/wso2/wsas/Main.java
==============================================================================
--- trunk/wsas/java/modules/standalone-edition/src/org/wso2/wsas/Main.java (original)
+++ trunk/wsas/java/modules/standalone-edition/src/org/wso2/wsas/Main.java Fri Jun 1 01:37:04 2007
@@ -29,6 +29,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Map;
+import java.util.ArrayList;
/**
* The main class of the WSO2 WSAS standalone distribution
@@ -95,7 +96,12 @@
public void shutdown() throws ServerException {
stopListeners();
- ServerManager.getInstance().stopHouseKeeping();
+ ArrayList arrayList = (ArrayList) ServerManager.getInstance().configContext
+ .getProperty(ServerConstants.WSO2WSAS_SERVER_INITIALIZER_LIST);
+ for (int j = 0 ; j < arrayList.size(); j++) {
+ ServerInitializer serverInitializer = (ServerInitializer)arrayList.get(j);
+ serverInitializer.shutdown();
+ }
cleanupSystem();
}
Modified: trunk/wsas/java/modules/standalone-edition/test-resources/server.xml
==============================================================================
--- trunk/wsas/java/modules/standalone-edition/test-resources/server.xml (original)
+++ trunk/wsas/java/modules/standalone-edition/test-resources/server.xml Fri Jun 1 01:37:04 2007
@@ -180,4 +180,13 @@
<Class>org.wso2.wsas.transport.fileupload.SpringFileUploadExecutor</Class>
</Mapping>
</FileUploadConfig>
+
+ <!--
+ Server intializing code. DefaultServerInitializer will intialize the WSAS specific
+ Configurations. It should be the first. All other intializers should come after that.
+ Use <Initialize/> elements to add new intializers.
+ -->
+ <ServerInitializer>
+ <Initialize>org.wso2.wsas.DefaultServerInitializer</Initialize>
+ </ServerInitializer>
</Server>
\ No newline at end of file
More information about the Wsas-java-dev
mailing list