Add support for NATS token authentication (#4238)

This commit is contained in:
powercas_gamer authored and GitHub committed 2026-03-17 21:10:56 +00:00
1 parent fc26521594
commit 691a87b5ea
13 files changed
+43 -2

No files matched your search

+1
View File
@@ -276,6 +276,7 @@ nats:
address: localhost
username: ''
password: ''
token: ''
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
+1
View File
@@ -274,6 +274,7 @@ nats:
address: localhost
username: ''
password: ''
token: ''
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
@@ -725,6 +725,11 @@ public final class ConfigKeys {
*/
public static final ConfigKey<String> NATS_PASSWORD = notReloadable(stringKey("nats.password", ""));
/**
* The token in use by the nats server, or an empty string if there is no token
*/
public static final ConfigKey<String> NATS_TOKEN = notReloadable(stringKey("nats.token", ""));
/**
* If the nats connection should use SSL
*/
@@ -170,15 +170,19 @@ public class MessagingFactory<P extends LuckPermsPlugin> {
String address = configuration.get(ConfigKeys.NATS_ADDRESS);
String username = configuration.get(ConfigKeys.NATS_USERNAME);
String password = configuration.get(ConfigKeys.NATS_PASSWORD);
String token = configuration.get(ConfigKeys.NATS_TOKEN);
if (password.isEmpty()) {
password = null;
}
if (username.isEmpty()) {
username = null;
}
if (token.isEmpty()) {
token = null;
}
boolean ssl = configuration.get(ConfigKeys.NATS_SSL);
natsMessenger.init(address, username, password, ssl);
natsMessenger.init(address, username, password, token, ssl);
return natsMessenger;
}
}
@@ -69,7 +69,7 @@ public class NatsMessenger implements Messenger {
this.connection.publish(CHANNEL, output.toByteArray());
}
public void init(String address, String username, String password, boolean ssl) {
public void init(String address, String username, String password, String token, boolean ssl) {
HostAndPort hostAndPort = new HostAndPort(address)
.requireBracketsForIPv6()
.withDefaultPort(Options.DEFAULT_PORT);
@@ -86,6 +86,10 @@ public class NatsMessenger implements Messenger {
builder.userInfo(username, password);
}
if (token != null) {
builder.token(token.toCharArray());
}
if (ssl) {
builder.secure();
}
+1
View File
@@ -280,6 +280,7 @@ nats {
address = "localhost"
username = ""
password = ""
token = ""
}
# Settings for RabbitMQ.
+10
View File
@@ -271,6 +271,16 @@ redis {
password = ""
}
# Settings for nats.
# Port 4222 is used by default; set address to "host:port" if differs
nats {
enabled = false
address = "localhost"
username = ""
password = ""
token = ""
}
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
rabbitmq {
+1
View File
@@ -276,6 +276,7 @@ nats:
address: localhost
username: ''
password: ''
token: ''
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
@@ -271,6 +271,16 @@ redis {
password = ""
}
# Settings for nats.
# Port 4222 is used by default; set address to "host:port" if differs
nats {
enabled = false
address = "localhost"
username = ""
password = ""
token = ""
}
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
rabbitmq {
+1
View File
@@ -271,6 +271,7 @@ nats:
address: localhost
username: ''
password: ''
token: ''
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
+1
View File
@@ -280,6 +280,7 @@ nats {
address = "localhost"
username = ""
password = ""
token = ""
}
# Settings for RabbitMQ.
+1
View File
@@ -261,6 +261,7 @@ nats:
address: localhost
username: ''
password: ''
token: ''
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs
+1
View File
@@ -265,6 +265,7 @@ nats:
address: localhost
username: ''
password: ''
token: ''
# Settings for RabbitMQ.
# Port 5672 is used by default; set address to "host:port" if differs