FINERACT-1452: Disallow changing of password of specific users

This commit is contained in:
Petri Tuomola
2021-12-29 22:47:42 +01:00
committed by Michael Vorburger ⛑️
parent bf2b8296e9
commit 5efbd04173
4 changed files with 33 additions and 4 deletions
@@ -286,7 +286,7 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ
List<Client> clients = new ArrayList<>(Arrays.asList(client)); List<Client> clients = new ArrayList<>(Arrays.asList(client));
User user = new User(selfServiceRegistration.getUsername(), selfServiceRegistration.getPassword(), authorities); User user = new User(selfServiceRegistration.getUsername(), selfServiceRegistration.getPassword(), authorities);
AppUser appUser = new AppUser(client.getOffice(), user, allRoles, selfServiceRegistration.getEmail(), client.getFirstname(), AppUser appUser = new AppUser(client.getOffice(), user, allRoles, selfServiceRegistration.getEmail(), client.getFirstname(),
client.getLastname(), null, passwordNeverExpire, isSelfServiceUser, clients); client.getLastname(), null, passwordNeverExpire, isSelfServiceUser, clients, null);
this.userDomainService.create(appUser, true); this.userDomainService.create(appUser, true);
return appUser; return appUser;
@@ -123,6 +123,9 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
@JoinColumn(name = "appuser_id", referencedColumnName = "id", nullable = false) @JoinColumn(name = "appuser_id", referencedColumnName = "id", nullable = false)
private Set<AppUserClientMapping> appUserClientMappings = new HashSet<>(); private Set<AppUserClientMapping> appUserClientMappings = new HashSet<>();
@Column(name = "cannot_change_password", nullable = true)
private Boolean cannotChangePassword;
public static AppUser fromJson(final Office userOffice, final Staff linkedStaff, final Set<Role> allRoles, public static AppUser fromJson(final Office userOffice, final Staff linkedStaff, final Set<Role> allRoles,
final Collection<Client> clients, final JsonCommand command) { final Collection<Client> clients, final JsonCommand command) {
@@ -144,6 +147,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
final boolean userAccountNonExpired = true; final boolean userAccountNonExpired = true;
final boolean userCredentialsNonExpired = true; final boolean userCredentialsNonExpired = true;
final boolean userAccountNonLocked = true; final boolean userAccountNonLocked = true;
final boolean cannotChangePassword = false;
final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>(); final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("DUMMY_ROLE_NOT_USED_OR_PERSISTED_TO_AVOID_EXCEPTION")); authorities.add(new SimpleGrantedAuthority("DUMMY_ROLE_NOT_USED_OR_PERSISTED_TO_AVOID_EXCEPTION"));
@@ -158,7 +162,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
final boolean isSelfServiceUser = command.booleanPrimitiveValueOfParameterNamed(AppUserConstants.IS_SELF_SERVICE_USER); final boolean isSelfServiceUser = command.booleanPrimitiveValueOfParameterNamed(AppUserConstants.IS_SELF_SERVICE_USER);
return new AppUser(userOffice, user, allRoles, email, firstname, lastname, linkedStaff, passwordNeverExpire, isSelfServiceUser, return new AppUser(userOffice, user, allRoles, email, firstname, lastname, linkedStaff, passwordNeverExpire, isSelfServiceUser,
clients); clients, cannotChangePassword);
} }
protected AppUser() { protected AppUser() {
@@ -169,7 +173,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
public AppUser(final Office office, final User user, final Set<Role> roles, final String email, final String firstname, public AppUser(final Office office, final User user, final Set<Role> roles, final String email, final String firstname,
final String lastname, final Staff staff, final boolean passwordNeverExpire, final boolean isSelfServiceUser, final String lastname, final Staff staff, final boolean passwordNeverExpire, final boolean isSelfServiceUser,
final Collection<Client> clients) { final Collection<Client> clients, final Boolean cannotChangePassword) {
this.office = office; this.office = office;
this.email = email.trim(); this.email = email.trim();
this.username = user.getUsername().trim(); this.username = user.getUsername().trim();
@@ -187,6 +191,7 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
this.passwordNeverExpires = passwordNeverExpire; this.passwordNeverExpires = passwordNeverExpire;
this.isSelfServiceUser = isSelfServiceUser; this.isSelfServiceUser = isSelfServiceUser;
this.appUserClientMappings = createAppUserClientMappings(clients); this.appUserClientMappings = createAppUserClientMappings(clients);
this.cannotChangePassword = cannotChangePassword;
} }
public EnumOptionData organisationalRoleData() { public EnumOptionData organisationalRoleData() {
@@ -198,6 +203,10 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
} }
public void updatePassword(final String encodePassword) { public void updatePassword(final String encodePassword) {
if (cannotChangePassword != null && cannotChangePassword == true) {
throw new NoAuthorizationException("Password of this user may not be modified");
}
this.password = encodePassword; this.password = encodePassword;
this.firstTimeLoginRemaining = false; this.firstTimeLoginRemaining = false;
this.lastTimePasswordUpdated = DateUtils.getDateOfTenant(); this.lastTimePasswordUpdated = DateUtils.getDateOfTenant();
@@ -0,0 +1,20 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.
--
ALTER TABLE m_appuser ADD COLUMN cannot_change_password BOOLEAN NULL DEFAULT NULL;
@@ -83,7 +83,7 @@ public class StorageTest {
now); now);
AppUser appUser = new AppUser(null, new User("J.J.", "", true, true, true, true, Collections.emptyList()), null, "user@com", "John", AppUser appUser = new AppUser(null, new User("J.J.", "", true, true, true, true, Collections.emptyList()), null, "user@com", "John",
"", null, false, false, null); "", null, false, false, null, null);
NotificationMapper notificationMapper = new NotificationMapper(notification, appUser, false, now); NotificationMapper notificationMapper = new NotificationMapper(notification, appUser, false, now);