use of org.jumpmind.symmetric.model.NodeSecurity in project symmetric-ds by JumpMind.
the class NodeService method findOrCreateNodeSecurity.
public NodeSecurity findOrCreateNodeSecurity(String nodeId) {
try {
if (nodeId != null) {
NodeSecurity security = findNodeSecurity(nodeId, false);
if (security == null) {
insertNodeSecurity(nodeId);
security = findNodeSecurity(nodeId, true);
}
return security;
} else {
log.debug("A 'null' node id was passed into findNodeSecurity");
return null;
}
} catch (UniqueKeyException ex) {
log.error("Could not find a node security row for '{}'", nodeId);
throw ex;
}
}
use of org.jumpmind.symmetric.model.NodeSecurity in project symmetric-ds by JumpMind.
the class NodeService method isNodeAuthorized.
/**
* Check that the given node and password match in the node_security table.
* A node must authenticate before it's allowed to sync data.
*/
public boolean isNodeAuthorized(String nodeId, String password) {
Map<String, NodeSecurity> nodeSecurities = findAllNodeSecurity(true);
NodeSecurity nodeSecurity = nodeSecurities.get(nodeId);
if (nodeSecurity != null && !nodeId.equals(findIdentityNodeId()) && ((nodeSecurity.getNodePassword() != null && !nodeSecurity.getNodePassword().equals("") && nodeSecurity.getNodePassword().equals(password)) || nodeSecurity.isRegistrationEnabled())) {
return true;
}
return false;
}
use of org.jumpmind.symmetric.model.NodeSecurity in project symmetric-ds by JumpMind.
the class PushService method pushToNode.
private void pushToNode(Node remote, RemoteNodeStatus status) {
Node identity = nodeService.findIdentity();
NodeSecurity identitySecurity = nodeService.findNodeSecurity(identity.getNodeId(), true);
IOutgoingWithResponseTransport transport = null;
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.PUSH_JOB));
Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put(WebConstants.THREAD_CHANNEL, status.getChannelId());
try {
transport = transportManager.getPushTransport(remote, identity, identitySecurity.getNodePassword(), requestProperties, parameterService.getRegistrationUrl());
List<OutgoingBatch> extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
if (extractedBatches.size() > 0) {
log.info("Push data sent to {}", remote);
List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
status.updateOutgoingStatus(extractedBatches, batchAcks);
}
if (processInfo.getStatus() != Status.ERROR) {
processInfo.setStatus(Status.OK);
}
fireOnline(remote, status);
} catch (Exception ex) {
processInfo.setStatus(Status.ERROR);
fireOffline(ex, remote, status);
} finally {
try {
transport.close();
} catch (Exception e) {
}
}
}
use of org.jumpmind.symmetric.model.NodeSecurity in project symmetric-ds by JumpMind.
the class OutgoingBatchService method areAllLoadBatchesComplete.
public boolean areAllLoadBatchesComplete(String nodeId) {
NodeSecurity security = nodeService.findNodeSecurity(nodeId);
if (security == null || security.isInitialLoadEnabled()) {
return false;
}
List<String> statuses = (List<String>) sqlTemplate.query(getSql("initialLoadStatusSql"), new StringMapper(), nodeId, 1);
if (statuses == null || statuses.size() == 0) {
throw new RuntimeException("The initial load has not been started for " + nodeId);
}
for (String status : statuses) {
if (!Status.OK.name().equals(status)) {
return false;
}
}
return true;
}
use of org.jumpmind.symmetric.model.NodeSecurity in project symmetric-ds by JumpMind.
the class TriggerRouterService method syncTriggers.
public void syncTriggers(StringBuilder sqlBuffer, boolean force) {
if ((parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS) || isCalledFromSymmetricAdminTool())) {
synchronized (this) {
if (clusterService.lock(ClusterConstants.SYNCTRIGGERS)) {
try {
String additionalMessage = "";
if (isCalledFromSymmetricAdminTool() && !parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
additionalMessage = " " + ParameterConstants.AUTO_SYNC_TRIGGERS + " is set to false, but the sync triggers process will run so that needed changes can be written to a file so they can be applied manually. Once all of the triggers have been successfully applied this process should not show triggers being created";
}
log.info("Synchronizing triggers{}", additionalMessage);
// make sure all tables are freshly read in
platform.resetCachedTableModel();
clearCache();
// make sure channels are read from the database
configurationService.clearCache();
List<Trigger> triggersForCurrentNode = getTriggersForCurrentNode();
boolean createTriggersForTables = false;
String nodeId = nodeService.findIdentityNodeId();
if (StringUtils.isNotBlank(nodeId)) {
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
if (nodeSecurity != null && (nodeSecurity.isInitialLoadEnabled() || nodeSecurity.getInitialLoadTime() == null)) {
createTriggersForTables = parameterService.is(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD);
if (!createTriggersForTables) {
log.info("Trigger creation has been disabled by " + ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD + " because an initial load is in progress or has not yet been requested");
}
} else {
createTriggersForTables = true;
}
}
if (!createTriggersForTables) {
triggersForCurrentNode.clear();
}
List<TriggerHistory> activeTriggerHistories = getActiveTriggerHistories();
inactivateTriggers(triggersForCurrentNode, sqlBuffer, activeTriggerHistories);
updateOrCreateDatabaseTriggers(triggersForCurrentNode, sqlBuffer, force, true, activeTriggerHistories, true);
resetTriggerRouterCacheByNodeGroupId();
if (createTriggersForTables) {
updateOrCreateDdlTriggers(sqlBuffer);
}
} finally {
clusterService.unlock(ClusterConstants.SYNCTRIGGERS);
log.info("Done synchronizing triggers");
}
} else {
Lock lock = clusterService.findLocks().get(ClusterConstants.SYNCTRIGGERS);
if (lock != null) {
log.info("Sync triggers was locked by the cluster service. The locking server id was: {}. The lock time was: {}", lock.getLockingServerId(), lock.getLockTime());
} else {
log.info("Sync triggers was locked by something but lock details were found");
}
}
}
} else {
log.info("Not synchronizing triggers. {} is set to false", ParameterConstants.AUTO_SYNC_TRIGGERS);
}
}
Aggregations