/** * Constructor accepting the {@link CacheManager} and the {@link TerracottaClientConfiguration} * * @param cacheManager the cache manager to be clustered * @param terracottaClientConfiguration the configuration for the terracotta client */ public TerracottaClient(CacheManager cacheManager, TerracottaClientConfiguration terracottaClientConfiguration) { this.cacheManager = cacheManager; this.terracottaClientConfiguration = terracottaClientConfiguration; if (terracottaClientConfiguration != null) { terracottaClientConfiguration.freezeConfig(); // If we're going clustered and secured and a secret provider is configured, it's time to wrap the // secret provider before the L1 can use it. // We must set this ehcache secret provider as both the L1 and the agent will use a different instance // and will want to fetch the password. In case of a console fetcher, the password would be asked twice. String secretProviderClassname = System.getProperty(CUSTOM_SECRET_PROVIDER_SYSTEM_PROPERTY); String tcUrl = terracottaClientConfiguration.getUrl(); if (tcUrl != null && tcUrl.contains("@") && secretProviderClassname != null) { try { System.setProperty(CUSTOM_SECRET_PROVIDER_SYSTEM_PROPERTY, CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME); Class<?> secretProviderWrapperClass = Class.forName(CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME); secretProviderWrapperClass.getMethod("useAsDelegate", String.class).invoke(secretProviderWrapperClass, secretProviderClassname); } catch (Exception e) { throw new CacheException("Unable to initialize " + CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME, e); } } } }
private ManagementRESTServiceConfiguration getDefaultClusteredManagementRESTServiceConfiguration(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService; managementRESTService = new ManagementRESTServiceConfiguration(); String url = configuration.getTerracottaConfiguration().getUrl(); if (url != null && url.contains("@")) { managementRESTService.setSslEnabled(true); } managementRESTService.setEnabled(true); managementRESTService.setBind(ManagementRESTServiceConfiguration.NO_BIND); managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); return managementRESTService; }
private void assertManagementRESTServiceConfigurationIsCorrect(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService = configuration.getManagementRESTService(); if (managementRESTService == null || !managementRESTService.isEnabled()) { return; } String url = configuration.getTerracottaConfiguration() != null ? configuration.getTerracottaConfiguration().getUrl() : null; boolean connectingToSecureCluster = url != null && url.contains("@"); if (connectingToSecureCluster && !managementRESTService.isSslEnabled()) { throw new InvalidConfigurationException("The REST agent cannot be bound to a port when SSL is disabled and" + " connecting to a secure cluster. Change your configuration to" + " <ManagementRESTServiceConfiguration sslEnabled=\"true\" .../>" + " or remove the ManagementRESTServiceConfiguration element."); } if (connectingToSecureCluster && managementRESTService.getSecurityServiceLocation() == null) { managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); LOG.warn("The REST agent must have a non-null Security Service Location when SSL is enabled." + " Using ManagementRESTServiceConfiguration.AUTO_LOCATION as a connection to a secure cluster" + " is configured."); } if (managementRESTService.isSslEnabled() && managementRESTService.getSecurityServiceLocation() == null) { throw new InvalidConfigurationException("The REST agent must have a non-null Security Service Location when" + " SSL is enabled. Change your configuration to" + " <ManagementRESTServiceConfiguration securityServiceLocation=\"...\" .../>."); } }
private void init() { if (tcConfigConfiguration == null) { return; } if (tcConfigConfiguration.getUrl() != null) { addAttribute(new SimpleNodeAttribute("url", tcConfigConfiguration.getUrl()).optional(true)); } addAttribute(new SimpleNodeAttribute("rejoin", tcConfigConfiguration.isRejoin()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_REJOIN_VALUE)); addAttribute(new SimpleNodeAttribute("wanEnabledTSA", tcConfigConfiguration.isWanEnabledTSA()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_WAN_ENABLED_TSA_VALUE)); if (tcConfigConfiguration.getOriginalEmbeddedConfig() != null) { addChildElement(new TCConfigElement(this, tcConfigConfiguration.getOriginalEmbeddedConfig())); } }
public static EhcacheTcConfig create(TerracottaClientConfiguration config) { if (config.isUrlConfig()) { String urlOrFilePath = config.getUrl(); if (isFile(urlOrFilePath)) { return new EhcacheTcConfig(Type.FILE, slurpFile(urlOrFilePath)); } else if (isValidURL(urlOrFilePath)) { return new EhcacheTcConfig(Type.EMBEDDED_TC_CONFIG, fetchConfigFromURL(urlOrFilePath)); } else { return new EhcacheTcConfig(Type.URL, urlOrFilePath); } } else { return new EhcacheTcConfig(Type.EMBEDDED_TC_CONFIG, config.getEmbeddedConfig()); } }
/** * Constructor accepting the {@link CacheManager} and the {@link TerracottaClientConfiguration} * * @param cacheManager the cache manager to be clustered * @param terracottaClientConfiguration the configuration for the terracotta client */ public TerracottaClient(CacheManager cacheManager, TerracottaClientConfiguration terracottaClientConfiguration) { this.cacheManager = cacheManager; this.terracottaClientConfiguration = terracottaClientConfiguration; if (terracottaClientConfiguration != null) { terracottaClientConfiguration.freezeConfig(); // If we're going clustered and secured and a secret provider is configured, it's time to wrap the // secret provider before the L1 can use it. // We must set this ehcache secret provider as both the L1 and the agent will use a different instance // and will want to fetch the password. In case of a console fetcher, the password would be asked twice. String secretProviderClassname = System.getProperty(CUSTOM_SECRET_PROVIDER_SYSTEM_PROPERTY); String tcUrl = terracottaClientConfiguration.getUrl(); if (tcUrl != null && tcUrl.contains("@") && secretProviderClassname != null) { try { System.setProperty(CUSTOM_SECRET_PROVIDER_SYSTEM_PROPERTY, CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME); Class<?> secretProviderWrapperClass = Class.forName(CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME); secretProviderWrapperClass.getMethod("useAsDelegate", String.class).invoke(secretProviderWrapperClass, secretProviderClassname); } catch (Exception e) { throw new CacheException("Unable to initialize " + CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME, e); } } } }
/** * Constructor accepting the {@link CacheManager} and the {@link TerracottaClientConfiguration} * * @param cacheManager the cache manager to be clustered * @param terracottaClientConfiguration the configuration for the terracotta client */ public TerracottaClient(CacheManager cacheManager, TerracottaClientConfiguration terracottaClientConfiguration) { this.cacheManager = cacheManager; this.terracottaClientConfiguration = terracottaClientConfiguration; if (terracottaClientConfiguration != null) { terracottaClientConfiguration.freezeConfig(); // If we're going clustered and secured and a secret provider is configured, it's time to wrap the // secret provider before the L1 can use it. // We must set this ehcache secret provider as both the L1 and the agent will use a different instance // and will want to fetch the password. In case of a console fetcher, the password would be asked twice. String secretProviderClassname = System.getProperty(CUSTOM_SECRET_PROVIDER_SYSTEM_PROPERTY); String tcUrl = terracottaClientConfiguration.getUrl(); if (tcUrl != null && tcUrl.contains("@") && secretProviderClassname != null) { try { System.setProperty(CUSTOM_SECRET_PROVIDER_SYSTEM_PROPERTY, CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME); Class<?> secretProviderWrapperClass = Class.forName(CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME); secretProviderWrapperClass.getMethod("useAsDelegate", String.class).invoke(secretProviderWrapperClass, secretProviderClassname); } catch (Exception e) { throw new CacheException("Unable to initialize " + CUSTOM_SECRET_PROVIDER_WRAPPER_CLASSNAME, e); } } } }
private ManagementRESTServiceConfiguration getDefaultClusteredManagementRESTServiceConfiguration(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService; managementRESTService = new ManagementRESTServiceConfiguration(); String url = configuration.getTerracottaConfiguration().getUrl(); if (url != null && url.contains("@")) { managementRESTService.setSslEnabled(true); } managementRESTService.setEnabled(true); managementRESTService.setBind(ManagementRESTServiceConfiguration.NO_BIND); managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); return managementRESTService; }
private ManagementRESTServiceConfiguration getDefaultClusteredManagementRESTServiceConfiguration(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService; managementRESTService = new ManagementRESTServiceConfiguration(); String url = configuration.getTerracottaConfiguration().getUrl(); if (url != null && url.contains("@")) { managementRESTService.setSslEnabled(true); } managementRESTService.setEnabled(true); managementRESTService.setBind(ManagementRESTServiceConfiguration.NO_BIND); managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); return managementRESTService; }
private void init() { if (tcConfigConfiguration == null) { return; } if (tcConfigConfiguration.getUrl() != null) { addAttribute(new SimpleNodeAttribute("url", tcConfigConfiguration.getUrl()).optional(true)); } addAttribute(new SimpleNodeAttribute("rejoin", tcConfigConfiguration.isRejoin()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_REJOIN_VALUE)); if (tcConfigConfiguration.getOriginalEmbeddedConfig() != null) { addChildElement(new TCConfigElement(this, tcConfigConfiguration.getOriginalEmbeddedConfig())); } }
private void assertManagementRESTServiceConfigurationIsCorrect(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService = configuration.getManagementRESTService(); if (managementRESTService == null || !managementRESTService.isEnabled()) { return; } String url = configuration.getTerracottaConfiguration() != null ? configuration.getTerracottaConfiguration().getUrl() : null; boolean connectingToSecureCluster = url != null && url.contains("@"); if (connectingToSecureCluster && !managementRESTService.isSslEnabled()) { throw new InvalidConfigurationException("The REST agent cannot be bound to a port when SSL is disabled and" + " connecting to a secure cluster. Change your configuration to" + " <ManagementRESTServiceConfiguration sslEnabled=\"true\" .../>" + " or remove the ManagementRESTServiceConfiguration element."); } if (connectingToSecureCluster && managementRESTService.getSecurityServiceLocation() == null) { managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); LOG.warn("The REST agent must have a non-null Security Service Location when SSL is enabled." + " Using ManagementRESTServiceConfiguration.AUTO_LOCATION as a connection to a secure cluster" + " is configured."); } if (managementRESTService.isSslEnabled() && managementRESTService.getSecurityServiceLocation() == null) { throw new InvalidConfigurationException("The REST agent must have a non-null Security Service Location when" + " SSL is enabled. Change your configuration to" + " <ManagementRESTServiceConfiguration securityServiceLocation=\"...\" .../>."); } }
private void assertManagementRESTServiceConfigurationIsCorrect(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService = configuration.getManagementRESTService(); if (managementRESTService == null || !managementRESTService.isEnabled()) { return; } String url = configuration.getTerracottaConfiguration() != null ? configuration.getTerracottaConfiguration().getUrl() : null; boolean connectingToSecureCluster = url != null && url.contains("@"); if (connectingToSecureCluster && !managementRESTService.isSslEnabled()) { throw new InvalidConfigurationException("The REST agent cannot be bound to a port when SSL is disabled and" + " connecting to a secure cluster. Change your configuration to" + " <ManagementRESTServiceConfiguration sslEnabled=\"true\" .../>" + " or remove the ManagementRESTServiceConfiguration element."); } if (connectingToSecureCluster && managementRESTService.getSecurityServiceLocation() == null) { managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); LOG.warn("The REST agent must have a non-null Security Service Location when SSL is enabled." + " Using ManagementRESTServiceConfiguration.AUTO_LOCATION as a connection to a secure cluster" + " is configured."); } if (managementRESTService.isSslEnabled() && managementRESTService.getSecurityServiceLocation() == null) { throw new InvalidConfigurationException("The REST agent must have a non-null Security Service Location when" + " SSL is enabled. Change your configuration to" + " <ManagementRESTServiceConfiguration securityServiceLocation=\"...\" .../>."); } }
private void init() { if (tcConfigConfiguration == null) { return; } if (tcConfigConfiguration.getUrl() != null) { addAttribute(new SimpleNodeAttribute("url", tcConfigConfiguration.getUrl()).optional(true)); } addAttribute(new SimpleNodeAttribute("rejoin", tcConfigConfiguration.isRejoin()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_REJOIN_VALUE)); addAttribute(new SimpleNodeAttribute("wanEnabledTSA", tcConfigConfiguration.isWanEnabledTSA()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_WAN_ENABLED_TSA_VALUE)); if (tcConfigConfiguration.getOriginalEmbeddedConfig() != null) { addChildElement(new TCConfigElement(this, tcConfigConfiguration.getOriginalEmbeddedConfig())); } }
private void init() { if (tcConfigConfiguration == null) { return; } if (tcConfigConfiguration.getUrl() != null) { addAttribute(new SimpleNodeAttribute("url", tcConfigConfiguration.getUrl()).optional(true)); } addAttribute(new SimpleNodeAttribute("rejoin", tcConfigConfiguration.isRejoin()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_REJOIN_VALUE)); addAttribute(new SimpleNodeAttribute("wanEnabledTSA", tcConfigConfiguration.isWanEnabledTSA()).optional(true).defaultValue( TerracottaClientConfiguration.DEFAULT_WAN_ENABLED_TSA_VALUE)); if (tcConfigConfiguration.getOriginalEmbeddedConfig() != null) { addChildElement(new TCConfigElement(this, tcConfigConfiguration.getOriginalEmbeddedConfig())); } }