public static String getOptionalProperty(ServiceProperties properties, String propertyName, String defaultValue) { String propertyValue = properties.get(propertyName); if (propertyValue == null) { return defaultValue; } return propertyValue; }
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; } }
isSimpleProperty = false; ServiceProperties newProperties = new DefaultServiceProperties(); properties.getNested(node.getLocalName(), true).add(newProperties); parseProperties(node, newProperties); break; String existingValue = properties.get(node.getLocalName()); if (existingValue == null) { properties.put(node.getLocalName(), nodeValue); } else { properties.put(node.getLocalName(), existingValue + LIST_SEPARATOR + nodeValue);
private void validateProperties(ServiceContext serviceContext) { ServiceProperties properties = serviceContext.getProperties(); // validate all properties: rewrite-cookie-domain, rewrite-cookie-path, rewrite-location Iterable<String> simpleProperties = properties.simplePropertyNames(); Set<String> unknownProperties = StreamSupport.stream(simpleProperties.spliterator(), false) .filter(p -> !KNOWN_SIMPLE_PROPERTIES.contains(p)) .collect(Collectors.toSet()); Iterable<String> nestedProperties = properties.nestedPropertyNames(); StreamSupport.stream(nestedProperties.spliterator(), false) .filter(p -> !KNOWN_NESTED_PROPERTIES.contains(p)) .forEach(unknownProperties::add); if (!unknownProperties.isEmpty()) { throw new IllegalArgumentException(serviceContext.getServiceName() + " http.proxy service specifies unknown properties : " + unknownProperties); } }
/** * 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()); }
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;
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; }
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 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; }
@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); }
options.put(format(optionPattern, AUTHENTICATION_CONNECT), getProperties().get("authentication.connect")); options.put(format(optionPattern, AUTHENTICATION_IDENTIFIER), getProperties().get("authentication.identifier")); options.put(format(optionPattern, AUTHENTICATION_CONNECT), getProperties().get("authentication.connect")); options.put(format(optionPattern, AUTHENTICATION_IDENTIFIER), getProperties().get("authentication.identifier")); options.put(format(optionPattern, ENCRYPTION_KEY_ALIAS), getProperties().get("encryption.key.alias")); options.put(format(optionPattern, SERVICE_DOMAIN), getProperties().get("service.domain"));
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);