use of org.jumpmind.security.ISecurityService in project symmetric-ds by JumpMind.
the class SymmetricAdmin method obfuscateText.
private void obfuscateText(CommandLine line, List<String> args) {
String plainText = popArg(args, "Text");
ISecurityService service = getSymmetricEngine().getSecurityService();
System.out.println(SecurityConstants.PREFIX_OBF + service.obfuscate(plainText));
}
use of org.jumpmind.security.ISecurityService in project symmetric-ds by JumpMind.
the class SymmetricAdmin method encryptText.
private void encryptText(CommandLine line, List<String> args) {
String plainText = popArg(args, "Text");
ISecurityService service = getSymmetricEngine().getSecurityService();
System.out.println(SecurityConstants.PREFIX_ENC + service.encrypt(plainText));
}
use of org.jumpmind.security.ISecurityService in project symmetric-ds by JumpMind.
the class SymmetricEngineHolder method install.
public ISymmetricEngine install(Properties passedInProperties) throws Exception {
TypedProperties properties = new TypedProperties(passedInProperties);
String password = properties.getProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD);
if (StringUtils.isNotBlank(password) && !password.startsWith(SecurityConstants.PREFIX_ENC)) {
try {
ISecurityService service = SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties);
properties.setProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD, SecurityConstants.PREFIX_ENC + service.encrypt(password));
} catch (Exception ex) {
log.warn("Could not encrypt password", ex);
}
}
String engineName = validateRequiredProperties(properties);
passedInProperties.setProperty(ParameterConstants.ENGINE_NAME, engineName);
if (engines.get(engineName) != null) {
try {
engines.get(engineName).stop();
} catch (Exception e) {
log.error("", e);
}
engines.remove(engineName);
}
File enginesDir = new File(AbstractCommandLauncher.getEnginesDir());
File symmetricProperties = new File(enginesDir, engineName + ".properties");
FileOutputStream fileOs = null;
try {
fileOs = new FileOutputStream(symmetricProperties);
properties.store(fileOs, "Updated by SymmetricDS Pro");
} catch (IOException ex) {
throw new RuntimeException("Failed to write symmetric.properties to engine directory", ex);
} finally {
IOUtils.closeQuietly(fileOs);
}
ISymmetricEngine engine = null;
try {
String registrationUrl = properties.getProperty(ParameterConstants.REGISTRATION_URL);
if (StringUtils.isNotBlank(registrationUrl)) {
Collection<ServerSymmetricEngine> all = getEngines().values();
for (ISymmetricEngine currentEngine : all) {
if (currentEngine.getParameterService().getSyncUrl().equals(registrationUrl)) {
String serverNodeGroupId = currentEngine.getParameterService().getNodeGroupId();
String clientNodeGroupId = properties.getProperty(ParameterConstants.NODE_GROUP_ID);
String externalId = properties.getProperty(ParameterConstants.EXTERNAL_ID);
IConfigurationService configurationService = currentEngine.getConfigurationService();
ITriggerRouterService triggerRouterService = currentEngine.getTriggerRouterService();
List<NodeGroup> groups = configurationService.getNodeGroups();
boolean foundGroup = false;
for (NodeGroup nodeGroup : groups) {
if (nodeGroup.getNodeGroupId().equals(clientNodeGroupId)) {
foundGroup = true;
}
}
if (!foundGroup) {
configurationService.saveNodeGroup(new NodeGroup(clientNodeGroupId));
}
boolean foundLink = false;
List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(serverNodeGroupId, false);
for (NodeGroupLink nodeGroupLink : links) {
if (nodeGroupLink.getTargetNodeGroupId().equals(clientNodeGroupId)) {
foundLink = true;
}
}
if (!foundLink) {
configurationService.saveNodeGroupLink(new NodeGroupLink(serverNodeGroupId, clientNodeGroupId, NodeGroupLinkAction.W));
triggerRouterService.syncTriggers();
}
IRegistrationService registrationService = currentEngine.getRegistrationService();
if (!registrationService.isAutoRegistration() && !registrationService.isRegistrationOpen(clientNodeGroupId, externalId)) {
Node node = new Node(properties);
registrationService.openRegistration(node);
}
}
}
}
engine = create(symmetricProperties.getAbsolutePath());
if (engine != null) {
engineCount++;
engine.start();
} else {
FileUtils.deleteQuietly(symmetricProperties);
log.warn("The engine could not be created. It will not be started");
}
return engine;
} catch (RuntimeException ex) {
if (engine != null) {
engine.destroy();
}
FileUtils.deleteQuietly(symmetricProperties);
throw ex;
}
}
use of org.jumpmind.security.ISecurityService in project symmetric-ds by JumpMind.
the class SymmetricWebServer method getConnectors.
protected Connector[] getConnectors(Server server, int port, int securePort, Mode mode) {
ArrayList<Connector> connectors = new ArrayList<Connector>();
String keyStoreFile = System.getProperty(SecurityConstants.SYSPROP_KEYSTORE);
String keyStoreType = System.getProperty(SecurityConstants.SYSPROP_KEYSTORE_TYPE, SecurityConstants.KEYSTORE_TYPE);
HttpConfiguration httpConfig = new HttpConfiguration();
if (mode.equals(Mode.HTTPS) || mode.equals(Mode.MIXED)) {
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(securePort);
}
httpConfig.setOutputBufferSize(32768);
if (mode.equals(Mode.HTTP) || mode.equals(Mode.MIXED)) {
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
http.setPort(port);
http.setHost(host);
http.setIdleTimeout(maxIdleTime);
connectors.add(http);
log.info(String.format("About to start %s web server on host:port %s:%s", name, host == null ? "default" : host, port));
}
if (mode.equals(Mode.HTTPS) || mode.equals(Mode.MIXED)) {
ISecurityService securityService = SecurityServiceFactory.create(SecurityServiceType.SERVER, new TypedProperties(System.getProperties()));
securityService.installDefaultSslCert(host);
String keyStorePassword = System.getProperty(SecurityConstants.SYSPROP_KEYSTORE_PASSWORD);
keyStorePassword = (keyStorePassword != null) ? keyStorePassword : SecurityConstants.KEYSTORE_PASSWORD;
SslContextFactory sslConnectorFactory = new SslContextFactory();
sslConnectorFactory.setKeyStorePath(keyStoreFile);
sslConnectorFactory.setKeyManagerPassword(keyStorePassword);
/* Prevent POODLE attack */
sslConnectorFactory.addExcludeProtocols("SSLv3");
sslConnectorFactory.setCertAlias(System.getProperty(SecurityConstants.SYSPROP_KEYSTORE_CERT_ALIAS, SecurityConstants.ALIAS_SYM_PRIVATE_KEY));
sslConnectorFactory.setKeyStoreType(keyStoreType);
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslConnectorFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
https.setPort(securePort);
https.setIdleTimeout(maxIdleTime);
https.setHost(host);
connectors.add(https);
log.info(String.format("About to start %s web server on secure host:port %s:%s", name, host == null ? "default" : host, securePort));
}
return connectors.toArray(new Connector[connectors.size()]);
}
Aggregations