private void useHelloService(HelloWorld service, String user) { System.out.println("Getting the list of existing users"); printUsers(service.getUsers()); System.out.println("Asking the service to add a new user " + user + " and also say hi"); System.out.println(service.sayHi(user)); System.out.println(service.sayHiToUser(new UserImpl(user))); System.out.println("Getting the list of existing users"); Map<Integer, User> users = service.getUsers(); printUsers(users); System.out.println("Echoing the list of existing users"); printUsers(service.echoUsers(users)); }
public void sayHelloAsUser() throws Exception { HelloWorld service = createServiceProxy("bob", "bobspassword"); System.out.println("Using HelloServiceRest with user priviliges"); System.out.println("Getting the list of existing users"); try { Map<Integer, User> users = service.getUsers(); printUsers(users); throw new RuntimeException("Only admin should be able to invoke getUsers"); } catch (WebApplicationException ex) { Assert.assertEquals("403 response code is expected", 403, ex.getResponse().getStatus()); System.out.println("Access was denied for user bob"); } System.out.println("Asking the service to add a new user Barry and also say hi"); try { System.out.println(service.sayHi("Barry")); System.out.println(service.sayHiToUser(new UserImpl("Barry"))); } catch (WebApplicationException ex) { throw new RuntimeException("Should be able to sayHi"); } }
public void sayHelloAsAdmin() throws Exception { HelloWorld service = createServiceProxy("jim", "jimspassword"); System.out.println("Using HelloServiceRest with admin priviliges"); System.out.println("Asking the service to add a new user and also say hi"); try { System.out.println(service.sayHi("Barry")); System.out.println(service.sayHiToUser(new UserImpl("Barry"))); } catch (WebApplicationException ex) { throw new RuntimeException("Should be able to sayHi", ex); } System.out.println("Getting the list of existing users"); try { Map<Integer, User> users = service.getUsers(); printUsers(users); } catch (WebApplicationException ex) { throw new RuntimeException("Admin should be able to invoke getUsers", ex); } }
printUsers(service.getUsers()); if (!admin) { throw new RuntimeException("Only Admin can invoke getUsers"); printUsers(users); if (!admin) { throw new RuntimeException("Only Admin can invoke getUsers"); printUsers(service.echoUsers(users)); if (!admin) { throw new RuntimeException("Only Admin can invoke echoUsers");
printUsers(service.getUsers()); if (!admin) { throw new RuntimeException("Only Admin can invoke getUsers"); printUsers(users); printUsers(service.echoUsers(users)); if (!admin) { throw new RuntimeException("Only Admin can invoke echoUsers");