Skip to content

Commit

Permalink
Fix can't authenticate by username and password when use Nacos (#9941)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxcrel committed Jun 14, 2022
1 parent 8d9e252 commit 9efe21a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -52,7 +52,9 @@
import java.util.stream.Stream;

import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
import static com.alibaba.nacos.api.PropertyKeyConst.PASSWORD;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
import static java.util.Collections.emptyMap;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.common.utils.StringConstantFieldValuePredicate.of;
Expand Down Expand Up @@ -143,6 +145,12 @@ private void setServerAddr(URL url, Properties properties) {
private static void setProperties(URL url, Properties properties) {
// Get the parameters from constants
Map<String, String> parameters = url.getParameters(of(PropertyKeyConst.class));
if (StringUtils.isNotEmpty(url.getUsername())){
properties.put(USERNAME, url.getUsername());
}
if (StringUtils.isNotEmpty(url.getPassword())){
properties.put(PASSWORD, url.getPassword());
}
// Put all parameters
properties.putAll(parameters);
}
Expand Down
Expand Up @@ -37,7 +37,9 @@
import java.util.Properties;

import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
import static com.alibaba.nacos.api.PropertyKeyConst.PASSWORD;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
Expand Down Expand Up @@ -150,7 +152,12 @@ private static void setProperties(URL url, Properties properties) {
Map<String, String> parameters = url.getParameters(of(PropertyKeyConst.class));
// Put all parameters
properties.putAll(parameters);

if (StringUtils.isNotEmpty(url.getUsername())){
properties.put(USERNAME, url.getUsername());
}
if (StringUtils.isNotEmpty(url.getPassword())){
properties.put(PASSWORD, url.getPassword());
}
putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
}

Expand Down

0 comments on commit 9efe21a

Please sign in to comment.