Guest User

Untitled

a guest
Nov 23rd, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class BasicAuth {
  2.  
  3. private String user;
  4. private String pass;
  5.  
  6. public BasicAuth(String user, String pass) {
  7.  
  8. if (TextUtils.isEmpty(user)) {
  9. throw new IllegalArgumentException("user cannot be null");
  10. }
  11.  
  12. if (TextUtils.isEmpty(pass)) {
  13. throw new IllegalArgumentException("pass cannot be null");
  14. }
  15.  
  16. this.user = user;
  17. this.pass = pass;
  18. }
  19.  
  20. public String getHeaderValue() {
  21. byte[] bytes = String.format("%s:%s", user, pass).getBytes();
  22. String value = String.format("Basic %s", Base64.encodeToString(bytes, Base64.DEFAULT));
  23. return value.trim();
  24. }
  25.  
  26. public String getHeaderName() {
  27. return "Authorization";
  28. }
  29.  
  30. }
Add Comment
Please, Sign In to add comment