You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2009/03/04 09:59:05 UTC
svn commit: r749945 - in /synapse/trunk/java:
modules/core/src/main/java/org/apache/synapse/
modules/core/src/main/java/org/apache/synapse/config/
modules/core/src/main/java/org/apache/synapse/endpoints/
modules/core/src/main/java/org/apache/synapse/se...
Author: indika
Date: Wed Mar 4 08:59:03 2009
New Revision: 749945
URL: http://svn.apache.org/viewvc?rev=749945&view=rev
Log:
some changes related to SYNAPSE-376
Not yet completed funtionality or logs or docs
Added:
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/MultiSecretCallback.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallback.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallbackHandler.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretLoadingModule.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SingleSecretCallback.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Endpoint.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdmin.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdminMBean.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/SecretManager.java
synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PWCallback.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceConfigurationConstants.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformation.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceFactory.java
synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
synapse/trunk/java/repository/conf/synapse.properties
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java Wed Mar 4 08:59:03 2009
@@ -82,7 +82,8 @@
this.information = configurationInformation;
- if (contextInformation == null) {
+ if (contextInformation == null || contextInformation.getServerContext() == null ||
+ configurationInformation.isCreateNewInstance()) {
if (log.isDebugEnabled()) {
log.debug("Initializing Synapse in a new axis2 server environment instance ");
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java Wed Mar 4 08:59:03 2009
@@ -30,6 +30,11 @@
/* A map to hold any context information*/
private final Map<String, Object> properties = new HashMap<String, Object>();
+ private ServerState serverState = ServerState.UNDETERMINED;
+
+ public ServerContextInformation() {
+ }
+
public ServerContextInformation(Object serverContext) {
this.serverContext = serverContext;
}
@@ -37,7 +42,8 @@
public Object getServerContext() {
return serverContext;
}
- public void setServerContext(Object serverContext){
+
+ public void setServerContext(Object serverContext) {
this.serverContext = serverContext;
}
@@ -48,4 +54,12 @@
public Object getProperty(String key) {
return properties.get(key);
}
+
+ public ServerState getServerState() {
+ return serverState;
+ }
+
+ public void setServerState(ServerState serverState) {
+ this.serverState = serverState;
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java Wed Mar 4 08:59:03 2009
@@ -37,14 +37,16 @@
private final static ServerManager instance = new ServerManager();
- /* The controller for synapse create and Destroy synapse artifacts in a particular environment*/
+ /* The controller for synapse create and Destroy synapse artifacts in a particular environment
+ Only for internal usage - DON"T PUT GETTER ,SETTER */
private SynapseController synapseController;
/* Server Configuration */
private ServerConfigurationInformation configurationInformation;
/* Server context */
private ServerContextInformation contextInformation;
- /* The state of the server - the state that marked at last operation on server */
- private ServerState serverState = ServerState.UNDETERMINED;
+ /*Only represents whether server manager has been initialized by given required
+ configuration information - not server state or internal usage - DON"T PUT SETTER */
+ private boolean initialized = false;
public static ServerManager getInstance() {
return instance;
@@ -59,12 +61,20 @@
*/
public ServerState init(ServerConfigurationInformation configurationInformation,
ServerContextInformation contextInformation) {
+
this.configurationInformation = configurationInformation;
- this.contextInformation = contextInformation;
+ if (contextInformation == null) {
+ this.contextInformation = new ServerContextInformation();
+ } else {
+ this.contextInformation = contextInformation;
+ }
this.synapseController = SynapseControllerFactory
.createSynapseController(configurationInformation);
+
+ this.initialized = true;
+
doInit();
- return this.serverState;
+ return this.contextInformation.getServerState();
}
/**
@@ -73,9 +83,10 @@
* @return ServerState - The state of the server after call this operation
*/
public ServerState start() {
+ assertInitialized();
doInit();
doStart();
- return this.serverState;
+ return this.contextInformation.getServerState();
}
/**
@@ -84,8 +95,9 @@
* @return ServerState - The state of the server after call this operation
*/
public ServerState stop() {
+ assertInitialized();
doStop();
- return this.serverState;
+ return this.contextInformation.getServerState();
}
/**
@@ -94,6 +106,7 @@
* @return ServerConfigurationInformation insatnce
*/
public ServerConfigurationInformation getInformation() {
+ assertInitialized();
return configurationInformation;
}
@@ -103,6 +116,7 @@
* @return ServerContextInformation instance
*/
public ServerContextInformation getContextInformation() {
+ assertInitialized();
return contextInformation;
}
@@ -111,11 +125,11 @@
*/
private void doInit() {
- this.serverState = ServerStateDetectionStrategy.currentState(serverState,
+ ServerState serverState = ServerStateDetectionStrategy.currentState(contextInformation,
configurationInformation);
- if (this.serverState == ServerState.INITIALIZABLE) {
-
+ if (serverState == ServerState.INITIALIZABLE) {
+
this.synapseController.init(configurationInformation, contextInformation);
if (this.contextInformation == null) {
@@ -124,8 +138,9 @@
} else if (this.contextInformation.getServerContext() == null) {
this.contextInformation.setServerContext(this.synapseController.getContext());
}
-
- this.serverState = ServerState.INITIALIZED;
+ chanageState(ServerState.INITIALIZED);
+ } else {
+ chanageState(serverState);
}
}
@@ -134,15 +149,17 @@
*/
private void doStart() {
- this.serverState = ServerStateDetectionStrategy.currentState(serverState,
+ ServerState serverState = ServerStateDetectionStrategy.currentState(contextInformation,
configurationInformation);
- if (this.serverState == ServerState.INITIALIZED) {
+ if (serverState == ServerState.INITIALIZED) {
this.synapseController.createSynapseConfiguration();
this.synapseController.createSynapseEnvironment();
- this.serverState = ServerState.STARTED;
+ chanageState(ServerState.STARTED);
log.info("Ready for processing");
+ } else {
+ chanageState(serverState);
}
}
@@ -151,7 +168,7 @@
*/
private void doStop() {
- this.serverState = ServerStateDetectionStrategy.currentState(serverState,
+ ServerState serverState = ServerStateDetectionStrategy.currentState(contextInformation,
configurationInformation);
switch (serverState) {
@@ -166,7 +183,33 @@
break;
}
}
- this.serverState = ServerState.STOPPED;
+ chanageState(ServerState.STOPPED);
+ this.initialized = false;
+ }
+
+ private void chanageState(ServerState serverState) {
+ this.contextInformation.setServerState(serverState);
+ }
+
+ private void assertInitialized() {
+ if (!initialized) {
+ String msg = "Server manager has not been initialized by giving " +
+ "required configurations information." +
+ "It is needed to initiate by giving required configurations information ," +
+ " before access any operations";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ }
+
+ /**
+ * Has server manager been initialized ?
+ *
+ * @return true if the server manager has been initialized by given required
+ * configuration information
+ */
+ public boolean isInitialized() {
+ return initialized;
}
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerStateDetectionStrategy.java Wed Mar 4 08:59:03 2009
@@ -30,14 +30,13 @@
/**
* Determine the next possible server state based on current states and other facts
*
- * @param previousState Previuos server state , a state where server was
- * there when last time check
- * @param information ServerConfigurationInformation instance
+ * @param contextInformation ServerContextInformation instance
+ * @param information ServerConfigurationInformation instance
* @return The actual current state possible states for the server
*/
- public static ServerState currentState(ServerState previousState,
+ public static ServerState currentState(ServerContextInformation contextInformation,
ServerConfigurationInformation information) {
-
+ ServerState previousState = contextInformation.getServerState();
String deploymentMode = information.getDeploymentMode();
if (previousState == ServerState.UNDETERMINED) {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseControllerFactory.java Wed Mar 4 08:59:03 2009
@@ -56,15 +56,15 @@
if (instance != null && instance instanceof SynapseController) {
return (SynapseController) instance;
} else {
- handleFatal("Invalid class as SecretRepositoryProvider : Class Name : " + provider);
+ fatal("Invalid class as SynapseController : Class Name : " + provider);
}
} catch (ClassNotFoundException e) {
- handleFatal("A Secret Provider cannot be found for class name : " + provider);
+ fatal("A SynapseController cannot be found for class name : " + provider, e);
} catch (IllegalAccessException e) {
- handleFatal("Error creating a instance from class : " + provider);
+ fatal("Error creating a instance from class : " + provider, e);
} catch (InstantiationException e) {
- handleFatal("Error creating a instance from class : " + provider);
+ fatal("Error creating a instance from class : " + provider, e);
}
return null;
}
@@ -76,9 +76,13 @@
*/
private static void validate(ServerConfigurationInformation information) {
+ if (information == null) {
+ fatal("Server Configuration Information is null");
+ }
+
String synapseHome = information.getSynapseHome();
if (synapseHome == null || !new File(synapseHome).exists()) {
- handleFatal("Synapse home");
+ fatalOnParameterValidationFailure("Synapse home");
} else {
log.info("Using Synapse home as : " + synapseHome);
}
@@ -86,7 +90,7 @@
if (information.isCreateNewInstance()) {
String axis2Repolocation = information.getAxis2RepoLocation();
if (axis2Repolocation == null || !new File(axis2Repolocation).exists()) {
- handleFatal("Axis2 repository");
+ fatalOnParameterValidationFailure("Axis2 repository");
} else {
log.info("Using the Axis2 Repository : " +
new File(axis2Repolocation).getAbsolutePath());
@@ -94,7 +98,7 @@
String axis2Xml = information.getAxis2Xml();
if (axis2Xml == null || !new File(axis2Xml).exists()) {
- handleFatal("axis2.xml location");
+ fatalOnParameterValidationFailure("axis2.xml location");
} else {
log.info("Using the axis2.xml : " + new File(axis2Xml).getAbsolutePath());
}
@@ -102,7 +106,7 @@
String synapseXMLPath = information.getSynapseXMLLocation();
if (synapseXMLPath == null || !new File(synapseXMLPath).exists()) {
- handleFatal("synapse.xml path");
+ fatalOnParameterValidationFailure("synapse.xml path");
}
String serverName = information.getServerName();
@@ -124,9 +128,19 @@
(SynapseConfigUtils.getTimeoutHandlerInterval() / 1000) + "s");
}
- private static void handleFatal(String msgPre) {
+ private static void fatalOnParameterValidationFailure(String msgPre) {
String msg = "The " + msgPre + " must be set as a system property or init-parameter";
log.fatal(msg);
throw new SynapseException(msg);
}
+
+ private static void fatal(String msg) {
+ log.fatal(msg);
+ throw new SynapseException(msg);
+ }
+
+ private static void fatal(String msg, Exception e) {
+ log.fatal(msg, e);
+ throw new SynapseException(msg, e);
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java Wed Mar 4 08:59:03 2009
@@ -633,28 +633,37 @@
}
public static String getSynapseHome() {
- ServerConfigurationInformation information =
- ServerManager.getInstance().getInformation();
- if (information != null) {
- return information.getSynapseHome();
+ ServerManager serverManager = ServerManager.getInstance();
+ if (serverManager.isInitialized()) {
+ ServerConfigurationInformation information =
+ serverManager.getInformation();
+ if (information != null) {
+ return information.getSynapseHome();
+ }
}
return "";
}
public static String getServerName() {
- ServerConfigurationInformation information =
- ServerManager.getInstance().getInformation();
- if (information != null) {
- return information.getServerName();
+ ServerManager serverManager = ServerManager.getInstance();
+ if (serverManager.isInitialized()) {
+ ServerConfigurationInformation information =
+ serverManager.getInformation();
+ if (information != null) {
+ return information.getServerName();
+ }
}
return "";
}
public static String getResolveRoot() {
- ServerConfigurationInformation information =
- ServerManager.getInstance().getInformation();
- if (information != null) {
- return information.getResolveRoot();
+ ServerManager serverManager = ServerManager.getInstance();
+ if (serverManager.isInitialized()) {
+ ServerConfigurationInformation information =
+ serverManager.getInformation();
+ if (information != null) {
+ return information.getResolveRoot();
+ }
}
return "";
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Endpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Endpoint.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Endpoint.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Endpoint.java Wed Mar 4 08:59:03 2009
@@ -20,7 +20,6 @@
package org.apache.synapse.endpoints;
import org.apache.synapse.MessageContext;
-import org.apache.synapse.ManagedLifecycle;
import java.util.List;
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdmin.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdmin.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdmin.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdmin.java Wed Mar 4 08:59:03 2009
@@ -36,8 +36,23 @@
/**
* @see SecretManagerAdminMBean
*/
- public void init(String identityStorePass, String identityKeyPass, String trustStorePass) {
+ public void init() {
+ this.secretManager.init();
+ }
+
+ public void shutDown() {
+ this.secretManager.shoutDown();
+ }
+
+ public void setIdentityStorePassword(String identityStorePassword) {
+ this.secretManager.setIdentityKeyPassword(identityStorePassword);
+ }
+
+ public void setIdentityKeyPassword(String identityKeyPassword) {
+ secretManager.setIdentityKeyPassword(identityKeyPassword);
+ }
- secretManager.init(identityStorePass, identityKeyPass, trustStorePass);
+ public void setTrustStorePassword(String trustStorePassword) {
+ this.secretManager.setTrustStorePassword(trustStorePassword);
}
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdminMBean.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdminMBean.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdminMBean.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretManagerAdminMBean.java Wed Mar 4 08:59:03 2009
@@ -26,10 +26,26 @@
/**
* Initialize the SecretManager
- *
- * @param identityStorePass Identity keyStore password
- * @param identityKeyPass Private key Password
- * @param trustStorePass TrustStore password
*/
- public void init(String identityStorePass, String identityKeyPass, String trustStorePass);
+ public void init();
+
+ /**
+ * Shutting Down the SecretManager
+ */
+ public void shutDown();
+
+ /**
+ * @param identityStorePassword Identity keyStore password
+ */
+ public void setIdentityStorePassword(String identityStorePassword);
+
+ /**
+ * @param identityKeyPassword Private key Password
+ */
+ public void setIdentityKeyPassword(String identityKeyPassword);
+
+ /**
+ * @param trustStorePassword TrustStore password
+ */
+ public void setTrustStorePassword(String trustStorePassword);
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/SecretManager.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/SecretManager.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/SecretManager.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/SecretManager.java Wed Mar 4 08:59:03 2009
@@ -43,6 +43,12 @@
/* True , if secret manage has been started up properly- need to have a at
least one Secret Repository*/
private boolean initialized = false;
+ /* Identity key store password*/
+ private String identityStorePassword;
+ /* Identity key password */
+ private String identityKeyPassword;
+ /* Trust store password */
+ private String trustStorePassword;
public static SecretManager getInstance() {
return SECRET_MANAGER;
@@ -53,14 +59,9 @@
}
/**
- * Initializes the Secret Manager .Paswords for both trusted and private keyStores have to be
- * provided separately due to security reasons
- *
- * @param identityStorePass Password to access private keyStore
- * @param identityKeyPass Password to access private or secret keys
- * @param trustStorePass Password to access trusted KeyStore
+ * Initialize the Secret Manager
*/
- public void init(String identityStorePass, String identityKeyPass, String trustStorePass) {
+ public void init() {
if (initialized) {
if (log.isDebugEnabled()) {
@@ -69,27 +70,70 @@
return;
}
- Properties keyStoreProperties = SynapsePropertiesLoader.loadSynapseProperties();
- if (keyStoreProperties == null) {
+ Properties configurationProperties = loadConfigurationPropertis();
+ if (configurationProperties == null) {
if (log.isDebugEnabled()) {
- log.debug("KeyStore configuration properties cannot be found");
+ log.debug("Secret Manager configuration properties cannot be found. " +
+ "Cannot initialize SecretManager");
}
return;
}
- String configurationFile = MiscellaneousUtil.getProperty(
- keyStoreProperties, SECRET_MANAGER_CONF, DEFAULT_CONF_LOCATION);
+ if (assertValidPasswords(identityStorePassword, identityKeyPassword, trustStorePassword)) {
+ init(configurationProperties, identityStorePassword, identityKeyPassword, trustStorePassword);
+ }
+ }
- Properties configurationProperties = MiscellaneousUtil.loadProperties(configurationFile);
- if (configurationProperties == null || configurationProperties.isEmpty()) {
+ /**
+ * Returns the secret corresponding to the given alias name
+ *
+ * @param alias The logical or alias name
+ * @return If there is a secret , otherwise , alias itself
+ */
+ public String getSecret(String alias) {
+ if (!initialized || parentRepository == null) {
if (log.isDebugEnabled()) {
- log.debug("Configuration properties can not be loaded form : " +
- configurationFile + " Will use synapse properties");
+ log.debug("There is no secret repository. Returning alias itself");
}
- configurationProperties = keyStoreProperties;
-
+ return alias;
}
+ return parentRepository.getSecret(alias);
+ }
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ public void shoutDown() {
+ this.parentRepository = null;
+ this.initialized = false;
+ }
+
+ public void setIdentityStorePassword(String identityStorePassword) {
+ this.identityStorePassword = identityStorePassword;
+ }
+
+ public void setIdentityKeyPassword(String identityKeyPassword) {
+ this.identityKeyPassword = identityKeyPassword;
+ }
+
+ public void setTrustStorePassword(String trustStorePassword) {
+ this.trustStorePassword = trustStorePassword;
+ }
+
+ /**
+ * Initializes the Secret Manager .Paswords for both trusted and private keyStores have to be
+ * provided separately due to security reasons
+ *
+ * @param configurationProperties Secret Manager configuration properties
+ * @param identityStorePass Password to access private keyStore
+ * @param identityKeyPass Password to access private or secret keys
+ * @param trustStorePass Password to access trusted KeyStore
+ */
+ private void init(Properties configurationProperties, String identityStorePass,
+ String identityKeyPass, String trustStorePass) {
+
+ Properties keyStoreProperties = SynapsePropertiesLoader.loadSynapseProperties();
String repositoriesString = MiscellaneousUtil.getProperty(
configurationProperties, SECRET_REPOSITORIES, null);
if (repositoriesString == null || "".equals(repositoriesString)) {
@@ -107,30 +151,6 @@
return;
}
- boolean inValid = false;
- if (identityStorePass == null || "".equals(identityStorePass)) {
- if (log.isDebugEnabled()) {
- log.debug("Identity KeyStore Password cannot be found.");
- }
- inValid = true;
- }
-
- if (identityKeyPass == null || "".equals(identityKeyPass)) {
- if (log.isDebugEnabled()) {
- log.debug("Identity Key Password cannot be found.");
- }
- }
-
- if (trustStorePass == null || "".equals(trustStorePass)) {
- if (log.isDebugEnabled()) {
- log.debug("Trust Store Password cannot be null.");
- }
- if (inValid) {
- handleException("Either Identity or Trust keystore password is mandotory" +
- " in order to initialized secret manager.");
- }
- }
-
//Create a KeyStore Information for private key entry KeyStore
IdentityKeyStoreInformation keyStoreInformation =
KeyStoreInformationFactory.createIdentityKeyStoreInformation(keyStoreProperties);
@@ -183,10 +203,12 @@
secretRepository.setParent(currentParent);
currentParent = secretRepository;
if (log.isDebugEnabled()) {
- log.debug("Successfully Initiate a Secret Repository provided by : " + provider);
+ log.debug("Successfully Initiate a Secret Repository provided by : " +
+ provider);
}
} else {
- handleException("Invalid class as SecretRepositoryProvider : Class Name : " + provider);
+ handleException("Invalid class as SecretRepositoryProvider : Class Name : " +
+ provider);
}
} catch (ClassNotFoundException e) {
@@ -197,33 +219,45 @@
handleException("Error creating a instance from class : " + provider);
}
}
-
+
initialized = true;
}
- /**
- * Returns the secret corresponding to the given alias name
- *
- * @param alias The logical or alias name
- * @return If there is a secret , otherwise , alias itself
- */
- public String getSecret(String alias) {
- if (!initialized || parentRepository == null) {
+ private boolean assertValidPasswords(String identityStorePass,
+ String identityKeyPass, String trustStorePass) {
+ boolean isValid = false;
+ if (trustStorePass != null && !"".equals(trustStorePass)) {
if (log.isDebugEnabled()) {
- log.debug("There is no secret repository. Returning alias itself");
+ log.debug("Trust Store Password cannot be found.");
+ }
+ isValid = true;
+ } else {
+ if (identityStorePass != null && !"".equals(identityStorePass) &&
+ identityKeyPass != null && !"".equals(identityKeyPass)) {
+ isValid = true;
}
- return alias;
}
- return parentRepository.getSecret(alias);
+ return isValid;
}
- public boolean isInitialized() {
- return initialized;
- }
+ private Properties loadConfigurationPropertis() {
+ Properties keyStoreProperties = SynapsePropertiesLoader.loadSynapseProperties();
+ if (keyStoreProperties != null) {
+ String configurationFile = MiscellaneousUtil.getProperty(
+ keyStoreProperties, SECRET_MANAGER_CONF, DEFAULT_CONF_LOCATION);
+
+ Properties configurationProperties = MiscellaneousUtil.loadProperties(configurationFile);
+ if (configurationProperties == null || configurationProperties.isEmpty()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Configuration properties can not be loaded form : " +
+ configurationFile + " Will use synapse properties");
+ }
+ configurationProperties = keyStoreProperties;
- public void shoutDown() {
- this.parentRepository = null;
- this.initialized = false;
+ }
+ return configurationProperties;
+ }
+ return null;
}
private static void handleException(String msg) {
@@ -233,6 +267,7 @@
private void registerMBean() {
MBeanRegistrar mBeanRegistrar = MBeanRegistrar.getInstance();
- mBeanRegistrar.registerMBean(new SecretManagerAdmin(this), "SecurityAdminServices", "SecretManagerAdmin");
+ mBeanRegistrar.registerMBean(new SecretManagerAdmin(this), "SecurityAdminServices",
+ "SecretManagerAdmin");
}
}
Modified: synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PWCallback.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PWCallback.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PWCallback.java (original)
+++ synapse/trunk/java/modules/samples/src/main/java/samples/userguide/PWCallback.java Wed Mar 4 08:59:03 2009
@@ -81,17 +81,17 @@
* This usage type is used only in case we received a
- * username token with a password of type PasswordText or
+ * username token with a secret of type PasswordText or
- * an unknown password type.
+ * an unknown secret type.
*
* This case the WSPasswordCallback object contains the
- * identifier (aka username), the password we received, and
+ * identifier (aka username), the secret we received, and
- * the password type string to identify the type.
+ * the secret type string to identify the type.
*
@@ -127,11 +127,11 @@
/*
- * here call a function/method to lookup the password for
+ * here call a function/method to lookup the secret for
* the given identifier (e.g. a user name or keystore alias)
- * e.g.: pc.setPassword(passStore.getPassword(pc.getIdentfifier))
+ * e.g.: pc.setSecret(passStore.getSecret(pc.getIdentfifier))
* for Testing we supply a fixed name here.
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceConfigurationConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceConfigurationConstants.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceConfigurationConstants.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceConfigurationConstants.java Wed Mar 4 08:59:03 2009
@@ -25,6 +25,7 @@
public static final String PROP_USER_NAME = "username";
public static final String PROP_PASSWORD = "password";
+ public static final String PROP_PASSWORD_PROVIDER = "passwordProvider";
public static final String PROP_DRIVER_CLS_NAME = "driverClassName";
public static final String PROP_DSNAME = "dsName";
public static final String PROP_URL = "url";
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformation.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformation.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformation.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformation.java Wed Mar 4 08:59:03 2009
@@ -19,6 +19,7 @@
package org.apache.synapse.commons.util.datasource;
import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.synapse.commons.util.secret.SecretCallbackHandler;
import java.util.HashMap;
import java.util.Map;
@@ -57,6 +58,7 @@
private final Properties properties = new Properties();
private String repositoryType = DataSourceConfigurationConstants.PROP_REGISTRY_MEMORY;
private String alias;
+ private SecretCallbackHandler passwordProvider;
private long timeBetweenEvictionRunsMillis =
GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
@@ -340,4 +342,12 @@
public Map<String, Object> getAllParameters() {
return this.parameters;
}
+
+ public SecretCallbackHandler getPasswordProvider() {
+ return passwordProvider;
+ }
+
+ public void setPasswordProvider(SecretCallbackHandler passwordProvider) {
+ this.passwordProvider = passwordProvider;
+ }
}
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceFactory.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceFactory.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceFactory.java Wed Mar 4 08:59:03 2009
@@ -24,9 +24,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.util.SynapseUtilException;
+import org.apache.synapse.commons.util.secret.SecretCallbackHandler;
+import org.apache.synapse.commons.util.secret.SecretLoadingModule;
+import org.apache.synapse.commons.util.secret.SecretCallback;
+import org.apache.synapse.commons.util.secret.SingleSecretCallback;
import org.apache.synapse.commons.util.datasource.DataSourceInformation;
import javax.sql.DataSource;
+import java.util.List;
/**
* Factory for creating a DataSource based on information in DataSourceInformation
@@ -34,6 +39,7 @@
public class DataSourceFactory {
private final static Log log = LogFactory.getLog(DataSourceFactory.class);
+ private final static String PROMPT = "DataBase Password for ";
private DataSourceFactory() {
}
@@ -64,11 +70,19 @@
String user = information.getUser();
String password = information.getPassword();
- //TODO move security code
-// SecretManager secretManager = SecretManager.getInstance();
-// if (secretManager.isInitialized()) {
-// password = secretManager.getSecret(password);
-// }
+ SecretCallbackHandler secretCallbackHandler = information.getPasswordProvider();
+
+ if (secretCallbackHandler != null) {
+ SecretLoadingModule secretLoadingModule = new SecretLoadingModule();
+ secretLoadingModule.init(new SecretCallbackHandler[]{secretCallbackHandler});
+ SecretCallback[] secretCallbacks = new SecretCallback[0];
+ SingleSecretCallback secretCallback = new SingleSecretCallback();
+ secretCallback.setPrompt(PROMPT + information.getAlias());
+ secretCallbacks[0] = secretCallback;
+ secretLoadingModule.load(secretCallbacks);
+ password = secretCallback.getSecret();
+ }
+
int defaultTransactionIsolation = information.getDefaultTransactionIsolation();
Modified: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java (original)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java Wed Mar 4 08:59:03 2009
@@ -24,6 +24,7 @@
import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.synapse.commons.util.MiscellaneousUtil;
import org.apache.synapse.commons.util.SynapseUtilException;
+import org.apache.synapse.commons.util.secret.SecretCallbackHandler;
import org.apache.synapse.commons.util.datasource.DataSourceConfigurationConstants;
import org.apache.synapse.commons.util.datasource.DataSourceInformation;
@@ -274,7 +275,32 @@
MiscellaneousUtil.getProperty(
properties, prefix + DataSourceConfigurationConstants.PROP_PROVIDER_PORT,
null));
-
+ String provider = MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_PASSWORD_PROVIDER,
+ null);
+
+ if (provider != null && !"".equals(provider)) {
+
+ try {
+ Class aClass = Thread.currentThread().getContextClassLoader().loadClass(provider);
+ Object instance = aClass.newInstance();
+
+ if (instance != null && instance instanceof SecretCallbackHandler) {
+ information.setPasswordProvider((SecretCallbackHandler) instance);
+ } else {
+ handleException("Invalid class as SecretCallbackHandler : Class Name : " +
+ provider);
+ }
+
+ } catch (ClassNotFoundException e) {
+ handleException("A SecretCallbackHandler cannot be found for class name : " +
+ provider, e);
+ } catch (IllegalAccessException e) {
+ handleException("Error creating a instance from class : " + provider, e);
+ } catch (InstantiationException e) {
+ handleException("Error creating a instance from class : " + provider, e);
+ }
+ }
return information;
}
@@ -287,4 +313,15 @@
log.error(msg);
throw new SynapseUtilException(msg);
}
+
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ * @param e Thorwen Exception
+ */
+ private static void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseUtilException(msg, e);
+ }
}
Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/MultiSecretCallback.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/MultiSecretCallback.java?rev=749945&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/MultiSecretCallback.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/MultiSecretCallback.java Wed Mar 4 08:59:03 2009
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.synapse.commons.util.secret;
+
+import java.util.*;
+
+/**
+ * Represents group of any number of Callbacks - group means, they provide secret for a one use
+ */
+
+public class MultiSecretCallback implements SecretCallback {
+
+ private final Map<String, SecretCallback> secretCallbacks =
+ new HashMap<String, SecretCallback>();
+
+ public void addSecretCallback(String id, SecretCallback secretCallback) {
+ secretCallbacks.put(id, secretCallback);
+ }
+
+ public Iterator<SecretCallback> getSecretCallbacks() {
+ return secretCallbacks.values().iterator();
+ }
+
+ public SecretCallback getSecretCallback(String id) {
+ return secretCallbacks.get(id);
+ }
+}
Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallback.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallback.java?rev=749945&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallback.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallback.java Wed Mar 4 08:59:03 2009
@@ -0,0 +1,7 @@
+package org.apache.synapse.commons.util.secret;
+
+/**
+ *
+ */
+public interface SecretCallback {
+}
Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallbackHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallbackHandler.java?rev=749945&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallbackHandler.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretCallbackHandler.java Wed Mar 4 08:59:03 2009
@@ -0,0 +1,9 @@
+package org.apache.synapse.commons.util.secret;
+
+/**
+ *
+ */
+public interface SecretCallbackHandler {
+
+ public void handle(SecretCallback[] secretCallbacks);
+}
Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretLoadingModule.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretLoadingModule.java?rev=749945&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretLoadingModule.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SecretLoadingModule.java Wed Mar 4 08:59:03 2009
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.synapse.commons.util.secret;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class SecretLoadingModule {
+
+ private final List<SecretCallbackHandler> secretCallbackHandlers =
+ new ArrayList<SecretCallbackHandler>();
+
+ public void init(SecretCallbackHandler[] secretCallbackHandlers) {
+ for (SecretCallbackHandler secretCallbackHandler : secretCallbackHandlers) {
+ if (secretCallbackHandler != null) {
+ this.secretCallbackHandlers.add(secretCallbackHandler);
+ }
+ }
+ }
+
+ public void load(SecretCallback[] secretCallbacks) {
+ for (SecretCallbackHandler secretCallbackHandler : secretCallbackHandlers) {
+ if (secretCallbackHandler != null) {
+ secretCallbackHandler.handle(secretCallbacks);
+ }
+ }
+ }
+}
Added: synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SingleSecretCallback.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SingleSecretCallback.java?rev=749945&view=auto
==============================================================================
--- synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SingleSecretCallback.java (added)
+++ synapse/trunk/java/modules/utils/src/main/java/org/apache/synapse/commons/util/secret/SingleSecretCallback.java Wed Mar 4 08:59:03 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.synapse.commons.util.secret;
+
+/**
+ *
+ */
+public class SingleSecretCallback implements SecretCallback {
+
+ private String secret;
+ private String prompt;
+
+ public void setSecret(String secret) {
+ this.secret = secret;
+ }
+
+ public String getSecret() {
+ return this.secret;
+ }
+
+ public String getPrompt() {
+ return prompt;
+ }
+
+ public void setPrompt(String prompt) {
+ this.prompt = prompt;
+ }
+}
Modified: synapse/trunk/java/repository/conf/synapse.properties
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/synapse.properties?rev=749945&r1=749944&r2=749945&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/synapse.properties (original)
+++ synapse/trunk/java/repository/conf/synapse.properties Wed Mar 4 08:59:03 2009
@@ -56,6 +56,7 @@
#synapse.datasources.lookupds.url=jdbc:derby://localhost:1527/lookupdb;create=false
#synapse.datasources.lookupds.username=synapse
#synapse.datasources.lookupds.password=synapse
+##synapse.datasources.lookupds.passwordProvider=org.apache.synapse.commons.util.secret.SecretCallbackHandler implementation
#synapse.datasources.lookupds.dsName=lookupdb
#synapse.datasources.lookupds.maxActive=100
#synapse.datasources.lookupds.maxIdle=20
@@ -71,6 +72,7 @@
#synapse.datasources.reportds.url=jdbc:derby://localhost:1527/reportdb;create=false
#synapse.datasources.reportds.username=synapse
#synapse.datasources.reportds.password=synapse
+##synapse.datasources.reportds.passwordProvider=org.apache.synapse.commons.util.secret.SecretCallbackHandler implementation
#synapse.datasources.reportds.maxActive=100
#synapse.datasources.reportds.maxIdle=20
#synapse.datasources.reportds.maxWait=10000