Skip to content

Commit

Permalink
fixed token auth - adapted readme
Browse files Browse the repository at this point in the history
  • Loading branch information
b3rnh8rd committed Feb 9, 2023
1 parent a7a9495 commit 491fac9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
27 changes: 15 additions & 12 deletions README.md
Expand Up @@ -110,21 +110,24 @@ This can also be combined with given trust and keystore configuration

###### Example with Schema Registry with HTTPS and Basic Auth

The http**s** and 'sslEnabled' is important if you want to use truststore and/or keystore otherwise those attributes are ignored and now sslContext is provided to Schema Registry client

you can use only Basic Auth if you SR is only protected with basic auth, you can use only keystore+truststore if your SR is protected with mTLS or you can use both settings in parallel.
The http**s** and 'sslEnabled' is important if you want to use truststore and/or keystore otherwise those attributes are ignored and now sslContext is provided to Schema Registry client.

You can use only Basic Auth if youy SR is only protected with basic auth, you can use Token Auth if your SR is protected with an OAUTH Token, you can use only keystore+truststore if your SR is protected with mTLS or you can use both settings in parallel.
schemaRegistryBasicAuthUserInfo is deprecated since token auth is supported in addition to basic auth.
There is a schemaRegistryAuthMode property with possible values NONE, BASIC or TOKEN and schemaRegistryAuthConfig property with either basic auth credentials or OAuthToken.
```
{
....
"schemaRegistry": "https://myschemaregistry:8081",
"schemaRegistryBasicAuthUserInfo": "<BasicAuthUser>:<BasicAuthPW>",
...
"sslEnabled": true,
"keyStoreLocation": "mykeystore.jks",
"keyStorePassword": "mykeystorepw",
"trustStoreLocation": "mytruststore.jks",
"trustStorePassword": "mykeystorepw"
....
"schemaRegistry": "https://myschemaregistry:8081",
deprecated-> "schemaRegistryBasicAuthUserInfo": "<BasicAuthUser>:<BasicAuthPW>",
"schemaRegistryAuthMode": "NONE|BASIC|TOKEN",
"schemaRegistryAuthConfig": "<BasicAuthUser>:<BasicAuthPW>|<OAuthToken>:",
...
"sslEnabled": true,
"keyStoreLocation": "mykeystore.jks",
"keyStorePassword": "mykeystorepw",
"trustStoreLocation": "mytruststore.jks",
"trustStorePassword": "mykeystorepw"
}
```

Expand Down
45 changes: 29 additions & 16 deletions src/main/java/at/esque/kafka/cluster/ClusterConfig.java
Expand Up @@ -15,8 +15,8 @@ public class ClusterConfig {
private StringProperty schemaRegistry = new SimpleStringProperty();
private StringProperty schemaRegistryBasicAuthUserInfo = new SimpleStringProperty();
private StringProperty schemaRegistryAuthConfig = new SimpleStringProperty();
private ListProperty<SchemaRegistryAuthMode> schemaRegistryAuthModes = new SimpleListProperty<>( FXCollections.observableArrayList(Arrays.asList(SchemaRegistryAuthMode.NONE,SchemaRegistryAuthMode.BASIC, SchemaRegistryAuthMode.TOKEN)));
private ObjectProperty<SchemaRegistryAuthMode> schemaRegistryAuthMode = new SimpleObjectProperty<>();
private ListProperty<SchemaRegistryAuthMode> schemaRegistryAuthModes = new SimpleListProperty<>(FXCollections.observableArrayList(Arrays.asList(SchemaRegistryAuthMode.NONE, SchemaRegistryAuthMode.BASIC, SchemaRegistryAuthMode.TOKEN)));
private ObjectProperty<SchemaRegistryAuthMode> schemaRegistryAuthMode = new SimpleObjectProperty<>(SchemaRegistryAuthMode.NONE);
private BooleanProperty schemaRegistryUseSsl = new SimpleBooleanProperty();
private BooleanProperty sslEnabled = new SimpleBooleanProperty();
private BooleanProperty certPathValidationSuppressed = new SimpleBooleanProperty();
Expand All @@ -36,17 +36,19 @@ public class ClusterConfig {

public ClusterConfig() {
}

public enum SchemaRegistryAuthMode {
NONE,
BASIC,
TOKEN
}

public ClusterConfig(ClusterConfig existingConfig) {
update(existingConfig);
}

public void update(ClusterConfig existingConfig) {
if(existingConfig != null) {
if (existingConfig != null) {
this.setIdentifier(existingConfig.getIdentifier());
this.setBootStrapServers(existingConfig.getBootStrapServers());
this.setSchemaRegistry(existingConfig.getSchemaRegistry());
Expand Down Expand Up @@ -128,6 +130,7 @@ public void setSslEnabled(boolean sslEnabled) {
public boolean isSchemaRegistrySuppressCertPathValidation() {
return certPathValidationSuppressed.get();
}

public BooleanProperty suppressCertPathValidation() {
return certPathValidationSuppressed;
}
Expand Down Expand Up @@ -241,19 +244,42 @@ public void setSaslJaasConfig(String saslJaasConfig) {
this.saslJaasConfig.set(saslJaasConfig);
}

/**
* Deprecated use schemaRegistryAuthConfig instead for basic and token auth
*/
@Deprecated
@JsonProperty("schemaRegistryBasicAuthUserInfo")
public String getSchemaRegistryBasicAuthUserInfo() {
return schemaRegistryBasicAuthUserInfo.get();
}

/**
* Deprecated use schemaRegistryAuthConfig instead for basic and token auth
*/
public StringProperty schemaRegistryBasicAuthUserInfoProperty() {
return schemaRegistryBasicAuthUserInfo;
}

/**
* Deprecated use schemaRegistryAuthConfig instead for basic and token auth
*/
public void setSchemaRegistryBasicAuthUserInfo(String schemaRegistryBasicAuthUserInfo) {
this.schemaRegistryBasicAuthUserInfo.set(schemaRegistryBasicAuthUserInfo);
}

@JsonProperty("schemaRegistryAuthMode")
public SchemaRegistryAuthMode getSchemaRegistryAuthMode() {
return schemaRegistryAuthMode.get();
}

public ObjectProperty<SchemaRegistryAuthMode> schemaRegistryAuthModeProperty() {
return schemaRegistryAuthMode;
}

public void setSchemaRegistryAuthMode(SchemaRegistryAuthMode schemaRegistryAuthMode) {
this.schemaRegistryAuthMode.set(schemaRegistryAuthMode);
}

@JsonProperty("schemaRegistryAuthConfig")
public String getSchemaRegistryAuthConfig() {
return schemaRegistryAuthConfig.get();
Expand All @@ -271,19 +297,6 @@ public ListProperty<SchemaRegistryAuthMode> schemaRegistryAuthModesProperty() {
return schemaRegistryAuthModes;
}

@JsonProperty("schemaRegistryAuthMode")
public SchemaRegistryAuthMode getSchemaRegistryAuthMode() {
return schemaRegistryAuthMode.get();
}

public ObjectProperty<SchemaRegistryAuthMode> schemaRegistryAuthModeProperty() {
return schemaRegistryAuthMode;
}

public void setSchemaRegistryAuthMode(SchemaRegistryAuthMode schemaRegistryAuthMode) {
this.schemaRegistryAuthMode.set(schemaRegistryAuthMode);
}

@JsonProperty("schemaRegistryUseSsl")
public boolean isSchemaRegistryUseSsl() {
return schemaRegistryUseSsl.get();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/esque/kafka/dialogs/ClusterConfigDialog.java
Expand Up @@ -20,8 +20,8 @@ public class ClusterConfigDialog {
public static final String LABEL_IDENTIFIER = "Identifier";
public static final String LABEL_BOOTSTRAP_SERVERS = "Bootstrap-Servers";
public static final String LABEL_SCHEMA_REGISTRY_URL = "Schema Registry URL";
public static final String LABEL_SCHEMA_REGISTRY_BASIC_AUTH_USER_INFO = "LEGACY -Schema Registry Basic Auth User Info";
public static final String LABEL_SCHEMA_REGISTRY_AUTH_USER_INFO = "Schema Registry Auth User Info";
public static final String LABEL_SCHEMA_REGISTRY_BASIC_AUTH_USER_INFO = "<<Deprecated>>Schema Registry Basic Auth User Info";
public static final String LABEL_SCHEMA_REGISTRY_AUTH_USER_INFO = "Schema Registry Auth Info";
public static final String LABEL_SCHEMA_REGISTRY_AUTH_MODE = "Schema Registry Auth Mode";
public static final String LABEL_ENABLE_SSL = "Enable SSL";
public static final String LABEL_KEY_STORE_LOCATION = "Key Store Location";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/esque/kafka/handlers/ConfigHandler.java
Expand Up @@ -325,8 +325,8 @@ public Map<String, String> getSaslProperties(ClusterConfig config) {
props.put(SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
props.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SchemaRegistryClientConfig.USER_INFO_CONFIG, config.getSchemaRegistryAuthConfig());
}else if (ClusterConfig.SchemaRegistryAuthMode.TOKEN.equals(config.getSchemaRegistryAuthMode())){
props.put(SchemaRegistryClientConfig.BEARER_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
props.put(SchemaRegistryClientConfig.CLIENT_NAMESPACE + SchemaRegistryClientConfig.BEARER_AUTH_TOKEN_CONFIG, config.getSchemaRegistryAuthConfig());
props.put(SchemaRegistryClientConfig.BEARER_AUTH_CREDENTIALS_SOURCE, "STATIC_TOKEN");
props.put(SchemaRegistryClientConfig.BEARER_AUTH_TOKEN_CONFIG, config.getSchemaRegistryAuthConfig());
}

return props;
Expand Down

0 comments on commit 491fac9

Please sign in to comment.