PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/atlassian/jira/plugins/bitbucket/api/impl/BasicAuthentication.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 48 lines | 37 code | 7 blank | 4 comment | 16 complexity | ca0ad2a74c927fbb2f31cd427418a814 MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.api.impl;
  2. import org.apache.commons.lang.StringUtils;
  3. import com.atlassian.jira.plugins.bitbucket.api.Authentication;
  4. import com.atlassian.sal.api.net.Request;
  5. /**
  6. * Basic authentication
  7. */
  8. public class BasicAuthentication implements Authentication
  9. {
  10. private final String username;
  11. private final String password;
  12. public BasicAuthentication(String username, String password)
  13. {
  14. this.username = username;
  15. this.password = password;
  16. }
  17. @Override
  18. public void addAuthentication(Request<?, ?> request, String url)
  19. {
  20. // add basic authentication
  21. if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password))
  22. request.addBasicAuthentication(username, password);
  23. }
  24. @Override
  25. public boolean equals(Object o)
  26. {
  27. if (this == o) return true;
  28. if (o == null || getClass() != o.getClass()) return false;
  29. BasicAuthentication that = (BasicAuthentication) o;
  30. if (password != null ? !password.equals(that.password) : that.password != null) return false;
  31. if (username != null ? !username.equals(that.username) : that.username != null) return false;
  32. return true;
  33. }
  34. @Override
  35. public int hashCode()
  36. {
  37. int result = username != null ? username.hashCode() : 0;
  38. result = 31 * result + (password != null ? password.hashCode() : 0);
  39. return result;
  40. }
  41. }