Skip to content

Commit 5ff2f17

Browse files
committed
Merge branch '4.11'
2 parents f8b6375 + 9a13227 commit 5ff2f17

7 files changed

Lines changed: 60 additions & 9 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.exception;
18+
19+
import com.cloud.utils.SerialVersionUID;
20+
21+
public class UnavailableCommandException extends PermissionDeniedException {
22+
23+
private static final long serialVersionUID = SerialVersionUID.UnavailableCommandException;
24+
25+
protected UnavailableCommandException() {
26+
super();
27+
}
28+
29+
public UnavailableCommandException(String msg) {
30+
super(msg);
31+
}
32+
33+
public UnavailableCommandException(String msg, Throwable cause) {
34+
super(msg, cause);
35+
}
36+
}

plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28+
import com.cloud.exception.UnavailableCommandException;
2829
import org.apache.cloudstack.api.APICommand;
2930

3031
import com.cloud.exception.PermissionDeniedException;
@@ -53,8 +54,7 @@ protected DynamicRoleBasedAPIAccessChecker() {
5354
}
5455

5556
private void denyApiAccess(final String commandName) throws PermissionDeniedException {
56-
throw new PermissionDeniedException("The API does not exist or is blacklisted for the account's role. " +
57-
"The account with is not allowed to request the api: " + commandName);
57+
throw new PermissionDeniedException("The API " + commandName + " is blacklisted for the account's role.");
5858
}
5959

6060
public boolean isDisabled() {
@@ -99,8 +99,7 @@ public boolean checkAccess(User user, String commandName) throws PermissionDenie
9999
}
100100

101101
// Default deny all
102-
denyApiAccess(commandName);
103-
return false;
102+
throw new UnavailableCommandException("The API " + commandName + " does not exist or is not available for this account.");
104103
}
105104

106105
public void addApiToRoleBasedAnnotationsMap(final RoleType roleType, final String commandName) {

plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28+
import com.cloud.exception.UnavailableCommandException;
2829
import org.apache.log4j.Logger;
2930

3031
import org.apache.cloudstack.api.APICommand;
@@ -45,6 +46,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
4546
protected static final Logger LOGGER = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class);
4647

4748
private Set<String> commandPropertyFiles = new HashSet<String>();
49+
private Set<String> commandNames = new HashSet<String>();
4850
private Set<String> commandsPropertiesOverrides = new HashSet<String>();
4951
private Map<RoleType, Set<String>> commandsPropertiesRoleBasedApisMap = new HashMap<RoleType, Set<String>>();
5052
private Map<RoleType, Set<String>> annotationRoleBasedApisMap = new HashMap<RoleType, Set<String>>();
@@ -87,7 +89,11 @@ public boolean checkAccess(User user, String commandName) throws PermissionDenie
8789
return true;
8890
}
8991

90-
throw new PermissionDeniedException("The API does not exist or is blacklisted. Role type=" + roleType.toString() + " is not allowed to request the api: " + commandName);
92+
if (commandNames.contains(commandName)) {
93+
throw new PermissionDeniedException("The API is blacklisted. Role type=" + roleType.toString() + " is not allowed to request the api: " + commandName);
94+
} else {
95+
throw new UnavailableCommandException("The API " + commandName + " does not exist or is not available for this account.");
96+
}
9197
}
9298

9399
@Override
@@ -110,6 +116,9 @@ public boolean start() {
110116
if (!commands.contains(command.name()))
111117
commands.add(command.name());
112118
}
119+
if (!commandNames.contains(command.name())) {
120+
commandNames.add(command.name());
121+
}
113122
}
114123
}
115124
return super.start();
@@ -119,6 +128,9 @@ private void processMapping(Map<String, String> configMap) {
119128
for (Map.Entry<String, String> entry : configMap.entrySet()) {
120129
String apiName = entry.getKey();
121130
String roleMask = entry.getValue();
131+
if (!commandNames.contains(apiName)) {
132+
commandNames.add(apiName);
133+
}
122134
commandsPropertiesOverrides.add(apiName);
123135
try {
124136
short cmdPermissions = Short.parseShort(roleMask);

scripts/vm/network/security_group.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,7 @@ def addFWFramework(brname):
11631163
execute("sysctl -w net.bridge.bridge-nf-call-iptables=1")
11641164
execute("sysctl -w net.bridge.bridge-nf-call-ip6tables=1")
11651165
except:
1166-
logging.debug("failed to turn on bridge netfilter")
1167-
return False
1166+
logging.warn("failed to turn on bridge netfilter")
11681167

11691168
brfw = getBrfw(brname)
11701169
try:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.cloud.exception.RequestLimitException;
3535
import com.cloud.exception.ResourceAllocationException;
3636
import com.cloud.exception.ResourceUnavailableException;
37+
import com.cloud.exception.UnavailableCommandException;
3738
import com.cloud.user.Account;
3839
import com.cloud.user.AccountManager;
3940
import com.cloud.user.DomainManager;
@@ -958,6 +959,9 @@ private boolean commandAvailable(final InetAddress remoteAddress, final String c
958959
} catch (final RequestLimitException ex) {
959960
s_logger.debug(ex.getMessage());
960961
throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage());
962+
} catch (final UnavailableCommandException ex) {
963+
s_logger.debug(ex.getMessage());
964+
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());
961965
} catch (final PermissionDeniedException ex) {
962966
final String errorMessage = "The given command '" + commandName + "' either does not exist, is not available" +
963967
" for user, or not available from ip address '" + remoteAddress + "'.";

test/integration/smoke/test_routers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ def test_04_restart_network_wo_cleanup(self):
521521
)
522522
if str(result[3]) == "min,":
523523
self.assertEqual(
524-
(int(result[2]) < 3),
524+
(int(result[2]) < 20),
525525
True,
526-
"Check uptime is less than 3 mins or not"
526+
"Check uptime is less than 20 mins or not"
527527
)
528528
else:
529529
self.assertEqual(

utils/src/main/java/com/cloud/utils/SerialVersionUID.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ public interface SerialVersionUID {
6868
public static final long NioConnectionException = Base | 0x2c;
6969
public static final long TaskExecutionException = Base | 0x2d;
7070
public static final long SnapshotBackupException = Base | 0x2e;
71+
public static final long UnavailableCommandException = Base | 0x2f;
7172
}

0 commit comments

Comments
 (0)