@Test public void testDelete() { Collection<GrantedAuthority> rights = new HashSet<GrantedAuthority>(); rights.addAll(Arrays.asList(Right.CRUD_SLC_OPERATOR, Right.CRUD_SEA_ADMIN, Right.CRUD_LEA_ADMIN)); Mockito.when(secUtil.getAllRights()).thenReturn(rights); Mockito.when(secUtil.getUid()).thenReturn(UUID1); User newUser = new User(); newUser.setGroups(Arrays.asList(RoleInitializer.SLC_OPERATOR)); newUser.setUid(UUID2); newUser.setTenant(""); Mockito.when(ldap.getUser(REALM, UUID2)).thenReturn(newUser); Mockito.when(secUtil.hasRole(RoleInitializer.SLC_OPERATOR)).thenReturn(true); Response res = resource.delete(newUser.getUid()); Mockito.verify(ldap, Mockito.atLeastOnce()).getUser(REALM, newUser.getUid()); Mockito.verify(ldap).removeUser(REALM, newUser.getUid()); Assert.assertNotNull(res); Assert.assertEquals(204, res.getStatus()); Collection<GrantedAuthority> rights2 = new HashSet<GrantedAuthority>(); rights2.addAll(Arrays.asList(Right.CRUD_SANDBOX_ADMIN)); Mockito.when(secUtil.getAllRights()).thenReturn(rights2); Mockito.when(secUtil.getUid()).thenReturn(UUID1); Mockito.when(secUtil.getTenantId()).thenReturn(TENANT); User userToDelete = new User(); userToDelete.setGroups(Arrays.asList(RoleInitializer.SLC_OPERATOR)); userToDelete.setUid(UUID2); userToDelete.setTenant(TENANT1); Mockito.when(ldap.getUser(REALM, UUID2)).thenReturn(userToDelete); Mockito.when(secUtil.hasRole(RoleInitializer.SLC_OPERATOR)).thenReturn(false); Mockito.when(secUtil.hasRole(RoleInitializer.SANDBOX_SLC_OPERATOR)).thenReturn(false); res = resource.delete(newUser.getUid()); Assert.assertNotNull(res); Assert.assertEquals(403, res.getStatus()); }
@DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response delete(@PathParam("uid") final String uid) { Response result = validateUserDelete(uid, secUtil.getTenantId()); if (result != null) { return result; } User userToDelete = ldapService.getUser(realm, uid); ldapService.removeUser(realm, uid); auditLogger.audit(createSecurityEvent("Deleted user " + uid + " with roles " + rolesToString(userToDelete), userToDelete.getTenant(), userToDelete.getEdorg())); return Response.status(Status.NO_CONTENT).build(); }
UserResource { @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response delete(@PathParam("uid") final String uid) { Response result = validateUserDelete(uid, secUtil.getTenantId()); if (result != null) { return result; } User userToDelete = ldapService.getUser(realm, uid); ldapService.removeUser(realm, uid); auditLogger.audit(createSecurityEvent("Deleted user " + uid + " with roles " + rolesToString(userToDelete), userToDelete.getTenant(), userToDelete.getEdorg())); return Response.status(Status.NO_CONTENT).build(); } }
UserResource { @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response delete(@PathParam("uid") final String uid) { Response result = validateUserDelete(uid, secUtil.getTenantId()); if (result != null) { return result; } User userToDelete = ldapService.getUser(realm, uid); ldapService.removeUser(realm, uid); auditLogger.audit(createSecurityEvent("Deleted user " + uid + " with roles " + rolesToString(userToDelete), userToDelete.getTenant(), userToDelete.getEdorg())); return Response.status(Status.NO_CONTENT).build(); }  }
UserResource { @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response delete(@PathParam("uid") final String uid) { Response result = validateUserDelete(uid, secUtil.getTenantId()); if (result != null) { return result; } User userToDelete = ldapService.getUser(realm, uid); ldapService.removeUser(realm, uid); auditLogger.audit(createSecurityEvent("Deleted user " + uid + " with roles " + rolesToString(userToDelete), userToDelete.getTenant(), userToDelete.getEdorg())); return Response.status(Status.NO_CONTENT).build(); }  @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response create(final User newUser); @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response readAll(); @PUT @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response update(final User updateUser); @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response delete(@PathParam("uid") final String uid); @GET @Path("edorgs") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response getEdOrgs(); void setRealm(String realm); }
UserResource { @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response delete(@PathParam("uid") final String uid) { Response result = validateUserDelete(uid, secUtil.getTenantId()); if (result != null) { return result; } User userToDelete = ldapService.getUser(realm, uid); ldapService.removeUser(realm, uid); auditLogger.audit(createSecurityEvent("Deleted user " + uid + " with roles " + rolesToString(userToDelete), userToDelete.getTenant(), userToDelete.getEdorg())); return Response.status(Status.NO_CONTENT).build(); }  @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response create(final User newUser); @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response readAll(); @PUT @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response update(final User updateUser); @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response delete(@PathParam("uid") final String uid); @GET @Path("edorgs") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response getEdOrgs(); void setRealm(String realm);  }