Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply #2925 to branch 2.6.x #3511

Merged
merged 1 commit into from Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -641,6 +641,8 @@ public class Constants {

public static final String FORCE_USE_TAG = "dubbo.force.tag";

public static final String TELNET = "telnet";

/*
* private Constants(){ }
*/
Expand Down
Expand Up @@ -17,7 +17,9 @@
package com.alibaba.dubbo.remoting.telnet.support;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.telnet.TelnetHandler;
Expand Down Expand Up @@ -49,14 +51,20 @@ public String telnet(Channel channel, String message) throws RemotingException {
}
if (command.length() > 0) {
if (extensionLoader.hasExtension(command)) {
try {
String result = extensionLoader.getExtension(command).telnet(channel, message);
if (result == null) {
return null;
if (commandEnabled(channel.getUrl(), command)) {
try {
String result = extensionLoader.getExtension(command).telnet(channel, message);
if (result == null) {
return null;
}
buf.append(result);
} catch (Throwable t) {
buf.append(t.getMessage());
}
buf.append(result);
} catch (Throwable t) {
buf.append(t.getMessage());
} else {
buf.append("Command: ");
buf.append(command);
buf.append(" disabled");
}
} else {
buf.append("Unsupported command: ");
Expand All @@ -72,4 +80,21 @@ public String telnet(Channel channel, String message) throws RemotingException {
return buf.toString();
}

private boolean commandEnabled(URL url, String command) {
boolean commandEnable = false;
String supportCommands = url.getParameter(Constants.TELNET);
if (StringUtils.isEmpty(supportCommands)) {
commandEnable = true;
} else {
String[] commands = Constants.COMMA_SPLIT_PATTERN.split(supportCommands);
for (String c : commands) {
if (command.equals(c)) {
commandEnable = true;
break;
}
}
}
return commandEnable;
}

}