Search in sources :

Example 1 with ISecurityService

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));
}
Also used : ISecurityService(org.jumpmind.security.ISecurityService)

Example 2 with ISecurityService

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));
}
Also used : ISecurityService(org.jumpmind.security.ISecurityService)

Example 3 with ISecurityService

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;
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) IOException(java.io.IOException) TypedProperties(org.jumpmind.properties.TypedProperties) IOException(java.io.IOException) ISecurityService(org.jumpmind.security.ISecurityService) FileOutputStream(java.io.FileOutputStream) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) File(java.io.File) NodeGroup(org.jumpmind.symmetric.model.NodeGroup)

Example 4 with ISecurityService

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()]);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ISecurityService(org.jumpmind.security.ISecurityService) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) TypedProperties(org.jumpmind.properties.TypedProperties) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Aggregations

ISecurityService (org.jumpmind.security.ISecurityService)4 TypedProperties (org.jumpmind.properties.TypedProperties)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Connector (org.eclipse.jetty.server.Connector)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)1 Node (org.jumpmind.symmetric.model.Node)1 NodeGroup (org.jumpmind.symmetric.model.NodeGroup)1 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)1 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)1 IRegistrationService (org.jumpmind.symmetric.service.IRegistrationService)1 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)1