/webportal/src/main/java/au/org/emii/portal/net/HttpAuthenticateProxy.java

http://alageospatialportal.googlecode.com/ · Java · 37 lines · 30 code · 7 blank · 0 comment · 3 complexity · 2921855e68f75d54e66efebcbe4277b6 MD5 · raw file

  1. package au.org.emii.portal.net;
  2. import au.org.emii.portal.settings.Settings;
  3. import au.org.emii.portal.util.Validate;
  4. import java.net.Authenticator;
  5. import java.net.PasswordAuthentication;
  6. import org.apache.log4j.Logger;
  7. public class HttpAuthenticateProxy extends Authenticator {
  8. private Settings settings = null;
  9. private Logger logger = Logger.getLogger(getClass());
  10. @Override
  11. protected PasswordAuthentication getPasswordAuthentication() {
  12. String proxyUserName = settings.getProxyUsername();
  13. String proxyPassword = settings.getProxyPassword();
  14. logger.debug(String.format("proxy username='%s' proxy password='%s'",proxyUserName, proxyPassword));
  15. PasswordAuthentication authenticator;
  16. if (Validate.empty(proxyUserName) && Validate.empty(proxyPassword)) {
  17. logger.debug("no username and password supplied for proxy - will return null authenticator");
  18. authenticator = null;
  19. } else {
  20. authenticator = new PasswordAuthentication(proxyUserName, proxyPassword.toCharArray());
  21. }
  22. return authenticator;
  23. }
  24. public Settings getSettings() {
  25. return settings;
  26. }
  27. public void setSettings(Settings settings) {
  28. this.settings = settings;
  29. }
  30. }