Guest User

Untitled

a guest
Oct 17th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. */
  2. public String login() {
  3. UserAuth userAuth = new UserAuth();
  4. userAuth.setUserName(username);
  5. userAuth.setPassword(password);
  6. try {
  7. EntryValue loginRes = wsClient.login(userAuth, Class.class.getName(), new NameValueList());
  8. return loginRes.getId();
  9. } catch (Exception e) {
  10. throw new RuntimeException(e.getMessage());
  11. }
  12. // if (!loginRes.getError().getNumber().equals("0")) {
  13. // throw new RuntimeException("Error login to SugarCRM:" + " " + loginRes.getError().getNumber() + " " + loginRes.getError().getName() + " " + loginRes.getError().getDescription());
  14. // }
  15. }
  16.  
  17. /**
  18. * @param data
  19. * @return
  20. * @throws Exception
  21. */
  22. private String getHexString(byte[] data) throws Exception {
  23. StringBuffer buf = new StringBuffer();
  24. for (int i = 0; i < data.length; i++) {
  25. int halfbyte = (data[i] >>> 4) & 0x0F;
  26. int two_halfs = 0;
  27. do {
  28. if ((0 <= halfbyte) && (halfbyte <= 9))
  29. buf.append((char) ('0' + halfbyte));
  30. else
  31. buf.append((char) ('a' + (halfbyte - 10)));
  32. halfbyte = data[i] & 0x0F;
  33. } while (two_halfs++ < 1);
  34. }
  35. return buf.toString();
  36. }
  37.  
  38. /**
  39. * @param password
  40. * @throws Exception
  41. */
  42. public void setPassword(String password) throws Exception {
  43. MessageDigest md = MessageDigest.getInstance("MD5");
  44. this.password = getHexString(md.digest(password.getBytes()));
  45. }
  46.  
  47. /**
  48. * @param username
  49. */
  50. public void setUsername(String username) {
  51. this.username = username;
  52. }
  53.  
  54. /**
  55. * @param wsClient
  56. */
  57. public void setWsClient(SugarsoapPortType wsClient) {
  58. this.wsClient = wsClient;
  59. }
Add Comment
Please, Sign In to add comment