Skip to content

Commit b189ddf

Browse files
code improvements
1 parent 4a2819e commit b189ddf

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiServerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ public ResponseObject loginUser(HttpSession session, String username, String pas
4949

5050
boolean resetPassword(UserAccount userAccount, String token, String password);
5151

52-
boolean isEnforcePostRequestsAndTimestamps();
52+
boolean isPostRequestsAndTimestampsEnforced();
5353
}

server/src/main/java/com/cloud/api/ApiServer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
198198
private static final String SANITIZATION_REGEX = "[\n\r]";
199199

200200
private static boolean encodeApiResponse = false;
201-
private boolean isEnforcePostRequestsAndTimestamps = false;
201+
private boolean isPostRequestsAndTimestampsEnforced = false;
202202

203203
/**
204204
* Non-printable ASCII characters - numbers 0 to 31 and 127 decimal
@@ -282,9 +282,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
282282
, ConfigKey.Scope.Global);
283283
static final ConfigKey<Boolean> EnforcePostRequestsAndTimestamps = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED
284284
, Boolean.class
285-
, "enable.enforce.post.requests.and.timestamps"
285+
, "enforce.post.requests.and.timestamps"
286286
, "false"
287-
, "enables/disables whether the ApiServer only accepts state-changing POST requests and requests with timestamps."
287+
, "Enable/Disable whether the ApiServer should only accept POST requests for state-changing APIs and requests with timestamps."
288288
, false
289289
, ConfigKey.Scope.Global);
290290
private static final ConfigKey<String> JSONDefaultContentType = new ConfigKey<> (ConfigKey.CATEGORY_ADVANCED
@@ -444,7 +444,7 @@ protected void setupIntegrationPortListener(Integer apiPort) {
444444
public boolean start() {
445445
Security.addProvider(new BouncyCastleProvider());
446446
Integer apiPort = IntegrationAPIPort.value(); // api port, null by default
447-
isEnforcePostRequestsAndTimestamps = EnforcePostRequestsAndTimestamps.value();
447+
isPostRequestsAndTimestampsEnforced = EnforcePostRequestsAndTimestamps.value();
448448

449449
final Long snapshotLimit = ConcurrentSnapshotsThresholdPerHost.value();
450450
if (snapshotLimit == null || snapshotLimit <= 0) {
@@ -726,8 +726,8 @@ public String handleRequest(final Map params, final String responseType, final S
726726
}
727727

728728
@Override
729-
public boolean isEnforcePostRequestsAndTimestamps() {
730-
return isEnforcePostRequestsAndTimestamps;
729+
public boolean isPostRequestsAndTimestampsEnforced() {
730+
return isPostRequestsAndTimestampsEnforced;
731731
}
732732

733733
private String getBaseAsyncResponse(final long jobId, final BaseAsyncCmd cmd) {
@@ -1029,13 +1029,13 @@ public boolean verifyRequest(final Map<String, Object[]> requestParameters, fina
10291029
apiKey = apiKey.replaceAll(SANITIZATION_REGEX, "_");
10301030
logger.debug("Request expired -- ignoring ...sig [{}], apiKey [{}].", signature, apiKey);
10311031
return false;
1032-
} else if (isEnforcePostRequestsAndTimestamps && expiresTS.after(thresholdTime)) {
1032+
} else if (isPostRequestsAndTimestampsEnforced && expiresTS.after(thresholdTime)) {
10331033
signature = signature.replaceAll(SANITIZATION_REGEX, "_");
10341034
apiKey = apiKey.replaceAll(SANITIZATION_REGEX, "_");
10351035
logger.debug(String.format("Expiration parameter is set for too long -- ignoring ...sig [%s], apiKey [%s].", signature, apiKey));
10361036
return false;
10371037
}
1038-
} else if (isEnforcePostRequestsAndTimestamps) {
1038+
} else if (isPostRequestsAndTimestampsEnforced) {
10391039
// Force expiration parameter
10401040
logger.debug("Signature Version must be 3, and should be along with the Expires parameter -- ignoring request.");
10411041
return false;

server/src/main/java/com/cloud/api/ApiServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
323323
}
324324
}
325325

326-
if (apiServer.isEnforcePostRequestsAndTimestamps() && !isStateChangingCommandUsingPOST(command, req.getMethod(), params)) {
326+
if (apiServer.isPostRequestsAndTimestampsEnforced() && !isStateChangingCommandUsingPOST(command, req.getMethod(), params)) {
327327
String errorText = String.format("State changing command %s needs to be sent using POST request", command);
328328
if (command.equalsIgnoreCase("updateConfiguration") && params.containsKey("name")) {
329329
errorText = String.format("Changes for configuration %s needs to be sent using POST request", params.get("name")[0]);

0 commit comments

Comments
 (0)