Skip to content

Commit

Permalink
DBZ-7876 Add NATS user/password authentication config options
Browse files Browse the repository at this point in the history
Add a secondary authentication method to NATS thanks to two new properties: `auth.user` and `auth.password`.
Since JWT/seed was available before this authentication method, they should only be used if JWT auth is not already configured.
  • Loading branch information
SylvainMarty authored and jpechane committed May 28, 2024
1 parent 13982e5 commit deda87c
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class NatsJetStreamChangeConsumer extends BaseChangeConsumer

private static final String PROP_AUTH_JWT = PROP_PREFIX + "auth.jwt";
private static final String PROP_AUTH_SEED = PROP_PREFIX + "auth.seed";
private static final String PROP_AUTH_USER = PROP_PREFIX + "auth.user";
private static final String PROP_AUTH_PASSWORD = PROP_PREFIX + "auth.password";

private Connection nc;
private JetStream js;
Expand All @@ -68,6 +70,12 @@ public class NatsJetStreamChangeConsumer extends BaseChangeConsumer
@ConfigProperty(name = PROP_AUTH_SEED)
Optional<String> seed;

@ConfigProperty(name = PROP_AUTH_USER)
Optional<String> user;

@ConfigProperty(name = PROP_AUTH_PASSWORD)
Optional<String> password;

@Inject
@CustomConsumerBuilder
Instance<JetStream> customStreamingConnection;
Expand All @@ -94,6 +102,9 @@ void connect() {
natsOptionsBuilder
.authHandler(Nats.staticCredentials(jwt.get().toCharArray(), seed.get().toCharArray()));
}
else if (user.isPresent() && password.isPresent()) {
natsOptionsBuilder.userInfo(user.get(), password.get());
}

nc = Nats.connect(natsOptionsBuilder.build());

Expand Down

0 comments on commit deda87c

Please sign in to comment.