Search in sources :

Example 46 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class JaasOptionsUtils method validateString.

public String validateString(String name, boolean isRequired) throws ValidateException {
    String value = (String) options.get(name);
    if (value == null) {
        if (isRequired)
            throw new ConfigException(String.format("The OAuth configuration option %s value must be non-null", name));
        else
            return null;
    }
    value = value.trim();
    if (value.isEmpty()) {
        if (isRequired)
            throw new ConfigException(String.format("The OAuth configuration option %s value must not contain only whitespace", name));
        else
            return null;
    }
    return value;
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException)

Example 47 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class ConfigurationControlManager method validateAlterConfig.

private ApiError validateAlterConfig(ConfigResource configResource, List<ApiMessageAndVersion> newRecords, Consumer<ConfigResource> existenceChecker) {
    Map<String, String> newConfigs = new HashMap<>();
    TimelineHashMap<String, String> existingConfigs = configData.get(configResource);
    if (existingConfigs != null)
        newConfigs.putAll(existingConfigs);
    for (ApiMessageAndVersion newRecord : newRecords) {
        ConfigRecord configRecord = (ConfigRecord) newRecord.message();
        if (configRecord.value() == null) {
            newConfigs.remove(configRecord.name());
        } else {
            newConfigs.put(configRecord.name(), configRecord.value());
        }
    }
    try {
        validator.validate(configResource, newConfigs);
        existenceChecker.accept(configResource);
        if (alterConfigPolicy.isPresent()) {
            alterConfigPolicy.get().validate(new RequestMetadata(configResource, newConfigs));
        }
    } catch (ConfigException e) {
        return new ApiError(INVALID_CONFIG, e.getMessage());
    } catch (Throwable e) {
        return ApiError.fromThrowable(e);
    }
    return ApiError.NONE;
}
Also used : ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) HashMap(java.util.HashMap) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ConfigException(org.apache.kafka.common.config.ConfigException) ApiError(org.apache.kafka.common.requests.ApiError) RequestMetadata(org.apache.kafka.server.policy.AlterConfigPolicy.RequestMetadata)

Example 48 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class OAuthCompatibilityTool method main.

public static void main(String[] args) {
    ArgsHandler argsHandler = new ArgsHandler();
    Namespace namespace;
    try {
        namespace = argsHandler.parseArgs(args);
    } catch (ArgumentParserException e) {
        Exit.exit(1);
        return;
    }
    ConfigHandler configHandler = new ConfigHandler(namespace);
    Map<String, ?> configs = configHandler.getConfigs();
    Map<String, Object> jaasConfigs = configHandler.getJaasOptions();
    try {
        String accessToken;
        {
            // Client side...
            try (AccessTokenRetriever atr = AccessTokenRetrieverFactory.create(configs, jaasConfigs)) {
                atr.init();
                AccessTokenValidator atv = AccessTokenValidatorFactory.create(configs);
                System.out.println("PASSED 1/5: client configuration");
                accessToken = atr.retrieve();
                System.out.println("PASSED 2/5: client JWT retrieval");
                atv.validate(accessToken);
                System.out.println("PASSED 3/5: client JWT validation");
            }
        }
        {
            // Broker side...
            try (CloseableVerificationKeyResolver vkr = VerificationKeyResolverFactory.create(configs, jaasConfigs)) {
                vkr.init();
                AccessTokenValidator atv = AccessTokenValidatorFactory.create(configs, vkr);
                System.out.println("PASSED 4/5: broker configuration");
                atv.validate(accessToken);
                System.out.println("PASSED 5/5: broker JWT validation");
            }
        }
        System.out.println("SUCCESS");
        Exit.exit(0);
    } catch (Throwable t) {
        System.out.println("FAILED:");
        t.printStackTrace();
        if (t instanceof ConfigException) {
            System.out.printf("%n");
            argsHandler.parser.printHelp();
        }
        Exit.exit(1);
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Namespace(net.sourceforge.argparse4j.inf.Namespace) AccessTokenValidator(org.apache.kafka.common.security.oauthbearer.secured.AccessTokenValidator) AccessTokenRetriever(org.apache.kafka.common.security.oauthbearer.secured.AccessTokenRetriever) CloseableVerificationKeyResolver(org.apache.kafka.common.security.oauthbearer.secured.CloseableVerificationKeyResolver) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException)

Example 49 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class Cast method parseFieldTypes.

private static Map<String, Schema.Type> parseFieldTypes(List<String> mappings) {
    final Map<String, Schema.Type> m = new HashMap<>();
    boolean isWholeValueCast = false;
    for (String mapping : mappings) {
        final String[] parts = mapping.split(":");
        if (parts.length > 2) {
            throw new ConfigException(ReplaceField.ConfigName.RENAME, mappings, "Invalid rename mapping: " + mapping);
        }
        if (parts.length == 1) {
            Schema.Type targetType = Schema.Type.valueOf(parts[0].trim().toUpperCase(Locale.ROOT));
            m.put(WHOLE_VALUE_CAST, validCastType(targetType, FieldType.OUTPUT));
            isWholeValueCast = true;
        } else {
            Schema.Type type;
            try {
                type = Schema.Type.valueOf(parts[1].trim().toUpperCase(Locale.ROOT));
            } catch (IllegalArgumentException e) {
                throw new ConfigException("Invalid type found in casting spec: " + parts[1].trim(), e);
            }
            m.put(parts[0].trim(), validCastType(type, FieldType.OUTPUT));
        }
    }
    if (isWholeValueCast && mappings.size() > 1) {
        throw new ConfigException("Cast transformations that specify a type to cast the entire value to " + "may ony specify a single cast in their spec");
    }
    return m;
}
Also used : Type(org.apache.kafka.connect.data.Schema.Type) HashMap(java.util.HashMap) Schema(org.apache.kafka.connect.data.Schema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) Type(org.apache.kafka.connect.data.Schema.Type) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 50 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project kafka by apache.

the class TimestampConverter method configure.

@Override
public void configure(Map<String, ?> configs) {
    final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs);
    final String field = simpleConfig.getString(FIELD_CONFIG);
    final String type = simpleConfig.getString(TARGET_TYPE_CONFIG);
    String formatPattern = simpleConfig.getString(FORMAT_CONFIG);
    final String unixPrecision = simpleConfig.getString(UNIX_PRECISION_CONFIG);
    schemaUpdateCache = new SynchronizedCache<>(new LRUCache<>(16));
    if (type.equals(TYPE_STRING) && Utils.isBlank(formatPattern)) {
        throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps");
    }
    SimpleDateFormat format = null;
    if (!Utils.isBlank(formatPattern)) {
        try {
            format = new SimpleDateFormat(formatPattern);
            format.setTimeZone(UTC);
        } catch (IllegalArgumentException e) {
            throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e);
        }
    }
    config = new Config(field, type, format, unixPrecision);
}
Also used : SimpleConfig(org.apache.kafka.connect.transforms.util.SimpleConfig) LRUCache(org.apache.kafka.common.cache.LRUCache) SimpleConfig(org.apache.kafka.connect.transforms.util.SimpleConfig) ConfigException(org.apache.kafka.common.config.ConfigException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ConfigException (org.apache.kafka.common.config.ConfigException)136 HashMap (java.util.HashMap)29 Test (org.junit.jupiter.api.Test)28 Test (org.junit.Test)20 Properties (java.util.Properties)10 KafkaException (org.apache.kafka.common.KafkaException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Pattern (java.util.regex.Pattern)9 Serde (org.apache.kafka.common.serialization.Serde)8 SimpleConfig (org.apache.kafka.connect.transforms.util.SimpleConfig)8 File (java.io.File)7 SSLContext (javax.net.ssl.SSLContext)7 Map (java.util.Map)6 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)6 KeyStore (java.security.KeyStore)5 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 ConfigDef (org.apache.kafka.common.config.ConfigDef)5 IOException (java.io.IOException)4