Skip to content

Commit b82dfce

Browse files
committed
Fixes #640
1 parent 2a6946f commit b82dfce

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

client/src/locale/en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const en = {
193193
andMore: "And {{nbr}} more.. Check the list of current users for more details."
194194
},
195195
noProvisioning: "Users added to this role, won't have immediate access to this application. See the <a href=' https://servicedesk.surf.nl/wiki/spaces/IAM/pages/128910179/Applicatie+aansluiten+op+SURFconext+Invite' target='_blank'>wiki</a> for more information",
196-
userRolesPresent: "You are not allowed to delete this role, as {{nbr}} user(s) have this role. You must first delete them."
196+
userRolesPresent: "You are not allowed to delete this role, as {{nbr}} user(s) have this role. You must first delete them from this role."
197197
},
198198
applications: {
199199
title: "Access Roles for this application ({{nbr}})",

client/src/locale/nl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const nl = {
193193
andMore: "En nog {{nbr}} meer.. Bekijk de lijst van huidige gebruikers voor meer details."
194194
},
195195
noProvisioning: "Gebruikers die toegevoegd worden aan deze rol, hebben niet gelijk toegang tot deze applicatie. Zie de <a href=' https://servicedesk.surf.nl/wiki/spaces/IAM/pages/128910179/Applicatie+aansluiten+op+SURFconext+Invite' target='_blank'>wiki</a> voor meer informatie.",
196-
userRolesPresent: "Je mag deze rol niet verwijderen, omdat {{nbr}} gebruiker(s) deze rol hebben. Je moet ze eerst verwijderen."
196+
userRolesPresent: "Je mag deze rol niet verwijderen, omdat {{nbr}} gebruiker(s) deze rol hebben. Je moet deze gebruikers eerst verwijderen uit deze rol."
197197
},
198198
applications: {
199199
title: "Toegangsrollen voor deze applicatie ({{nbr}})",

server/src/main/java/invite/api/RoleController.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
import invite.logging.Event;
88
import invite.manage.EntityType;
99
import invite.manage.Manage;
10-
import invite.model.*;
10+
import invite.model.Application;
11+
import invite.model.ApplicationUsage;
12+
import invite.model.Authority;
13+
import invite.model.Role;
14+
import invite.model.RoleRequest;
15+
import invite.model.User;
16+
import invite.model.UserRole;
1117
import invite.provision.ProvisioningService;
1218
import invite.provision.scim.GroupURN;
1319
import invite.repository.ApplicationRepository;
@@ -33,12 +39,27 @@
3339
import org.springframework.transaction.annotation.Transactional;
3440
import org.springframework.util.StringUtils;
3541
import org.springframework.validation.annotation.Validated;
36-
import org.springframework.web.bind.annotation.*;
42+
import org.springframework.web.bind.annotation.DeleteMapping;
43+
import org.springframework.web.bind.annotation.GetMapping;
44+
import org.springframework.web.bind.annotation.PathVariable;
45+
import org.springframework.web.bind.annotation.PostMapping;
46+
import org.springframework.web.bind.annotation.PutMapping;
47+
import org.springframework.web.bind.annotation.RequestBody;
48+
import org.springframework.web.bind.annotation.RequestMapping;
49+
import org.springframework.web.bind.annotation.RequestParam;
50+
import org.springframework.web.bind.annotation.RestController;
3751

3852
import java.net.URLDecoder;
3953
import java.nio.charset.Charset;
4054
import java.sql.SQLTransactionRollbackException;
41-
import java.util.*;
55+
import java.util.ArrayList;
56+
import java.util.Collection;
57+
import java.util.List;
58+
import java.util.Map;
59+
import java.util.Objects;
60+
import java.util.Optional;
61+
import java.util.Set;
62+
import java.util.UUID;
4263
import java.util.stream.Collectors;
4364

4465
import static invite.SwaggerOpenIdConfig.API_TOKENS_SCHEME_NAME;
@@ -57,6 +78,7 @@ public class RoleController implements ApplicationResource {
5778
private static final Log LOG = LogFactory.getLog(RoleController.class);
5879

5980
private final RoleRepository roleRepository;
81+
private final UserRoleRepository userRoleRepository;
6082
@Getter
6183
private final ApplicationRepository applicationRepository;
6284
@Getter
@@ -67,12 +89,14 @@ public class RoleController implements ApplicationResource {
6789
private final String groupUrnPrefix;
6890

6991
public RoleController(RoleRepository roleRepository,
92+
UserRoleRepository userRoleRepository,
7093
ApplicationRepository applicationRepository,
7194
ApplicationUsageRepository applicationUsageRepository,
7295
Manage manage,
7396
ProvisioningService provisioningService,
7497
@Value("${voot.group_urn_domain}") String groupUrnPrefix) {
7598
this.roleRepository = roleRepository;
99+
this.userRoleRepository = userRoleRepository;
76100
this.applicationRepository = applicationRepository;
77101
this.applicationUsageRepository = applicationUsageRepository;
78102
this.manage = manage;
@@ -204,6 +228,15 @@ public ResponseEntity<Void> deleteRole(@PathVariable("id") Long id,
204228
@Parameter(hidden = true) User user) {
205229
Role role = roleRepository.findById(id).orElseThrow(() -> new NotFoundException("Role not found"));
206230

231+
List<UserRole> userRoles = this.userRoleRepository.findByRole(role);
232+
if (!userRoles.isEmpty() && !user.isSuperUser()) {
233+
throw new UserRestrictionException(
234+
String.format("User %s is not allowed to delete role %s when there are still %s userRoles",
235+
user.getEmail(),
236+
role.getName(),
237+
userRoles.size()));
238+
}
239+
207240
LOG.debug(String.format("Delete role %s by user %s", role.getName(), user.getEduPersonPrincipalName()));
208241

209242
manage.addManageMetaData(List.of(role));

server/src/main/java/invite/exception/UserRestrictionException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ public class UserRestrictionException extends AuthenticationException {
1010
public UserRestrictionException() {
1111
super("Forbidden");
1212
}
13+
14+
public UserRestrictionException(String message) {
15+
super(message);
16+
}
1317
}

0 commit comments

Comments
 (0)