Skip to content

Commit 8bf1097

Browse files
code improvements
1 parent aa48ec9 commit 8bf1097

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
@@ -201,7 +201,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
201201
private static final String SANITIZATION_REGEX = "[\n\r]";
202202

203203
private static boolean encodeApiResponse = false;
204-
private boolean isEnforcePostRequestsAndTimestamps = false;
204+
private boolean isPostRequestsAndTimestampsEnforced = false;
205205

206206
/**
207207
* Non-printable ASCII characters - numbers 0 to 31 and 127 decimal
@@ -287,9 +287,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
287287
, ConfigKey.Scope.Global);
288288
static final ConfigKey<Boolean> EnforcePostRequestsAndTimestamps = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED
289289
, Boolean.class
290-
, "enable.enforce.post.requests.and.timestamps"
290+
, "enforce.post.requests.and.timestamps"
291291
, "false"
292-
, "enables/disables whether the ApiServer only accepts state-changing POST requests and requests with timestamps."
292+
, "Enable/Disable whether the ApiServer should only accept POST requests for state-changing APIs and requests with timestamps."
293293
, false
294294
, ConfigKey.Scope.Global);
295295
private static final ConfigKey<String> JSONDefaultContentType = new ConfigKey<> (ConfigKey.CATEGORY_ADVANCED
@@ -449,7 +449,7 @@ protected void setupIntegrationPortListener(Integer apiPort) {
449449
public boolean start() {
450450
Security.addProvider(new BouncyCastleProvider());
451451
Integer apiPort = IntegrationAPIPort.value(); // api port, null by default
452-
isEnforcePostRequestsAndTimestamps = EnforcePostRequestsAndTimestamps.value();
452+
isPostRequestsAndTimestampsEnforced = EnforcePostRequestsAndTimestamps.value();
453453

454454
final Long snapshotLimit = ConcurrentSnapshotsThresholdPerHost.value();
455455
if (snapshotLimit == null || snapshotLimit <= 0) {
@@ -730,8 +730,8 @@ public String handleRequest(final Map params, final String responseType, final S
730730
}
731731

732732
@Override
733-
public boolean isEnforcePostRequestsAndTimestamps() {
734-
return isEnforcePostRequestsAndTimestamps;
733+
public boolean isPostRequestsAndTimestampsEnforced() {
734+
return isPostRequestsAndTimestampsEnforced;
735735
}
736736

737737
private String getBaseAsyncResponse(final long jobId, final BaseAsyncCmd cmd) {
@@ -1038,13 +1038,13 @@ public boolean verifyRequest(final Map<String, Object[]> requestParameters, fina
10381038
apiKey = apiKey.replaceAll(SANITIZATION_REGEX, "_");
10391039
logger.debug("Request expired -- ignoring ...sig [{}], apiKey [{}].", signature, apiKey);
10401040
return false;
1041-
} else if (isEnforcePostRequestsAndTimestamps && expiresTS.after(thresholdTime)) {
1041+
} else if (isPostRequestsAndTimestampsEnforced && expiresTS.after(thresholdTime)) {
10421042
signature = signature.replaceAll(SANITIZATION_REGEX, "_");
10431043
apiKey = apiKey.replaceAll(SANITIZATION_REGEX, "_");
10441044
logger.debug(String.format("Expiration parameter is set for too long -- ignoring ...sig [%s], apiKey [%s].", signature, apiKey));
10451045
return false;
10461046
}
1047-
} else if (isEnforcePostRequestsAndTimestamps) {
1047+
} else if (isPostRequestsAndTimestampsEnforced) {
10481048
// Force expiration parameter
10491049
logger.debug("Signature Version must be 3, and should be along with the Expires parameter -- ignoring request.");
10501050
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)