Skip to content

Commit

Permalink
dev checkin. move security service. added basicdatasourcefactory for …
Browse files Browse the repository at this point in the history
…reuse.
  • Loading branch information
chenson42 committed Dec 18, 2012
1 parent 41e9a27 commit 3eda5f7
Show file tree
Hide file tree
Showing 38 changed files with 438 additions and 260 deletions.
2 changes: 1 addition & 1 deletion symmetric-assemble/src/docbook/advanced-topics.xml
Expand Up @@ -805,7 +805,7 @@ net stop symmetricds</programlisting>
<filename class="directory">web/WEB-INF/lib</filename> folders.
Then, in the <filename class="filename">symmetric.properties</filename> specify your class name for the security service.

<programlisting>security.service.class.name=org.jumpmind.symmetric.service.impl.SecurityService</programlisting>
<programlisting>security.service.class.name=org.jumpmind.security.SecurityService</programlisting>

Remember to specify your properties file when encrypting passwords, so it will use your custom ISecurityService.

Expand Down
Expand Up @@ -51,6 +51,7 @@
import org.apache.log4j.xml.DOMConfigurator;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.properties.TypedProperties;
import org.jumpmind.security.SecurityConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.SystemConstants;
import org.slf4j.Logger;
Expand Down Expand Up @@ -287,7 +288,7 @@ public File findSingleEnginesPropertiesFile() {

protected void configureCrypto(CommandLine line) throws Exception {
if (line.hasOption(OPTION_KEYSTORE_PASSWORD)) {
System.setProperty(SystemConstants.SYSPROP_KEYSTORE_PASSWORD,
System.setProperty(SecurityConstants.SYSPROP_KEYSTORE_PASSWORD,
line.getOptionValue(OPTION_KEYSTORE_PASSWORD));
}

Expand Down
Expand Up @@ -28,12 +28,11 @@
import org.jumpmind.db.platform.JdbcDatabasePlatformFactory;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.db.sql.SqlTemplateSettings;
import org.jumpmind.db.util.ResettableBasicDataSource;
import org.jumpmind.db.util.BasicDataSourceFactory;
import org.jumpmind.exception.IoException;
import org.jumpmind.properties.TypedProperties;
import org.jumpmind.symmetric.DbExport.Format;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.SecurityConstants;
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.db.JdbcSymmetricDialectFactory;
Expand All @@ -44,10 +43,8 @@
import org.jumpmind.symmetric.job.IJobManager;
import org.jumpmind.symmetric.job.JobManager;
import org.jumpmind.symmetric.model.TriggerHistory;
import org.jumpmind.symmetric.service.ISecurityService;
import org.jumpmind.util.AppUtils;
import org.jumpmind.util.JarBuilder;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
Expand Down Expand Up @@ -187,55 +184,7 @@ public synchronized void stop() {

public static BasicDataSource createBasicDataSource(File propsFile) {
TypedProperties properties = createTypedPropertiesFactory(propsFile, null).reload();
return createBasicDataSource(properties, createSecurityService(properties));
}

public static BasicDataSource createBasicDataSource(TypedProperties properties,
ISecurityService securityService) {
ResettableBasicDataSource dataSource = new ResettableBasicDataSource();
dataSource.setDriverClassName(properties.get(ParameterConstants.DB_POOL_DRIVER, null));
dataSource.setUrl(properties.get(ParameterConstants.DB_POOL_URL, null));
String user = properties.get(ParameterConstants.DB_POOL_USER, "");
if (user != null && user.startsWith(SecurityConstants.PREFIX_ENC)) {
user = securityService.decrypt(user.substring(SecurityConstants.PREFIX_ENC.length()));
}
dataSource.setUsername(user);

String password = properties.get(ParameterConstants.DB_POOL_PASSWORD, "");
if (password != null && password.startsWith(SecurityConstants.PREFIX_ENC)) {
password = securityService.decrypt(password.substring(SecurityConstants.PREFIX_ENC
.length()));
}
dataSource.setPassword(password);
dataSource.setInitialSize(properties.getInt(ParameterConstants.DB_POOL_INITIAL_SIZE, 5));
dataSource.setMaxActive(properties.getInt(ParameterConstants.DB_POOL_MAX_ACTIVE, 20));
dataSource.setMaxWait(properties.getInt(ParameterConstants.DB_POOL_MAX_WAIT, 5000));
dataSource.setMinEvictableIdleTimeMillis(properties.getInt(
ParameterConstants.DB_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS, 60000));
dataSource.setTimeBetweenEvictionRunsMillis(120000);
dataSource.setNumTestsPerEvictionRun(10);
dataSource.setValidationQuery(properties.get(ParameterConstants.DB_POOL_VALIDATION_QUERY,
null));
dataSource.setTestOnBorrow(properties.is(ParameterConstants.DB_POOL_TEST_ON_BORROW, true));
dataSource.setTestOnReturn(properties.is(ParameterConstants.DB_POOL_TEST_ON_RETURN, false));
dataSource.setTestWhileIdle(properties
.is(ParameterConstants.DB_POOL_TEST_WHILE_IDLE, false));

String connectionProperties = properties.get(
ParameterConstants.DB_POOL_CONNECTION_PROPERTIES, null);
if (StringUtils.isNotBlank(connectionProperties)) {
String[] tokens = connectionProperties.split(";");
for (String property : tokens) {
String[] keyValue = property.split("=");
if (keyValue != null && keyValue.length > 1) {
LoggerFactory.getLogger(ClientSymmetricEngine.class).info(
"Setting database connection property %s=%s", keyValue[0], keyValue[1]);
dataSource.addConnectionProperty(keyValue[0], keyValue[1]);
}
}
}
return dataSource;

return BasicDataSourceFactory.create(properties, createSecurityService(properties));
}

@Override
Expand All @@ -252,7 +201,7 @@ protected IDatabasePlatform createDatabasePlatform(TypedProperties properties) {
public static IDatabasePlatform createDatabasePlatform(TypedProperties properties,
BasicDataSource dataSource, boolean waitOnAvailableDatabase) {
if (dataSource == null) {
dataSource = createBasicDataSource(properties, createSecurityService(properties));
dataSource = BasicDataSourceFactory.create(properties, createSecurityService(properties));
}
if (waitOnAvailableDatabase) {
waitForAvailableDatabase(dataSource);
Expand Down
Expand Up @@ -43,14 +43,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.h2.util.StringUtils;
import org.jumpmind.symmetric.common.SecurityConstants;
import org.jumpmind.security.ISecurityService;
import org.jumpmind.security.SecurityConstants;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.service.IDataExtractorService;
import org.jumpmind.symmetric.service.IDataLoaderService;
import org.jumpmind.symmetric.service.IDataService;
import org.jumpmind.symmetric.service.IPurgeService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.service.ISecurityService;
import org.jumpmind.symmetric.service.ITriggerRouterService;
import org.jumpmind.util.JarBuilder;

Expand Down
Expand Up @@ -35,9 +35,9 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.extension.IBuiltInExtensionPoint;
import org.jumpmind.security.SecurityConstants;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.SecurityConstants;
import org.jumpmind.symmetric.ext.ISymmetricEngineAware;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.transport.ConcurrentConnectionManager.NodeConnectionStatistics;
Expand Down
Expand Up @@ -42,6 +42,8 @@
import org.jumpmind.db.sql.SqlScript;
import org.jumpmind.db.sql.SqlScriptReader;
import org.jumpmind.properties.TypedProperties;
import org.jumpmind.security.ISecurityService;
import org.jumpmind.security.SecurityService;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TableConstants;
Expand Down Expand Up @@ -76,7 +78,6 @@
import org.jumpmind.symmetric.service.IPushService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.service.IRouterService;
import org.jumpmind.symmetric.service.ISecurityService;
import org.jumpmind.symmetric.service.ISequenceService;
import org.jumpmind.symmetric.service.IStatisticService;
import org.jumpmind.symmetric.service.ITransformService;
Expand All @@ -100,7 +101,6 @@
import org.jumpmind.symmetric.service.impl.PushService;
import org.jumpmind.symmetric.service.impl.RegistrationService;
import org.jumpmind.symmetric.service.impl.RouterService;
import org.jumpmind.symmetric.service.impl.SecurityService;
import org.jumpmind.symmetric.service.impl.SequenceService;
import org.jumpmind.symmetric.service.impl.StatisticService;
import org.jumpmind.symmetric.service.impl.TransformService;
Expand Down Expand Up @@ -635,6 +635,16 @@ public void forceTriggerRebuild() {
public NodeStatus getNodeStatus() {
return nodeService.getNodeStatus();
}

public void removeAndCleanupNode(String nodeId) {
log.warn("Removing node {}", nodeId);
nodeService.deleteNode(nodeId);
log.warn("Marking outgoing batch records as Ok for {}", nodeId);
outgoingBatchService.markAllAsSentForNode(nodeId);
log.warn("Marking incoming batch records as Ok for {}", nodeId);
incomingBatchService.markIncomingBatchesOk(nodeId);
log.warn("Done removing node {}", nodeId);
}

public RemoteNodeStatuses pull() {
MDC.put("engineName", getEngineName());
Expand Down
Expand Up @@ -26,6 +26,7 @@

import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.security.ISecurityService;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.ext.IExtensionPointManager;
import org.jumpmind.symmetric.io.stage.IStagingManager;
Expand All @@ -50,7 +51,6 @@
import org.jumpmind.symmetric.service.IPushService;
import org.jumpmind.symmetric.service.IRegistrationService;
import org.jumpmind.symmetric.service.IRouterService;
import org.jumpmind.symmetric.service.ISecurityService;
import org.jumpmind.symmetric.service.ISequenceService;
import org.jumpmind.symmetric.service.IStatisticService;
import org.jumpmind.symmetric.service.ITransformService;
Expand Down Expand Up @@ -210,6 +210,8 @@ public interface ISymmetricEngine {
* @param force forces this action to be run regardless of the parameter settings
*/
public void setupDatabase(boolean force);

public void removeAndCleanupNode(String nodeId);

public IConfigurationService getConfigurationService();

Expand Down
Expand Up @@ -160,20 +160,6 @@ private ParameterConstants() {
public final static String CACHE_TIMEOUT_TABLES_IN_MS = "cache.table.time.ms";

public final static String TRIGGER_UPDATE_CAPTURE_CHANGED_DATA_ONLY = "trigger.update.capture.changed.data.only.enabled";

public final static String DB_POOL_URL = "db.url";
public final static String DB_POOL_DRIVER = "db.driver";
public final static String DB_POOL_USER = "db.user";
public final static String DB_POOL_PASSWORD = "db.password";
public final static String DB_POOL_INITIAL_SIZE = "db.pool.initial.size";
public final static String DB_POOL_MAX_ACTIVE = "db.pool.max.active";
public final static String DB_POOL_MAX_WAIT = "db.pool.max.wait.millis";
public final static String DB_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS = "db.pool.min.evictable.idle.millis";
public final static String DB_POOL_VALIDATION_QUERY = "db.validation.query";
public final static String DB_POOL_TEST_ON_BORROW = "db.test.on.borrow";
public final static String DB_POOL_TEST_ON_RETURN = "db.test.on.return";
public final static String DB_POOL_TEST_WHILE_IDLE = "db.test.while.idle";
public final static String DB_POOL_CONNECTION_PROPERTIES = "db.connection.properties";

public final static String DB_METADATA_IGNORE_CASE = "db.metadata.ignore.case";
public final static String DB_NATIVE_EXTRACTOR = "db.native.extractor";
Expand Down
Expand Up @@ -33,9 +33,7 @@ public class SystemConstants {
public static final String SYSPROP_WEB_DIR = "symmetric.default.web.dir";
public static final String SYSPROP_DEFAULT_HTTP_PORT = "symmetric.default.http.port";
public static final String SYSPROP_DEFAULT_HTTPS_PORT = "symmetric.default.https.port";
public static final String SYSPROP_KEYSTORE = "sym.keystore.file";
public static final String SYSPROP_KEYSTORE_TYPE = "sym.keystore.type";
public static final String SYSPROP_KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword";
public static final String SYSPROP_KEYSTORE_CERT_ALIAS = "sym.keystore.ssl.cert.alias";

}
Expand Down
Expand Up @@ -59,7 +59,7 @@ public void clientNodeOffline(Node node) {
statisticManager.incrementNodesDisabled(1);
node.setSyncEnabled(false);
nodeService.save(node);
outgoingBatchService.markAllAsSentForNode(node);
outgoingBatchService.markAllAsSentForNode(node.getNodeId());
nodeService.deleteNodeSecurity(node.getNodeId());
}

Expand Down
Expand Up @@ -24,7 +24,6 @@
import java.util.List;

import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.OutgoingBatch;
import org.jumpmind.symmetric.model.OutgoingBatchSummary;
import org.jumpmind.symmetric.model.OutgoingBatches;
Expand All @@ -34,13 +33,13 @@
*/
public interface IOutgoingBatchService {

public void markAllAsSentForNode(Node node);
public void markAllAsSentForNode(String nodeId);

public void updateAbandonedRoutingBatches();

public OutgoingBatch findOutgoingBatch(long batchId, String nodeId);

public OutgoingBatches getOutgoingBatches(Node node, boolean includeDisabledChannels);
public OutgoingBatches getOutgoingBatches(String nodeId, boolean includeDisabledChannels);

public OutgoingBatches getOutgoingBatchRange(String startBatchId, String endBatchId);

Expand Down
Expand Up @@ -298,7 +298,7 @@ public List<OutgoingBatch> extract(Node targetNode, IOutgoingTransport targetTra
routerService.routeData(true);
}

OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(targetNode, false);
OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(targetNode.getNodeId(), false);

if (batches.containsBatches()) {

Expand Down
Expand Up @@ -137,7 +137,7 @@ public void insertReloadEvents(Node targetNode, boolean reverse) {
/*
* Outgoing data events are pointless because we are reloading all data
*/
engine.getOutgoingBatchService().markAllAsSentForNode(targetNode);
engine.getOutgoingBatchService().markAllAsSentForNode(targetNode.getNodeId());

Node sourceNode = engine.getNodeService().findIdentity();

Expand Down
Expand Up @@ -223,6 +223,7 @@ public void deleteNode(String nodeId) {
if (nodeId.equals(findIdentityNodeId())) {
sqlTemplate.update(getSql("deleteNodeIdentitySql"));
}
deleteNodeSecurity(nodeId);
sqlTemplate.update(getSql("deleteNodeHostSql"), new Object[] { nodeId });
sqlTemplate.update(getSql("deleteNodeSql"), new Object[] { nodeId });
}
Expand Down

0 comments on commit 3eda5f7

Please sign in to comment.