Guest User

Untitled

a guest
Jul 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. @Test
  2. public void exploratorySecurityTest() {
  3. String username = "user";
  4. String password = "pwd";
  5.  
  6. UserStoryService service = new UserStoryService();
  7. UserStoryServiceSoap port = service.getUserStoryServiceSoap();
  8.  
  9. //initialize security
  10. org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
  11. org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
  12. Map<String, Object> outProps = new HashMap<String, Object>();
  13. outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
  14. outProps.put(WSHandlerConstants.USER, username);
  15. outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
  16. outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());
  17. WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
  18. cxfEndpoint.getOutInterceptors().add(wssOut);
  19.  
  20. int storyId = 33401;
  21. UserStoryDTO userStoryDTO = port.getByID(storyId);
  22.  
  23. //success if no error
  24. }
  25.  
  26. public class ClientPasswordCallback implements CallbackHandler {
  27.  
  28. @Override
  29. public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  30. WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
  31. pc.setPassword("pwd");
  32. }
  33.  
  34. if (pc.getIdentifier().equals("user")) {
  35. pc.setPassword("pwd");
  36. }
  37.  
  38. @Test
  39. public void exploratorySecurityTest() {
  40. String username = "user";
  41. String password = "pwd";
  42.  
  43. UserStoryService service = new UserStoryService();
  44. UserStoryServiceSoap port = service.getUserStoryServiceSoap();
  45.  
  46. //initialize security
  47. org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
  48. org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
  49. Map<String, Object> outProps = new HashMap<String, Object>();
  50. outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
  51. outProps.put(WSHandlerConstants.USER, username);
  52.  
  53. //pass the password here?
  54. outProps.put("password", password);
  55.  
  56. outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
  57. outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());
  58. WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
  59.  
  60. cxfEndpoint.getOutInterceptors().add(wssOut);
  61. ...
  62. }
Add Comment
Please, Sign In to add comment