Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 1657fd5

Browse files
committed
FF-255 Added remaining logic.
1 parent 312a797 commit 1657fd5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/de/filefighter/rest/domain/user/business/UserBusinessService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ public void updateUser(long userId, UserRegisterForm userToUpdate, User authenti
162162
if (null == userEntityToUpdate)
163163
throw new UserNotUpdatedException("User does not exist, use register endpoint.");
164164

165+
if(Arrays.stream(userEntityToUpdate.getGroupIds()).asDoubleStream().anyMatch(id -> id == Groups.SYSTEM.getGroupId()))
166+
throw new UserNotUpdatedException("Runtime users cannot be modified.");
167+
165168
Update newUpdate = new Update();
166169

167170
boolean changesWereMade = updateUserName(newUpdate, userToUpdate.getUsername());
168-
169171
boolean usernameIsValid = stringIsValid(userToUpdate.getUsername());
170172
String lowerCaseUsername = usernameIsValid ? userToUpdate.getUsername().toLowerCase() : userEntityToUpdate.getLowercaseUsername();
171173
boolean passwordWasUpdated = updatePassword(newUpdate, userToUpdate.getPassword(), userToUpdate.getConfirmationPassword(), lowerCaseUsername);
@@ -186,6 +188,8 @@ private boolean updateGroups(Update newUpdate, long[] groupIds, boolean authenti
186188
if (null != groupIds && groupIds.length != 0) {
187189
try {
188190
for (Groups group : groupRepository.getGroupsByIds(groupIds)) {
191+
if( group == Groups.SYSTEM)
192+
throw new UserNotUpdatedException("Users cannot be added to the '"+ Groups.SYSTEM.getDisplayName()+"' Group");
189193
if (group == Groups.ADMIN && !authenticatedUserIsAdmin)
190194
throw new UserNotUpdatedException("Only admins can add users to group " + Groups.ADMIN.getDisplayName() + ".");
191195
}

0 commit comments

Comments
 (0)