Created
February 20, 2013 18:36
-
-
Save bshaffer/4997874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.omniture.android.dashboard.viewer.model.user; | |
import java.io.UnsupportedEncodingException; | |
import java.security.NoSuchAlgorithmException; | |
import com.omniture.android.dashboard.viewer.utilities.Base64Coder; | |
import com.omniture.android.dashboard.viewer.utilities.ISOUtilities; | |
import com.omniture.android.dashboard.viewer.utilities.SimpleMD5; | |
import com.omniture.android.dashboard.viewer.utilities.SimpleSHA1; | |
public class AuthHelper { | |
String mUser_login; | |
String mCompany; | |
String mHashed_password; | |
String mApp_key; | |
String mApp_shared_secret; | |
OMUser mUser; | |
public AuthHelper(OMUser user, String mUserLogin, String mCompany, String mHashedPassword, String mAppKey, String mAppSharedSecret) { | |
super(); | |
this.mUser = user; | |
this.mUser_login = mUserLogin; | |
this.mCompany = mCompany; | |
this.mHashed_password = mHashedPassword; | |
this.mApp_key = mAppKey; | |
this.mApp_shared_secret = mAppSharedSecret; | |
} | |
// creates and fills an authParams object with one time use properties. | |
public AuthParams getOneTimeAuthParams() { | |
AuthParams auth_params = new AuthParams(); | |
String nonce = generateNonce(); | |
String appnonce = generateNonce(); | |
try { | |
String timestamp = ISOUtilities.formatDateTime(); | |
String tempDigest = nonce + timestamp + mHashed_password; | |
String tempDigestSHA1 = SimpleSHA1.SHA1Hex(tempDigest); | |
String tempAppDigest = appnonce + mApp_shared_secret; | |
String tempAppDigestSHA1 = SimpleSHA1.SHA1Hex(tempAppDigest); | |
auth_params.setmAuth_username(mUser_login + ":" + mCompany); | |
auth_params.setmAuth_nonce(nonce); | |
auth_params.setmAuth_created(timestamp); | |
auth_params.setmAuth_digest(Base64Coder.encodeString(tempDigestSHA1)); | |
auth_params.setmAppdigest(Base64Coder.encodeString(tempAppDigestSHA1)); | |
auth_params.setmAppnonce(appnonce); | |
auth_params.setmAppkey(mApp_key); | |
} catch (NoSuchAlgorithmException ne) { | |
ne.printStackTrace(); | |
return null; | |
} catch (UnsupportedEncodingException uce) { | |
uce.printStackTrace(); | |
return null; | |
} | |
return auth_params; | |
} | |
// Generates a unique hash based on epoch date. | |
public String generateNonce() { | |
String nonce = ISOUtilities.milliDateTime(); | |
try{ | |
nonce = SimpleMD5.MD5(nonce); | |
return nonce; | |
} catch (NoSuchAlgorithmException ne) { | |
ne.printStackTrace(); | |
return null; | |
} catch (UnsupportedEncodingException uce) { | |
uce.printStackTrace(); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment