FINERACT-1060: Stop delete / update of system user

This commit is contained in:
Petri Tuomola
2020-07-03 15:35:33 +02:00
committed by Michael Vorburger ⛑️
parent c92e926d6c
commit 551819ee18
5 changed files with 58 additions and 3 deletions
@@ -264,6 +264,12 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
final String usernameParamName = "username";
if (command.isChangeInStringParameterNamed(usernameParamName, this.username)) {
// TODO Remove this check once we are identifying system user based on user ID
if (isSystemUser()) {
throw new NoAuthorizationException("User name of current system user may not be modified");
}
final String newValue = command.stringValueOfParameterNamed(usernameParamName);
actualChanges.put(usernameParamName, newValue);
this.username = newValue;
@@ -343,6 +349,10 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
* Any fields with unique constraints and prepended with id of record.
*/
public void delete() {
if (isSystemUser()) {
throw new NoAuthorizationException("User configured as the system user cannot be deleted");
}
this.deleted = true;
this.enabled = false;
this.accountNonExpired = false;
@@ -355,6 +365,15 @@ public class AppUser extends AbstractPersistableCustom implements PlatformUser {
return this.deleted;
}
public boolean isSystemUser() {
// TODO Determine system user by ID not by user name
if (this.username.equals(AppUserConstants.SYSTEM_USER_NAME)) {
return true;
}
return false;
}
@Override
public Collection<GrantedAuthority> getAuthorities() {
return populateGrantedAuthorities();
@@ -19,6 +19,7 @@
package org.apache.fineract.useradministration.domain;
import org.apache.fineract.useradministration.exception.UserNotFoundException;
import org.apache.fineract.useradministration.service.AppUserConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -33,10 +34,9 @@ public class AppUserRepositoryWrapper {
}
public AppUser fetchSystemUser() {
String userName = "system";
AppUser user = this.appUserRepository.findAppUserByName(userName);
AppUser user = this.appUserRepository.findAppUserByName(AppUserConstants.SYSTEM_USER_NAME);
if (user == null) {
throw new UserNotFoundException(userName);
throw new UserNotFoundException(AppUserConstants.SYSTEM_USER_NAME);
}
return user;
}
@@ -24,4 +24,6 @@ public class AppUserConstants {
public static final String IS_SELF_SERVICE_USER = "isSelfServiceUser";
public static final String CLIENTS = "clients";
// TODO: Remove hard coding of system user name and make this a configurable parameter
public static final String SYSTEM_USER_NAME = "system";
}