Skip to content

Commit

Permalink
Fix SCRAM naming
Browse files Browse the repository at this point in the history
  • Loading branch information
gfinocchiaro committed Mar 20, 2024
1 parent 71c5855 commit 8ea1a2c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,24 +638,24 @@ Example:
<param name="authentication.password">authorized-kafka-user-password</param>
```

###### `SCRAM-256`
###### `SCRAM_256`

Example:

```xml
<param name="authentication.enable">true</param>
<param name="authentication.mechanism">SCRAM-256</param>
<param name="authentication.mechanism">SCRAM_256</param>
<param name="authentication.username">authorized-kafka-usee</param>
<param name="authentication.password">authorized-kafka-user-password</param>
```

###### `SCRAM-512`
###### `SCRAM_512`

Example:

```xml
<param name="authentication.enable">true</param>
<param name="authentication.mechanism">SCRAM-512</param>
<param name="authentication.mechanism">SCRAM_512</param>
<param name="authentication.username">authorized-kafka-username</param>
<param name="authentication.password">authorized-kafka-username-password</param>
```
Expand Down
2 changes: 1 addition & 1 deletion kafka-connector-project/kafka-connector-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ task distribuiteConsumer(type: Copy) {
}

clean {
delete "$rootDir/$consumerDeployDirName"
delete "$rootDir/$consumerDeployDirName"
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static Properties addAuthentication(ConnectorConfig config) {
NonNullKeyProperties props = new NonNullKeyProperties();
if (config.isAuthenticationEnabled()) {
SaslMechanism mechanism = config.authenticationMechanism();
props.setProperty(SaslConfigs.SASL_MECHANISM, mechanism.toString());
props.setProperty(SaslConfigs.SASL_MECHANISM, mechanism.toProperty());
props.setProperty(SaslConfigs.SASL_JAAS_CONFIG, configuredWith(config));
if (config.isGssapiEnabled()) {
props.setProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,23 @@ public String loginModule() {
public String loginModule() {
return "org.apache.kafka.common.security.scram.ScramLoginModule";
}

@Override
public String toProperty() {
return "SCRAM-SHA-256";
}
},

SCRAM_512 {
@Override
public String loginModule() {
return "org.apache.kafka.common.security.scram.ScramLoginModule";
}

@Override
public String toProperty() {
return "SCRAM-SHA-512";
}
},

GSSAPI {
Expand All @@ -135,6 +145,10 @@ public static Set<String> names() {
public String loginModule() {
return "";
}

public String toProperty() {
return toString();
}
}

public enum RecordComsumeFrom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Stream;

public class ConnectorConfigTest {

Expand Down Expand Up @@ -1205,10 +1204,7 @@ public void shouldGetDefaultAuthenticationSettings() {
@Test
public void shouldOverrideAuthenticationSettings() {
// Sasl mechanisms under test
List<String> mechanisms =
Stream.of(SaslMechanism.SCRAM_256, SaslMechanism.SCRAM_512)
.map(Object::toString)
.toList();
List<SaslMechanism> mechanisms = List.of(SaslMechanism.SCRAM_256, SaslMechanism.SCRAM_512);

for (boolean encrypted : List.of(true, false)) {
Map<String, String> updatedConfig = new HashMap<>(standardParameters());
Expand All @@ -1217,13 +1213,14 @@ public void shouldOverrideAuthenticationSettings() {
if (encrypted) {
updatedConfig.putAll(encryptionParameters());
}
for (String mechanism : mechanisms) {
updatedConfig.put(BrokerAuthenticationConfigs.SASL_MECHANISM, mechanism);
for (SaslMechanism mechanism : mechanisms) {
updatedConfig.put(BrokerAuthenticationConfigs.SASL_MECHANISM, mechanism.toString());
ConnectorConfig config =
ConnectorConfig.newConfig(adapterDir.toFile(), updatedConfig);

assertThat(config.isAuthenticationEnabled()).isTrue();
assertThat(config.authenticationMechanism().toString()).isEqualTo(mechanism);
assertThat(config.authenticationMechanism().toString())
.isEqualTo(mechanism.toString());
assertThat(config.authenticationUsername()).isEqualTo("sasl-username");
assertThat(config.authenticationPassword()).isEqualTo("sasl-password");

Expand All @@ -1235,7 +1232,7 @@ public void shouldOverrideAuthenticationSettings() {
? SecurityProtocol.SASL_SSL.toString()
: SecurityProtocol.SASL_PLAINTEXT.toString(),
SaslConfigs.SASL_MECHANISM,
mechanism,
mechanism.toProperty(),
SaslConfigs.SASL_JAAS_CONFIG,
"org.apache.kafka.common.security.scram.ScramLoginModule required username='sasl-username' password='sasl-password';");
}
Expand Down

0 comments on commit 8ea1a2c

Please sign in to comment.