Skip to content

Commit

Permalink
[3.0] Fix can't authenticate by username and password when use Nacos
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxcrel committed Apr 19, 2022
1 parent 6da4c0c commit b398fa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
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 @@ -147,6 +149,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());
}
}

private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.common.utils.StringConstantFieldValuePredicate.of;
Expand Down Expand Up @@ -140,6 +142,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 b398fa8

Please sign in to comment.