|
29 | 29 | import com.cloud.exception.CloudAuthenticationException; |
30 | 30 | import com.cloud.exception.InsufficientCapacityException; |
31 | 31 | import com.cloud.exception.InvalidParameterValueException; |
| 32 | +import com.cloud.exception.OriginDeniedException; |
32 | 33 | import com.cloud.exception.PermissionDeniedException; |
33 | 34 | import com.cloud.exception.RequestLimitException; |
34 | 35 | import com.cloud.exception.ResourceAllocationException; |
@@ -843,11 +844,7 @@ public boolean verifyRequest(final Map<String, Object[]> requestParameters, fina |
843 | 844 | if (userId != null) { |
844 | 845 | final User user = ApiDBUtils.findUserById(userId); |
845 | 846 |
|
846 | | - if (!commandAvailable(remoteAddress, commandName, user)) { |
847 | | - return false; |
848 | | - } |
849 | | - |
850 | | - return true; |
| 847 | + return commandAvailable(remoteAddress, commandName, user); |
851 | 848 | } else { |
852 | 849 | // check against every available command to see if the command exists or not |
853 | 850 | if (!s_apiNameCmdClassMap.containsKey(commandName) && !commandName.equals("login") && !commandName.equals("logout")) { |
@@ -989,7 +986,11 @@ private boolean commandAvailable(final InetAddress remoteAddress, final String c |
989 | 986 | throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage()); |
990 | 987 | } catch (final PermissionDeniedException ex) { |
991 | 988 | final String errorMessage = "The given command '" + commandName + "' either does not exist, is not available" + |
992 | | - " for user, or not available from ip address '" + remoteAddress + "'."; |
| 989 | + " for user."; |
| 990 | + throw new ServerApiException(ApiErrorCode.UNAUTHORIZED , errorMessage); |
| 991 | + } catch (final OriginDeniedException ex) { |
| 992 | + // in this case we can remove the session with extreme prejudice |
| 993 | + final String errorMessage = "The user '" + user.getUsername() + "' is not allowed to execute commands from ip address '" + remoteAddress.getHostName() + "'."; |
993 | 994 | s_logger.debug(errorMessage); |
994 | 995 | return false; |
995 | 996 | } |
@@ -1163,7 +1164,7 @@ private void checkCommandAvailable(final User user, final String commandName, fi |
1163 | 1164 | s_logger.debug("CIDRs from which account '" + account.toString() + "' is allowed to perform API calls: " + accessAllowedCidrs); |
1164 | 1165 | if (!NetUtils.isIpInCidrList(remoteAddress, accessAllowedCidrs.split(","))) { |
1165 | 1166 | s_logger.warn("Request by account '" + account.toString() + "' was denied since " + remoteAddress + " does not match " + accessAllowedCidrs); |
1166 | | - throw new PermissionDeniedException("Calls for domain '" + account.getAccountName() + "' are not allowed from ip address '" + remoteAddress.getHostAddress()); |
| 1167 | + throw new OriginDeniedException("Calls from disallowed origin", account, remoteAddress); |
1167 | 1168 | } |
1168 | 1169 | } |
1169 | 1170 |
|
|
0 commit comments