Skip to content

Commit 57e54ce

Browse files
Merge branch 'main' into healthcheck-main
2 parents cb24461 + 554ea22 commit 57e54ce

File tree

29 files changed

+820
-109
lines changed

29 files changed

+820
-109
lines changed

api/src/main/java/com/cloud/user/AccountService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ User createUser(String userName, String password, String firstName, String lastN
116116

117117
void checkAccess(Account account, AccessType accessType, boolean sameOwner, String apiName, ControlledEntity... entities) throws PermissionDeniedException;
118118

119+
void validateAccountHasAccessToResource(Account account, AccessType accessType, Object resource);
120+
119121
Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly);
120122

121123
/**

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,9 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
20292029
MigrationOptions.Type migrationType = decideMigrationTypeAndCopyTemplateIfNeeded(destHost, vmInstance, srcVolumeInfo, sourceStoragePool, destStoragePool, destDataStore);
20302030
migrateNonSharedInc = migrateNonSharedInc || MigrationOptions.Type.LinkedClone.equals(migrationType);
20312031

2032+
MigrationOptions.Type migrationType = decideMigrationTypeAndCopyTemplateIfNeeded(destHost, vmInstance, srcVolumeInfo, sourceStoragePool, destStoragePool, destDataStore);
2033+
migrateNonSharedInc = migrateNonSharedInc || MigrationOptions.Type.LinkedClone.equals(migrationType);
2034+
20322035
VolumeVO destVolume = duplicateVolumeOnAnotherStorage(srcVolume, destStoragePool);
20332036
VolumeInfo destVolumeInfo = _volumeDataFactory.getVolume(destVolume.getId(), destDataStore);
20342037

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
import javax.inject.Inject;
2323

24+
import com.cloud.user.Account;
25+
26+
import org.apache.cloudstack.api.ACL;
2427
import org.apache.cloudstack.api.APICommand;
2528
import org.apache.cloudstack.api.ApiConstants;
2629
import org.apache.cloudstack.api.BaseCmd;
@@ -40,6 +43,7 @@ public class QuotaBalanceCmd extends BaseCmd {
4043
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which statement needs to be generated")
4144
private String accountName;
4245

46+
@ACL
4347
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "If domain Id is given and the caller is domain admin then the statement is generated for domain.")
4448
private Long domainId;
4549

@@ -51,6 +55,7 @@ public class QuotaBalanceCmd extends BaseCmd {
5155
ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS)
5256
private Date startDate;
5357

58+
@ACL
5459
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
5560
private Long accountId;
5661

@@ -104,7 +109,14 @@ public void setStartDate(Date startDate) {
104109

105110
@Override
106111
public long getEntityOwnerId() {
107-
return _accountService.getActiveAccountByName(accountName, domainId).getAccountId();
112+
if (accountId != null) {
113+
return accountId;
114+
}
115+
Account account = _accountService.getActiveAccountByName(accountName, domainId);
116+
if (account != null) {
117+
return account.getAccountId();
118+
}
119+
return Account.ACCOUNT_ID_SYSTEM;
108120
}
109121

110122
@Override

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.cloud.user.Account;
2020

21+
import org.apache.cloudstack.api.ACL;
2122
import org.apache.cloudstack.api.APICommand;
2223
import org.apache.cloudstack.api.ApiConstants;
2324
import org.apache.cloudstack.api.ApiErrorCode;
@@ -46,6 +47,7 @@ public class QuotaCreditsCmd extends BaseCmd {
4647
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which quota credits need to be added")
4748
private String accountName;
4849

50+
@ACL
4951
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
5052
private Long domainId;
5153

@@ -130,6 +132,10 @@ public void execute() {
130132

131133
@Override
132134
public long getEntityOwnerId() {
135+
Account account = _accountService.getActiveAccountByName(accountName, domainId);
136+
if (account != null) {
137+
return account.getAccountId();
138+
}
133139
return Account.ACCOUNT_ID_SYSTEM;
134140
}
135141

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import javax.inject.Inject;
2323

24+
import org.apache.cloudstack.api.ACL;
2425
import org.apache.cloudstack.api.APICommand;
2526
import org.apache.cloudstack.api.ApiConstants;
2627
import org.apache.cloudstack.api.BaseCmd;
@@ -42,6 +43,7 @@ public class QuotaStatementCmd extends BaseCmd {
4243
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Optional, Account Id for which statement needs to be generated")
4344
private String accountName;
4445

46+
@ACL
4547
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Optional, If domain Id is given and the caller is domain admin then the statement is generated for domain.")
4648
private Long domainId;
4749

@@ -56,6 +58,7 @@ public class QuotaStatementCmd extends BaseCmd {
5658
@Parameter(name = ApiConstants.TYPE, type = CommandType.INTEGER, description = "List quota usage records for the specified usage type")
5759
private Integer usageType;
5860

61+
@ACL
5962
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
6063
private Long accountId;
6164

@@ -112,6 +115,9 @@ public void setStartDate(Date startDate) {
112115

113116
@Override
114117
public long getEntityOwnerId() {
118+
if (accountId != null) {
119+
return accountId;
120+
}
115121
Account activeAccountByName = _accountService.getActiveAccountByName(accountName, domainId);
116122
if (activeAccountByName != null) {
117123
return activeAccountByName.getAccountId();

plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/MockAccountManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ public void checkAccess(Account account, AccessType accessType, boolean sameOwne
454454
// TODO Auto-generated method stub
455455
}
456456

457+
@Override
458+
public void validateAccountHasAccessToResource(Account account, AccessType accessType, Object resource) {
459+
// TODO Auto-generated method stub
460+
}
461+
457462
@Override
458463
public Long finalyzeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly) {
459464
// TODO Auto-generated method stub

plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO;
4747
import org.apache.cloudstack.storage.object.BaseObjectStoreDriverImpl;
4848
import org.apache.cloudstack.storage.object.BucketObject;
49-
import org.apache.logging.log4j.LogManager;
50-
import org.apache.logging.log4j.Logger;
5149
import org.twonote.rgwadmin4j.RgwAdmin;
5250
import org.twonote.rgwadmin4j.RgwAdminBuilder;
5351
import org.twonote.rgwadmin4j.model.BucketInfo;
@@ -62,7 +60,6 @@
6260
import java.util.HashMap;
6361

6462
public class CephObjectStoreDriverImpl extends BaseObjectStoreDriverImpl {
65-
private static final Logger s_logger = LogManager.getLogger(CephObjectStoreDriverImpl.class);
6663

6764
@Inject
6865
AccountDao _accountDao;
@@ -168,7 +165,7 @@ public void setBucketPolicy(BucketTO bucket, String policy, long storeId) {
168165
String policyConfig;
169166

170167
if (policy.equalsIgnoreCase("public")) {
171-
s_logger.debug("Setting public policy on bucket " + bucket.getName());
168+
logger.debug("Setting public policy on bucket " + bucket.getName());
172169
StringBuilder builder = new StringBuilder();
173170
builder.append("{\n");
174171
builder.append(" \"Statement\": [\n");
@@ -192,7 +189,7 @@ public void setBucketPolicy(BucketTO bucket, String policy, long storeId) {
192189
builder.append("}\n");
193190
policyConfig = builder.toString();
194191
} else {
195-
s_logger.debug("Setting private policy on bucket " + bucket.getName());
192+
logger.debug("Setting private policy on bucket " + bucket.getName());
196193
policyConfig = "{\"Version\":\"2012-10-17\",\"Statement\":[]}";
197194
}
198195

@@ -218,15 +215,15 @@ public boolean createUser(long accountId, long storeId) {
218215
RgwAdmin rgwAdmin = getRgwAdminClient(storeId);
219216
String username = account.getUuid();
220217

221-
s_logger.debug("Attempting to create Ceph RGW user for account " + account.getAccountName() + " with UUID " + username);
218+
logger.debug("Attempting to create Ceph RGW user for account " + account.getAccountName() + " with UUID " + username);
222219
try {
223220
Optional<User> user = rgwAdmin.getUserInfo(username);
224221
if (user.isPresent()) {
225-
s_logger.info("User already exists in Ceph RGW: " + username);
222+
logger.info("User already exists in Ceph RGW: " + username);
226223
return true;
227224
}
228225
} catch (Exception e) {
229-
s_logger.debug("User does not exist. Creating user in Ceph RGW: " + username);
226+
logger.debug("User does not exist. Creating user in Ceph RGW: " + username);
230227
}
231228

232229
try {

plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CephObjectStoreLifeCycleImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
public class CephObjectStoreLifeCycleImpl implements ObjectStoreLifeCycle {
4141

42-
private static final Logger s_logger = LogManager.getLogger(CephObjectStoreLifeCycleImpl.class);
42+
private Logger logger = LogManager.getLogger(CephObjectStoreLifeCycleImpl.class);
4343

4444
@Inject
4545
ObjectStoreHelper objectStoreHelper;
@@ -72,7 +72,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
7272
objectStoreParameters.put("accesskey", accessKey);
7373
objectStoreParameters.put("secretkey", secretKey);
7474

75-
s_logger.info("Attempting to connect to Ceph RGW at " + url + " with access key " + accessKey);
75+
logger.info("Attempting to connect to Ceph RGW at " + url + " with access key " + accessKey);
7676

7777
RgwAdmin rgwAdmin = new RgwAdminBuilder()
7878
.accessKey(accessKey)
@@ -81,10 +81,10 @@ public DataStore initialize(Map<String, Object> dsInfos) {
8181
.build();
8282
try {
8383
List<String> buckets = rgwAdmin.listBucket();
84-
s_logger.debug("Found " + buckets + " buckets at Ceph RGW: " + url);
85-
s_logger.info("Successfully connected to Ceph RGW: " + url);
84+
logger.debug("Found " + buckets + " buckets at Ceph RGW: " + url);
85+
logger.info("Successfully connected to Ceph RGW: " + url);
8686
} catch (Exception e) {
87-
s_logger.debug("Error while initializing Ceph RGW Object Store: " + e.getMessage());
87+
logger.debug("Error while initializing Ceph RGW Object Store: " + e.getMessage());
8888
throw new RuntimeException("Error while initializing Ceph RGW Object Store. Invalid credentials or URL");
8989
}
9090

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.cloudstack.saml.SAML2AuthManager;
4848
import org.apache.cloudstack.saml.SAMLUtils;
4949

50+
import com.cloud.api.ApiServer;
5051
import com.cloud.api.response.ApiResponseSerializer;
5152
import com.cloud.domain.Domain;
5253
import com.cloud.domain.dao.DomainDao;
@@ -59,6 +60,8 @@
5960
import com.cloud.user.dao.UserDao;
6061
import com.cloud.utils.HttpUtils;
6162

63+
import org.apache.commons.lang3.EnumUtils;
64+
6265
@APICommand(name = "listAndSwitchSamlAccount", description = "Lists and switches to other SAML accounts owned by the SAML user", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
6366
public class ListAndSwitchSAMLAccountCmd extends BaseCmd implements APIAuthenticator {
6467

@@ -102,7 +105,9 @@ public String authenticate(final String command, final Map<String, Object[]> par
102105
params, responseType));
103106
}
104107

105-
if (!HttpUtils.validateSessionKey(session, params, req.getCookies(), ApiConstants.SESSIONKEY)) {
108+
HttpUtils.ApiSessionKeyCheckOption sessionKeyCheckOption = EnumUtils.getEnumIgnoreCase(HttpUtils.ApiSessionKeyCheckOption.class,
109+
ApiServer.ApiSessionKeyCheckLocations.value(), HttpUtils.ApiSessionKeyCheckOption.CookieAndParameter);
110+
if (!HttpUtils.validateSessionKey(session, params, req.getCookies(), ApiConstants.SESSIONKEY, sessionKeyCheckOption)) {
106111
throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, _apiServer.getSerializedApiError(ApiErrorCode.UNAUTHORIZED.getHttpCode(),
107112
"Unauthorized session, please re-login",
108113
params, responseType));

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public interface SAML2AuthManager extends PluggableAPIAuthenticator, PluggableSe
7373
ConfigKey<Boolean> SAMLCheckSignature = new ConfigKey<Boolean>("Advanced", Boolean.class, "saml2.check.signature", "true",
7474
"When enabled (default and recommended), SAML2 signature checks are enforced and lack of signature in the SAML SSO response will cause login exception. Disabling this is not advisable but provided for backward compatibility for users who are able to accept the risks.", false);
7575

76+
ConfigKey<String> SAMLUserSessionKeyPathAttribute = new ConfigKey<String>("Advanced", String.class, "saml2.user.sessionkey.path", "",
77+
"The Path attribute of sessionkey cookie when SAML users have logged in. If not set, it will be set to the path of SAML redirection URL (saml2.redirect.url).", true);
78+
7679
SAMLProviderMetadata getSPMetadata();
7780
SAMLProviderMetadata getIdPMetadata(String entityId);
7881
Collection<SAMLProviderMetadata> getAllIdPMetadata();

0 commit comments

Comments
 (0)