Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. package com.omniture.android.dashboard.viewer.model.user;
  2.  
  3. import java.io.UnsupportedEncodingException;
  4. import java.security.NoSuchAlgorithmException;
  5.  
  6. import com.omniture.android.dashboard.viewer.utilities.Base64Coder;
  7. import com.omniture.android.dashboard.viewer.utilities.ISOUtilities;
  8. import com.omniture.android.dashboard.viewer.utilities.SimpleMD5;
  9. import com.omniture.android.dashboard.viewer.utilities.SimpleSHA1;
  10.  
  11. public class AuthHelper {
  12.  
  13. String mUser_login;
  14. String mCompany;
  15. String mHashed_password;
  16. String mApp_key;
  17. String mApp_shared_secret;
  18. OMUser mUser;
  19.  
  20. public AuthHelper(OMUser user, String mUserLogin, String mCompany, String mHashedPassword, String mAppKey, String mAppSharedSecret) {
  21. super();
  22. this.mUser = user;
  23. this.mUser_login = mUserLogin;
  24. this.mCompany = mCompany;
  25. this.mHashed_password = mHashedPassword;
  26. this.mApp_key = mAppKey;
  27. this.mApp_shared_secret = mAppSharedSecret;
  28. }
  29.  
  30. // creates and fills an authParams object with one time use properties.
  31. public AuthParams getOneTimeAuthParams() {
  32. AuthParams auth_params = new AuthParams();
  33.  
  34. String nonce = generateNonce();
  35. String appnonce = generateNonce();
  36.  
  37. try {
  38. String timestamp = ISOUtilities.formatDateTime();
  39. String tempDigest = nonce + timestamp + mHashed_password;
  40. String tempDigestSHA1 = SimpleSHA1.SHA1Hex(tempDigest);
  41. String tempAppDigest = appnonce + mApp_shared_secret;
  42. String tempAppDigestSHA1 = SimpleSHA1.SHA1Hex(tempAppDigest);
  43.  
  44. auth_params.setmAuth_username(mUser_login + ":" + mCompany);
  45. auth_params.setmAuth_nonce(nonce);
  46. auth_params.setmAuth_created(timestamp);
  47. auth_params.setmAuth_digest(Base64Coder.encodeString(tempDigestSHA1));
  48. auth_params.setmAppdigest(Base64Coder.encodeString(tempAppDigestSHA1));
  49. auth_params.setmAppnonce(appnonce);
  50. auth_params.setmAppkey(mApp_key);
  51. } catch (NoSuchAlgorithmException ne) {
  52. ne.printStackTrace();
  53. return null;
  54. } catch (UnsupportedEncodingException uce) {
  55. uce.printStackTrace();
  56. return null;
  57. }
  58.  
  59. return auth_params;
  60. }
  61.  
  62. // Generates a unique hash based on epoch date.
  63. public String generateNonce() {
  64. String nonce = ISOUtilities.milliDateTime();
  65.  
  66. try{
  67. nonce = SimpleMD5.MD5(nonce);
  68. return nonce;
  69. } catch (NoSuchAlgorithmException ne) {
  70. ne.printStackTrace();
  71. return null;
  72. } catch (UnsupportedEncodingException uce) {
  73. uce.printStackTrace();
  74. return null;
  75. }
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement