Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package it.roaned.proxy;
  2.  
  3. import java.net.Authenticator;
  4. import java.net.PasswordAuthentication;
  5.  
  6. /**
  7. * copiata da:
  8. * http://blog.ashwani.co.in/blog/2013-07-29/access-sharepoint-webservices-from-java-behind-proxy/
  9. */
  10. public class SimpleAuthenticator extends Authenticator
  11. {
  12. private final static String proxyHost = "proxy.aubay.it";
  13. private String username;
  14. private final char[] password;
  15.  
  16. public SimpleAuthenticator(String username,String password)
  17. {
  18. super();
  19. this.username = new String(username);
  20. this.password = password.toCharArray();
  21. }
  22.  
  23. protected PasswordAuthentication getPasswordAuthentication()
  24. {
  25. String requestingHost = getRequestingHost();
  26. if (requestingHost == proxyHost){
  27. System.out.println("getPasswordAuthentication() request recieved from->" + requestingHost );
  28. return new PasswordAuthentication(username,password);
  29. }
  30. else{
  31. System.out.println("getPasswordAuthentication() request recieved from->" + requestingHost );
  32. return new PasswordAuthentication(username,password);
  33. }
  34.  
  35. }
  36. }
  37.  
  38.  
  39.  
  40. // Authenticator.setDefault(new SimpleAuthenticator("andrei.cebotari", "Htc__Aub92"));
  41. // log.info("Configuring Proxy settings");
  42. // System.getProperties().put("http.proxyHost","proxy.aubay.it");
  43. // System.getProperties().put("http.proxyPort","3128");
  44. // System.getProperties().put("https.proxyHost","proxy.aubay.it");
  45. // System.getProperties().put("https.proxyPort", "3128");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement