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;
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations