private User assertAdmin(String userEmail, String userToken) { User user = userService.getUserByEmailToken(userEmail, userToken); if (user.isAdmin()) { return user; } else { throw new IllegalArgumentException( "Error: User '" + user.getEmail() + "' does not have admin rights"); } }
@MessageMapping("/admin_removeUserByEmail") public void deleteUserByEmail(AdminMessage message) throws Exception { logger.info("Attempting to delete user " + message.getValue()); User user = assertAdmin(message.getUserEmail(), message.getUserToken()); userService.deleteUserByEmail(message.getValue()); // tell the user that the game has been created messagingTemplate.convertAndSend( "/queue/" + user.getToken() + "/admin", "User " + message.getValue() + " has been removed"); }