Skip to content

Commit 21a6bef

Browse files
committed
CLOUDSTACK-7989: Ignore Auth API calls in unauthenticated HTTP handlers
If an auth API call (such as login, logout) is called on unauthenticated port such as the 8096 integration server port, we need to ignore such API calls as calling auth APIs on 8096 is un-necessary and is undefined. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 9f4c267 commit 21a6bef

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.apache.cloudstack.api.ResponseObject;
6767
import org.apache.cloudstack.api.ResponseObject.ResponseView;
6868
import org.apache.cloudstack.api.ServerApiException;
69+
import org.apache.cloudstack.api.auth.APIAuthenticationManager;
6970
import org.apache.cloudstack.api.command.admin.account.ListAccountsCmdByAdmin;
7071
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
7172
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
@@ -204,6 +205,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
204205
private ConfigurationDao _configDao;
205206
@Inject
206207
private EntityManager _entityMgr;
208+
@Inject
209+
APIAuthenticationManager _authManager;
207210

208211
List<PluggableService> _pluggableServices;
209212
List<APIChecker> _apiAccessCheckers;
@@ -485,6 +488,10 @@ public String handleRequest(final Map params, final String responseType, final S
485488
}
486489
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent");
487490
} else {
491+
// Don't allow Login/Logout APIs to go past this point
492+
if (_authManager.getAPIAuthenticator(command[0]) != null) {
493+
return null;
494+
}
488495
final Map<String, String> paramMap = new HashMap<String, String>();
489496
final Set keys = params.keySet();
490497
final Iterator keysIter = keys.iterator();
@@ -522,12 +529,10 @@ public String handleRequest(final Map params, final String responseType, final S
522529
else
523530
buildAuditTrail(auditTrailSb, command[0], response);
524531
} else {
525-
if (!command[0].equalsIgnoreCase("login") && !command[0].equalsIgnoreCase("logout")) {
526-
final String errorString = "Unknown API command: " + command[0];
527-
s_logger.warn(errorString);
528-
auditTrailSb.append(" " + errorString);
529-
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString);
530-
}
532+
final String errorString = "Unknown API command: " + command[0];
533+
s_logger.warn(errorString);
534+
auditTrailSb.append(" " + errorString);
535+
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString);
531536
}
532537
}
533538
} catch (final InvalidParameterValueException ex) {

server/src/com/cloud/api/auth/APIAuthenticationManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public boolean start() {
5757
APICommand command = authenticator.getAnnotation(APICommand.class);
5858
if (command != null && !command.name().isEmpty()
5959
&& APIAuthenticator.class.isAssignableFrom(authenticator)) {
60-
s_authenticators.put(command.name(), authenticator);
60+
s_authenticators.put(command.name().toLowerCase(), authenticator);
6161
}
6262
}
6363
return true;
@@ -81,6 +81,7 @@ public List<Class<?>> getCommands() {
8181

8282
@Override
8383
public APIAuthenticator getAPIAuthenticator(String name) {
84+
name = name.toLowerCase();
8485
APIAuthenticator apiAuthenticator = null;
8586
if (s_authenticators != null && s_authenticators.containsKey(name)) {
8687
try {

0 commit comments

Comments
 (0)