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

removed group name and password checks from rest calls #13757

Closed
Closed
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 @@ -16,8 +16,19 @@

package com.hazelcast.internal.ascii.rest;

import com.hazelcast.cluster.ClusterState;
import com.hazelcast.instance.Node;
import com.hazelcast.internal.ascii.AbstractTextCommandProcessor;
import com.hazelcast.internal.ascii.TextCommandService;
import com.hazelcast.internal.cluster.ClusterService;
import com.hazelcast.internal.util.rest.RestUtil;
import com.hazelcast.logging.ILogger;

import static com.hazelcast.internal.util.rest.RestUtil.exceptionResponse;
import static com.hazelcast.internal.util.rest.RestUtil.response;
import static com.hazelcast.internal.util.rest.RestUtil.sendResponse;
import static com.hazelcast.util.StringUtil.lowerCaseInternal;
import static com.hazelcast.util.StringUtil.stringToBytes;


public abstract class HttpCommandProcessor<T> extends AbstractTextCommandProcessor<T> {
Expand Down Expand Up @@ -60,7 +71,42 @@ public abstract class HttpCommandProcessor<T> extends AbstractTextCommandProcess
public static final String LEGACY_URI_MANCENTER_WAN_CLEAR_QUEUES = "/hazelcast/rest/mancenter/clearWanQueues";
public static final String LEGACY_URI_ADD_WAN_CONFIG = "/hazelcast/rest/wan/addWanConfig";

private final ILogger logger;

protected HttpCommandProcessor(TextCommandService textCommandService) {
super(textCommandService);
this.logger = textCommandService.getNode().getLogger(HttpCommandProcessor.class);
}

public void handleGetClusterState(HttpCommand command) {
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
res = response(RestUtil.ResponseType.SUCCESS, "state", lowerCaseInternal(clusterState.toString()));
} catch (Throwable throwable) {
logger.warning("Error occurred while getting cluster state", throwable);
res = exceptionResponse(throwable);
}
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}

public void handleListNodes(HttpCommand command) {
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
final String responseTxt = clusterService.getMembers().toString() + "\n"
+ node.getBuildInfo().getVersion() + "\n"
+ System.getProperty("java.version");
res = response(RestUtil.ResponseType.SUCCESS, "response", responseTxt);
sendResponse(textCommandService, command, res);
return;
} catch (Throwable throwable) {
logger.warning("Error occurred while listing nodes", throwable);
res = exceptionResponse(throwable);
}
sendResponse(textCommandService, command, res);
}
}
Expand Up @@ -23,12 +23,16 @@
import com.hazelcast.internal.cluster.ClusterService;
import com.hazelcast.internal.cluster.impl.ClusterServiceImpl;
import com.hazelcast.internal.partition.InternalPartitionService;
import com.hazelcast.internal.util.rest.RestUtil;
import com.hazelcast.logging.ILogger;
import com.hazelcast.nio.ConnectionManager;
import com.hazelcast.util.StringUtil;

import static com.hazelcast.internal.ascii.TextCommandConstants.MIME_TEXT_PLAIN;
import static com.hazelcast.internal.ascii.rest.HttpCommand.CONTENT_TYPE_BINARY;
import static com.hazelcast.internal.ascii.rest.HttpCommand.CONTENT_TYPE_PLAIN_TEXT;
import static com.hazelcast.internal.util.rest.RestUtil.exceptionResponse;
import static com.hazelcast.internal.util.rest.RestUtil.response;
import static com.hazelcast.util.StringUtil.stringToBytes;

public class HttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> {
Expand All @@ -41,11 +45,15 @@ public class HttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand
private static final String HEALTH_PATH_PARAM_MIGRATION_QUEUE_SIZE = "/migration-queue-size";
private static final String HEALTH_PATH_PARAM_CLUSTER_SIZE = "/cluster-size";

private final ILogger logger;

public HttpGetCommandProcessor(TextCommandService textCommandService) {
super(textCommandService);
this.logger = textCommandService.getNode().getLogger(HttpGetCommandProcessor.class);
}

@Override
@SuppressWarnings({"checkstyle:cyclomaticcomplexity"})
public void handle(HttpGetCommand command) {
String uri = command.getURI();
if (uri.startsWith(URI_MAPS)) {
Expand All @@ -58,6 +66,10 @@ public void handle(HttpGetCommand command) {
handleHealthcheck(command, uri);
} else if (uri.startsWith(URI_CLUSTER_VERSION_URL)) {
handleGetClusterVersion(command);
} else if (uri.startsWith(URI_CLUSTER_STATE_URL)) {
handleGetClusterState(command);
} else if (uri.startsWith(URI_CLUSTER_NODES_URL)) {
handleListNodes(command);
} else {
command.send400();
}
Expand Down Expand Up @@ -114,11 +126,16 @@ private static String booleanToString(boolean b) {
}

private void handleGetClusterVersion(HttpGetCommand command) {
String res = "{\"status\":\"${STATUS}\",\"version\":\"${VERSION}\"}";
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
res = res.replace("${STATUS}", "success");
res = res.replace("${VERSION}", clusterService.getClusterVersion().toString());
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
String clusterVersion = clusterService.getClusterVersion().toString();
res = response(RestUtil.ResponseType.SUCCESS, "version", clusterVersion);
} catch (Throwable throwable) {
logger.warning("Error occurred while getting cluster version", throwable);
res = exceptionResponse(throwable);
}
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}

Expand Down