Skip to content

Commit 5ee61c2

Browse files
committed
Merge branch '4.19' into 4.20
2 parents b3dc402 + 52584d9 commit 5ee61c2

File tree

8 files changed

+161
-1
lines changed

8 files changed

+161
-1
lines changed

engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
4747

4848
void removeAccountFromProjects(long accountId);
4949

50+
void removeUserFromProjects(long userId);
51+
5052
boolean canUserModifyProject(long projectId, long accountId, long userId);
5153

5254
List<ProjectAccountVO> listUsersOrAccountsByRole(long id);

engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ public void removeAccountFromProjects(long accountId) {
192192
}
193193
}
194194

195+
@Override
196+
public void removeUserFromProjects(long userId) {
197+
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
198+
sc.setParameters("userId", userId);
199+
200+
int removedCount = remove(sc);
201+
if (removedCount > 0) {
202+
logger.debug(String.format("Removed user [%s] from %s project(s).", userId, removedCount));
203+
}
204+
}
205+
195206
@Override
196207
public boolean canUserModifyProject(long projectId, long accountId, long userId) {
197208
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.upgrade.dao;
18+
19+
import com.cloud.utils.exception.CloudRuntimeException;
20+
21+
import java.io.InputStream;
22+
import java.sql.Connection;
23+
24+
public class Upgrade41910to41920 implements DbUpgrade {
25+
26+
@Override
27+
public String[] getUpgradableVersionRange() {
28+
return new String[]{"4.19.1.0", "4.19.2.0"};
29+
}
30+
31+
@Override
32+
public String getUpgradedVersion() {
33+
return "4.19.2.0";
34+
}
35+
36+
@Override
37+
public boolean supportsRollingUpgrade() {
38+
return false;
39+
}
40+
41+
@Override
42+
public InputStream[] getPrepareScripts() {
43+
final String scriptFile = "META-INF/db/schema-41910to41920.sql";
44+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
45+
if (script == null) {
46+
throw new CloudRuntimeException("Unable to find " + scriptFile);
47+
}
48+
49+
return new InputStream[]{script};
50+
}
51+
52+
@Override
53+
public void performDataMigration(Connection conn) {
54+
}
55+
56+
@Override
57+
public InputStream[] getCleanupScripts() {
58+
final String scriptFile = "META-INF/db/schema-41910to41920-cleanup.sql";
59+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
60+
if (script == null) {
61+
throw new CloudRuntimeException("Unable to find " + scriptFile);
62+
}
63+
64+
return new InputStream[]{script};
65+
}
66+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
18+
--;
19+
-- Schema upgrade cleanup from 4.19.1.0 to 4.19.2.0
20+
--;
21+
22+
-- Delete `project_account` entries for users that were removed
23+
DELETE FROM `cloud`.`project_account` WHERE `user_id` IN (SELECT `id` FROM `cloud`.`user` WHERE `removed`);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
18+
--;
19+
-- Schema upgrade from 4.19.1.0 to 4.19.2.0
20+
--;

framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ private void migrateTemplateDeployAsIsDetails(Connection conn) throws SQLExcepti
656656
String sqlTemplateDeployAsIsDetails = "SELECT template_deploy_as_is_details.value " +
657657
"FROM template_deploy_as_is_details JOIN vm_instance " +
658658
"WHERE template_deploy_as_is_details.template_id = vm_instance.vm_template_id " +
659-
"vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";
659+
"AND vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";
660660
try (PreparedStatement selectPstmt = conn.prepareStatement("SELECT id, vm_id, name, value FROM user_vm_deploy_as_is_details");
661661
ResultSet rs = selectPstmt.executeQuery();
662662
PreparedStatement updatePstmt = conn.prepareStatement("UPDATE user_vm_deploy_as_is_details SET value=? WHERE id=?")

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,8 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
15001500
* <ul>
15011501
* <li> If 'password' is blank, we throw an {@link InvalidParameterValueException};
15021502
* <li> If 'current password' is not provided and user is not an Admin, we throw an {@link InvalidParameterValueException};
1503+
* <li> If the user whose password is being changed has a source equal to {@link User.Source#SAML2}, {@link User.Source#SAML2DISABLED} or {@link User.Source#LDAP},
1504+
* we throw an {@link InvalidParameterValueException};
15031505
* <li> If a normal user is calling this method, we use {@link #validateCurrentPassword(UserVO, String)} to check if the provided old password matches the database one;
15041506
* </ul>
15051507
*
@@ -1514,6 +1516,12 @@ public void validateUserPasswordAndUpdateIfNeeded(String newPassword, UserVO use
15141516
throw new InvalidParameterValueException("Password cannot be empty or blank.");
15151517
}
15161518

1519+
User.Source userSource = user.getSource();
1520+
if (userSource == User.Source.SAML2 || userSource == User.Source.SAML2DISABLED || userSource == User.Source.LDAP) {
1521+
logger.warn(String.format("Unable to update the password for user [%d], as its source is [%s].", user.getId(), user.getSource().toString()));
1522+
throw new InvalidParameterValueException("CloudStack does not support updating passwords for SAML or LDAP users. Please contact your cloud administrator for assistance.");
1523+
}
1524+
15171525
passwordPolicy.verifyIfPasswordCompliesWithPasswordPolicies(newPassword, user.getUsername(), getAccount(user.getAccountId()).getDomainId());
15181526

15191527
Account callingAccount = getCurrentCallingAccount();

server/src/test/java/com/cloud/user/AccountManagerImplTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,36 @@ public void validateUserPasswordAndUpdateIfNeededTestIfVerifyIfPasswordCompliesW
874874
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword, false);
875875
}
876876

877+
@Test(expected = InvalidParameterValueException.class)
878+
public void validateUserPasswordAndUpdateIfNeededTestSaml2UserShouldNotBeAllowedToUpdateTheirPassword() {
879+
String newPassword = "newPassword";
880+
String currentPassword = "theCurrentPassword";
881+
882+
Mockito.when(userVoMock.getSource()).thenReturn(User.Source.SAML2);
883+
884+
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword, false);
885+
}
886+
887+
@Test(expected = InvalidParameterValueException.class)
888+
public void validateUserPasswordAndUpdateIfNeededTestSaml2DisabledUserShouldNotBeAllowedToUpdateTheirPassword() {
889+
String newPassword = "newPassword";
890+
String currentPassword = "theCurrentPassword";
891+
892+
Mockito.when(userVoMock.getSource()).thenReturn(User.Source.SAML2DISABLED);
893+
894+
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword, false);
895+
}
896+
897+
@Test(expected = InvalidParameterValueException.class)
898+
public void validateUserPasswordAndUpdateIfNeededTestLdapUserShouldNotBeAllowedToUpdateTheirPassword() {
899+
String newPassword = "newPassword";
900+
String currentPassword = "theCurrentPassword";
901+
902+
Mockito.when(userVoMock.getSource()).thenReturn(User.Source.LDAP);
903+
904+
accountManagerImpl.validateUserPasswordAndUpdateIfNeeded(newPassword, userVoMock, currentPassword, false);
905+
}
906+
877907
private String configureUserMockAuthenticators(String newPassword) {
878908
accountManagerImpl._userPasswordEncoders = new ArrayList<>();
879909
UserAuthenticator authenticatorMock1 = Mockito.mock(UserAuthenticator.class);

0 commit comments

Comments
 (0)