public static String getOptionalProperty(ServiceProperties properties, String propertyName, String defaultValue) { String propertyValue = properties.get(propertyName); if (propertyValue == null) { return defaultValue; } return propertyValue; }
/** * Creates the list of PatternCacheControl objects * @param properties - list of ServiceProperties from the configuration file * @return a list of PatternCacheControl objects */ private List<PatternCacheControl> buildPatternsList(ServiceProperties properties) { Map<String, PatternCacheControl> patterns = new LinkedHashMap<>(); List<ServiceProperties> locationsList = properties.getNested("location"); if (locationsList != null && locationsList.size() != 0) { for (ServiceProperties location : locationsList) { String directiveList = location.get("cache-control"); String[] patternList = location.get("patterns").split("\\s+"); for (String pattern : patternList) { patterns.put(pattern, new PatternCacheControl(pattern, directiveList)); } } resolvePatternSpecificity(patterns); return sortByMatchingPatternCount(patterns); } return new ArrayList<>(patterns.values()); }
public static String getRequiredProperty(ServiceProperties properties, String propertyName) { String propertyValue = properties.get(propertyName); if (propertyValue == null) { throw new IllegalStateException("Missing required property \"" + propertyName + "\""); } return propertyValue; }
rewriteCookieDomain = "enabled".equals(properties.get("rewrite-cookie-domain")); rewriteCookiePath = "enabled".equals(properties.get("rewrite-cookie-path")); rewriteLocation = !"disabled".equals(properties.get("rewrite-location")); List<ServiceProperties> cookieDomainProperties = properties.getNested("cookie-domain-mapping"); for (ServiceProperties sp : cookieDomainProperties) { cookieDomainMap.put(sp.get("from"), sp.get("to")); List<ServiceProperties> cookiePathProperties = properties.getNested("cookie-path-mapping"); for (ServiceProperties sp : cookiePathProperties) { cookiePathMap.put(sp.get("from"), sp.get("to")); List<ServiceProperties> locationProperties = properties.getNested("location-mapping"); for (ServiceProperties sp : locationProperties) { locationMap.put(sp.get("from"), sp.get("to")); useForwarded = properties.get("use-forwarded"); if (useForwarded == null) { useForwarded = FORWARDED_IGNORE;
private TurnRestCredentialsGenerator setUpCredentialsGenerator(ServiceProperties properties) throws ConfigurationException, InstantiationException, IllegalAccessException { TurnRestCredentialsGenerator credentialGeneratorInstance = resolveCredentialsGenerator(properties); Key sharedSecret = resolveSharedSecret(properties); String algorithm = properties.get("key.algorithm") != null ? properties.get("key.algorithm") : DEFAULT_KEY_ALGORITHM; char separator = properties.get("username.separator") != null ? properties.get("username.separator").charAt(0) : DEFAULT_USER_SEPARATOR; credentialGeneratorInstance.setAlgorithm(algorithm); credentialGeneratorInstance.setSharedSecret(sharedSecret); credentialGeneratorInstance.setUsernameSeparator(separator); return credentialGeneratorInstance; }
private static JSONObject asJSONObject(ServiceProperties properties) { JSONObject result = new JSONObject(); try { for (String name : properties.simplePropertyNames()) { result.put(name, properties.get(name)); } for (String name : properties.nestedPropertyNames()) { for (ServiceProperties nested : properties.getNested(name)) { result.append(name, asJSONObject(nested)); } } } catch (JSONException e) { // can't happen (unless ServiceProperties has a bug and incorrectly returns a null property name) throw new RuntimeException(e); } return result; } }
private TurnRestCredentialsGenerator setUpCredentialsGenerator(ServiceProperties properties) throws ConfigurationException, InstantiationException, IllegalAccessException { TurnRestCredentialsGenerator credentialGeneratorInstance = resolveCredentialsGenerator(properties); Key sharedSecret = resolveSharedSecret(properties); String algorithm = properties.get("key.algorithm") != null ? properties.get("key.algorithm") : DEFAULT_KEY_ALGORITHM; char separator = properties.get("username.separator") != null ? properties.get("username.separator").charAt(0) : DEFAULT_USER_SEPARATOR; credentialGeneratorInstance.setAlgorithm(algorithm); credentialGeneratorInstance.setSharedSecret(sharedSecret); credentialGeneratorInstance.setUsernameSeparator(separator); return credentialGeneratorInstance; }
String existingValue = properties.get(node.getLocalName()); if (existingValue == null) { properties.put(node.getLocalName(), nodeValue);
@SuppressWarnings("unchecked") private TurnRestCredentialsGenerator resolveCredentialsGenerator(ServiceProperties properties) throws ConfigurationException, InstantiationException, IllegalAccessException { String credentialGeneratorClassName = properties.get("credentials.generator"); TurnRestCredentialsGenerator credentialGeneratorInstance; if (credentialGeneratorClassName == null) { throw new ConfigurationException("No credential generator specified"); } Class<? extends TurnRestCredentialsGenerator> credentialGeneratorClass; if (!credentialGeneratorClassName.startsWith(CLASS_PREFIX)) { throw new IllegalArgumentException("Class name must have \"class:\" prefix."); } String className = credentialGeneratorClassName.substring(CLASS_PREFIX.length()); try { Class<?> clazz = Class.forName(className); if (!TurnRestCredentialsGenerator.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Invalid credential generator class: " + className); } credentialGeneratorClass = (Class<? extends TurnRestCredentialsGenerator>) clazz; credentialGeneratorInstance = credentialGeneratorClass.newInstance(); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unknown credential generator class: " + className, e); } return credentialGeneratorInstance; }
@SuppressWarnings("unchecked") private TurnRestCredentialsGenerator resolveCredentialsGenerator(ServiceProperties properties) throws ConfigurationException, InstantiationException, IllegalAccessException { String credentialGeneratorClassName = properties.get("credentials.generator"); TurnRestCredentialsGenerator credentialGeneratorInstance; if (credentialGeneratorClassName == null) { throw new ConfigurationException("No credential generator specified"); } Class<? extends TurnRestCredentialsGenerator> credentialGeneratorClass; if (!credentialGeneratorClassName.startsWith(CLASS_PREFIX)) { throw new IllegalArgumentException("Class name must have \"class:\" prefix."); } String className = credentialGeneratorClassName.substring(CLASS_PREFIX.length()); try { Class<?> clazz = Class.forName(className); if (!TurnRestCredentialsGenerator.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Invalid credential generator class: " + className); } credentialGeneratorClass = (Class<? extends TurnRestCredentialsGenerator>) clazz; credentialGeneratorInstance = credentialGeneratorClass.newInstance(); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unknown credential generator class: " + className, e); } return credentialGeneratorInstance; }
private Key resolveSharedSecret(ServiceProperties properties) { KeyStore ks = securityContext.getKeyStore(); String alias = properties.get("key.alias"); return TurnUtils.getSharedSecret(ks, alias, securityContext.getKeyStorePassword()); }
@Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; EarlyAccessFeatures.TURN_REST_SERVICE.assertEnabled(getConfiguration(), serviceContext.getLogger()); ServiceProperties properties = serviceContext.getProperties(); String urls = properties.get("url"); TurnRestCredentialsGenerator credentialGeneratorInstance = setUpCredentialsGenerator(properties); long ttl = Utils.parseTimeInterval(properties.get("credentials.ttl"), TimeUnit.SECONDS, DEFAULT_CREDENTIALS_TTL); handler = new TurnRestServiceHandler(Long.toString(ttl), credentialGeneratorInstance, urls); }
@Override public void init(ServiceContext serviceContext) throws Exception { this.serviceContext = serviceContext; EarlyAccessFeatures.TURN_REST_SERVICE.assertEnabled(getConfiguration(), serviceContext.getLogger()); ServiceProperties properties = serviceContext.getProperties(); String urls = properties.get("url"); TurnRestCredentialsGenerator credentialGeneratorInstance = setUpCredentialsGenerator(properties); long ttl = Utils.parseTimeInterval(properties.get("credentials.ttl"), TimeUnit.SECONDS, DEFAULT_CREDENTIALS_TTL); handler = new TurnRestServiceHandler(Long.toString(ttl), credentialGeneratorInstance, urls); }
private Key resolveSharedSecret(ServiceProperties properties) { KeyStore ks = securityContext.getKeyStore(); String alias = properties.get("key.alias"); return TurnUtils.getSharedSecret(ks, alias, securityContext.getKeyStorePassword()); }
@Override public void init(ServiceContext serviceContext) throws Exception { EarlyAccessFeatures.HTTP_REDIRECT.assertEnabled(configuration, serviceContext.getLogger()); this.serviceContext = serviceContext; handler = new HttpRedirectServiceHandler(logger); ServiceProperties properties = serviceContext.getProperties(); String location = properties.get("location"); if (location == null || "".equals(location)) { throw new IllegalArgumentException("Missing required property: location"); } HttpStatus statusCode; String strStatusCode = properties.get("status-code"); if (strStatusCode == null) statusCode = HttpStatus.REDIRECT_MULTIPLE_CHOICES; else statusCode = HttpStatus.getHttpStatus(strStatusCode); if (statusCode.code() > 399 || statusCode.code() < 300) { throw new IllegalArgumentException( "Wrong value for status-code:" + statusCode + ". Valid values are integers between 300 and 399"); } String cacheControlDirectives = properties.get("cache-control"); // this is null-able handler.setLocation(location); handler.setStatusCode(statusCode); handler.setCacheControl(cacheControlDirectives); }
@Override public void init(ServiceContext serviceContext) throws Exception { EarlyAccessFeatures.HTTP_REDIRECT.assertEnabled(configuration, serviceContext.getLogger()); this.serviceContext = serviceContext; handler = new HttpRedirectServiceHandler(logger); ServiceProperties properties = serviceContext.getProperties(); String location = properties.get("location"); if (location == null || "".equals(location)) { throw new IllegalArgumentException("Missing required property: location"); } HttpStatus statusCode; String strStatusCode = properties.get("status-code"); if (strStatusCode == null) statusCode = HttpStatus.REDIRECT_MULTIPLE_CHOICES; else statusCode = HttpStatus.getHttpStatus(strStatusCode); if (statusCode.code() > 399 || statusCode.code() < 300) { throw new IllegalArgumentException( "Wrong value for status-code:" + statusCode + ". Valid values are integers between 300 and 399"); } String cacheControlDirectives = properties.get("cache-control"); // this is null-able handler.setLocation(location); handler.setStatusCode(statusCode); handler.setCacheControl(cacheControlDirectives); }
String directory = properties.get("directory"); if (directory == null) { throw new IllegalArgumentException("Missing required property: directory"); String welcomeFile = properties.get("welcome-file"); if (welcomeFile != null) { String pathSeparator = File.pathSeparator; File errorPagesDir = toFile(webDir.getParentFile(), properties.get("error-pages-directory")); handler.setPatterns(buildPatternsList(properties)); String indexes = properties.get("options"); if ((indexes != null) && "indexes".equalsIgnoreCase(indexes)) { handler.setIndexes(true);
OnClientMessage onClientMessage = OnClientMessage.fromString(serviceContext.getProperties().get(ON_CLIENT_MESSAGE)); if ( maximumScheduledWriteBytes != Long.MAX_VALUE ) { String reconnectDelay = properties.get("reconnect.delay"); if ((connectURIs == null || connectURIs.isEmpty())) { throw new IllegalArgumentException("Missing required connect");
@Override public void stop() throws Exception { quiesce(); // KG-10156: Add some logging to indicate that JMX has stopped ServiceProperties properties = serviceContext.getProperties(); String connectorServerAddress = properties.get("connector.server.address"); if (connectorServerAddress == null) { connectorServerAddress = "jmx://localhost:2020"; } Logger startupLogger = Launcher.getGatewayStartupLogger(); startupLogger.info(format("Stopping JMX Management service with URI %s", connectorServerAddress)); // cleanup the MBeans that were added... handler.cleanupRegisteredBeans(); if (connectorServer != null) { connectorServer.stop(); connectorServer = null; } if (sRMIRegistry != null) { UnicastRemoteObject.unexportObject(sRMIRegistry, true); sRMIRegistry = null; } }
String connectorServerAddress = properties.get("connector.server.address"); if (connectorServerAddress != null) { uri = new URI(connectorServerAddress);