|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.engine.BaseEngine com.vodafone360.people.engine.login.LoginEngine
public class LoginEngine
Engine handling sign in to existing accounts and sign up to new accounts.
Nested Class Summary | |
---|---|
static interface |
LoginEngine.ILoginEventsListener
Listener interface that can be used by clients to receive login state events from the engine. |
private static class |
LoginEngine.State
List of states for LoginEngine. |
Nested classes/interfaces inherited from class com.vodafone360.people.engine.BaseEngine |
---|
BaseEngine.IEngineEventCallback |
Field Summary | |
---|---|
private static long |
ACTIVATE_LOGIN_TIMEOUT
Timeout used when waiting for the server to sent an activation SMS. |
private static java.lang.String |
AUTH_SESSION_HOLDER
Used to verify datatype of server response for Auth.getSessionByCredentials(com.vodafone360.people.engine.BaseEngine, java.lang.String, java.lang.String, java.util.Map request. |
private java.lang.String |
mActivationCode
Holds the activation code once an activation SMS has been received. |
private boolean |
mAreLoginDetailsValid
Determines if current login information from database can be used to establish a session. |
private Context |
mContext
Context used for listening to SMS events |
private boolean |
mCurrentLoginState
Determines if the user is currently logged in with a valid session |
private java.lang.String |
mCurrentSubscriberId
Subscriber ID fetched from SIM card |
private DatabaseHelper |
mDb
Database used for fetching/storing state information |
private BroadcastReceiver |
mEventReceiver
A broadcast receiver which is used to receive notifications when a data SMS arrives. |
private java.util.ArrayList<LoginEngine.ILoginEventsListener> |
mEventsListener
Contains a list of login engine observers which will be notified when the login engine changes state. |
private boolean |
mIsRegistrationComplete
Set to true when sign in or sign up has been completed by the user. |
private LoginDetails |
mLoginDetails
Contains user login details such as user name and password |
private java.lang.Object |
mMutex
mutex for thread synchronization |
private PublicKeyDetails |
mPublicKey
Contains a public key for encrypting login details to be sent to the server |
private RegistrationDetails |
mRegistrationDetails
Contains user registration details such as name, username, password, etc. |
private static int |
MS_IN_SECONDS
To convert between seconds and milliseconds |
private LoginEngine.State |
mState
Current state of the engine |
private TelephonyManager |
mTelephonyManager
Android telephony manager used for fetching subscriber ID |
private static AuthSessionHolder |
sActivatedSession
Contains the authenticated session information while the user is logged in |
private static java.lang.String |
STATUS_MSG
Used to verify datatype of server response to request activation code and activation account. |
Fields inherited from class com.vodafone360.people.engine.BaseEngine |
---|
mActiveUiRequest, mCurrentTimeout, mEngineId, mEventCallback |
Constructor Summary | |
---|---|
LoginEngine(Context context,
BaseEngine.IEngineEventCallback eventCallback,
DatabaseHelper db)
Public constructor. |
Method Summary | |
---|---|
void |
addListener(LoginEngine.ILoginEventsListener listener)
Add a listener which will receive events whenever the login state changes. |
void |
addUiFetchPrivacyStatementRequest()
Called by the INowPlusService implementation to privacy statement for the UI. |
void |
addUiFetchTermsOfServiceRequest()
Called by the INowPlusService implementation to fetch terms of service text for the UI. |
void |
addUiGetUsernameStateRequest(java.lang.String username)
Called by the INowPlusService implementation to check if a username is available for registration. |
void |
addUiLoginRequest(LoginDetails loginDetails)
Called by the INowPlusService implementation to start a manual login. |
void |
addUiRegistrationRequest(RegistrationDetails details)
Called by the INowPlusService implementation to start the sign-up process. |
void |
addUiRemoveUserDataRequest()
Called by the INowPlusService implementation to remove user data Issues a UI request to effectively log out. |
boolean |
getLoginRequired()
A helper function which determines which activity should be displayed when the UI is loaded. |
void |
getNewPublicKey()
Requests a new Public Key from the server. |
long |
getNextRunTime()
Return the absolute time in milliseconds when the engine needs to run (based on System.currentTimeMillis). |
static AuthSessionHolder |
getSession()
Retrieves the active comms session. |
private void |
handleActivateAccountResponse(java.util.List<BaseDataType> data)
Called when a response to the Activate API is received (manual login or sign-up). |
private void |
handleCreateSessionAutoResponse(java.util.List<BaseDataType> data)
Called when a response to the GetSessionByCredentials API is received (auto login). |
private void |
handleCreateSessionManualResponse(java.util.List<BaseDataType> data)
Called when a response to the GetSessionByCredentials API is received (manual login). |
private void |
handleNewPublicKeyResponse(java.util.List<BaseDataType> mDataTypes)
Called when a response to the server fetch public key request is received. |
private void |
handleRequestingActivationResponse(java.util.List<BaseDataType> data)
Called when a response to the RequestActivationCode API is received (manual login). |
private void |
handleServerSimpleTextResponse(java.util.List<BaseDataType> data)
Called when a response to the GetTermsAndConditions, GetPrivacyStatement and GetUsernameState APIs are received. |
private void |
handleSignUpResponse(java.util.List<BaseDataType> data)
Called when a response to the sign-up API is received. |
private void |
handleSmsResponse()
Called when an SMS is received during sign-up or manual login. |
private void |
initialiseEngine()
Called by the run() function the first time it is executed to perform non-trivial initialisation such as auto login. |
boolean |
isLoggedIn()
Determines if the user is currently logged in with a valid session. |
private static java.lang.String |
makeSecurePassword(java.lang.String userName,
java.lang.String password,
long ts)
Concatenates the username, password, current time and some other data into a string which can be encrypted and sent to the server. |
private void |
newState(LoginEngine.State newState)
Changes the state of the engine. |
void |
onCreate()
This will be called immediately after creation to perform extra initialisation. |
void |
onDestroy()
This will be called just before the engine is shutdown. |
private void |
onLoginStateChanged(boolean loggedIn)
Called when the engine transitions between the logged in and logged out states. |
protected void |
onRequestComplete()
Called by the base engine implementation whenever a UI request is completed to do any necessary cleanup. |
void |
onReset()
Called by the framework before a remove user data operation takes place. |
protected void |
onTimeoutEvent()
Handles timeouts for SMS activation and auto login retries. |
private byte[] |
prepareBytesForSignup(long timeStampInSeconds)
Encrypts the sign-up data ready for sending to the server |
protected void |
processCommsResponse(ResponseQueue.Response resp)
Called when a server response is received, processes the response based on the engine state. |
protected void |
processUiRequest(ServiceUiRequest requestId,
java.lang.Object data)
Called when a UI request is ready to be processed. |
private void |
removeAllListeners()
Remove all ILoginStateChangeListener (done as part of cleanup). |
void |
removeListener(LoginEngine.ILoginEventsListener listener)
Remove a listener added by the addListener function. |
private void |
restoreLoginState()
Once the engine has finished processing a user request, this function is called to restore the state back to an appropriate value (based on the user login state). |
boolean |
retryAutoLogin()
Retries to log the user in based on credential information stored in the database. |
void |
run()
Do some work but anything that takes longer than 1 second must be broken up. |
void |
setActivatedSession(AuthSessionHolder session)
Helper function to store the new session in the database and inform clients that the session has changed. |
private void |
setRegistrationComplete(boolean value)
Helper function to set the registration complete flag and update the database with the new state. |
static void |
setTestSession(AuthSessionHolder session)
Set 'dummy' auth session for test purposes only. |
private void |
startActivateAccount()
Sends a activate account request to the server. |
private void |
startFetchPrivacyStatement()
Sends a fetch privacy statement request to the server. |
private void |
startFetchTermsOfService()
Sends a fetch terms of service request to the server. |
private void |
startFetchUsernameState(java.lang.String username)
Sends a fetch user-name state request to the server. |
private void |
startGetSessionManual()
Sends a get session by credentials request to the server. |
private void |
startLogout()
Clears the session and registration complete information so that the user will need to manually login again to use the now+ services. |
private void |
startManualLoginProcess(LoginDetails details)
Sets registration complete flag to false then starts a new sign-in request. |
private void |
startRegistrationProcessCrypted(RegistrationDetails details)
Starts the sign-up process where the password is RSA encrypted. |
private void |
startRequestActivationCode()
Sends a request activation code request to the server. |
private void |
startSignUpCrypted(byte[] theBytes,
long timestamp)
Puts the engine into the signing up state and sends an encrypted sign-up request to the server. |
private boolean |
uiRequestReady()
Helper function which returns true if a UI request is waiting on the queue and we are ready to process it. |
private boolean |
validateRegistrationDetails()
Basic check to determine if the registration details given by the user are valid |
Methods inherited from class com.vodafone360.people.engine.BaseEngine |
---|
addUiRequestToQueue, clearTimeout, completeUiRequest, completeUiRequest, deactivateEngine, emptyUiRequestQueue, engineId, genericHandleResponseType, getCurrentTimeout, isCommsResponseOutstanding, isDeactivated, isUiRequestOutstanding, onCommsInMessage, processCommsInQueue, processTimeout, processUiQueue, setReqId, setTimeout |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.lang.Object mMutex
private static final java.lang.String STATUS_MSG
private static final java.lang.String AUTH_SESSION_HOLDER
Auth.getSessionByCredentials(com.vodafone360.people.engine.BaseEngine, java.lang.String, java.lang.String, java.util.Map>)
request.
private static final int MS_IN_SECONDS
private LoginEngine.State mState
private Context mContext
private DatabaseHelper mDb
private java.lang.String mCurrentSubscriberId
private TelephonyManager mTelephonyManager
private static AuthSessionHolder sActivatedSession
private final LoginDetails mLoginDetails
private PublicKeyDetails mPublicKey
private final RegistrationDetails mRegistrationDetails
private boolean mAreLoginDetailsValid
private static final long ACTIVATE_LOGIN_TIMEOUT
private java.lang.String mActivationCode
private boolean mIsRegistrationComplete
private final java.util.ArrayList<LoginEngine.ILoginEventsListener> mEventsListener
private boolean mCurrentLoginState
private final BroadcastReceiver mEventReceiver
Constructor Detail |
---|
public LoginEngine(Context context, BaseEngine.IEngineEventCallback eventCallback, DatabaseHelper db)
context
- The service ContexteventCallback
- Provides access to useful engine manager
functionalitydb
- The Now+ database used for fetching/storing login state
informationMethod Detail |
---|
public void onCreate()
onCreate
in class BaseEngine
public void onDestroy()
onDestroy
in class BaseEngine
public void addUiLoginRequest(LoginDetails loginDetails)
loginDetails
- The login information entered by the userpublic void addUiRemoveUserDataRequest()
public void addUiRegistrationRequest(RegistrationDetails details)
details
- The registration details entered by the userpublic void addUiFetchTermsOfServiceRequest()
public void addUiFetchPrivacyStatementRequest()
public void addUiGetUsernameStateRequest(java.lang.String username)
username
- Username to fetch the state ofpublic long getNextRunTime()
getNextRunTime
in class BaseEngine
public void run()
run
in class BaseEngine
private boolean uiRequestReady()
public boolean isLoggedIn()
public void addListener(LoginEngine.ILoginEventsListener listener)
listener
- The callback interfacepublic void removeListener(LoginEngine.ILoginEventsListener listener)
listener
- The same callback interface passed in to the add functionprivate void removeAllListeners()
private void restoreLoginState()
protected void processCommsResponse(ResponseQueue.Response resp)
processCommsResponse
in class BaseEngine
resp
- Response data from serverprotected void processUiRequest(ServiceUiRequest requestId, java.lang.Object data)
processUiRequest
in class BaseEngine
requestId
- UI request typedata
- Interpretation of this data depends on the request typeprivate void initialiseEngine()
private void startRegistrationProcessCrypted(RegistrationDetails details)
#startRegistrationProcess(RegistrationDetails)
function.
details
- Registration details received from the UI requestprivate byte[] prepareBytesForSignup(long timeStampInSeconds) throws InvalidCipherTextException
timeStampInSeconds
- Current time in milliseconds
InvalidCipherTextException
private static java.lang.String makeSecurePassword(java.lang.String userName, java.lang.String password, long ts)
userName
- User name for sign-in or sign-uppassword
- Password as entered by userts
- Current time in milliseconds
private void startSignUpCrypted(byte[] theBytes, long timestamp)
theBytes
- byte-array containing encrypted password data.timestamp
- Current timestamp.private boolean validateRegistrationDetails()
public void getNewPublicKey()
private void startFetchTermsOfService()
private void startFetchPrivacyStatement()
private void startFetchUsernameState(java.lang.String username)
username,
- the user-name to retrieve information for.private void startManualLoginProcess(LoginDetails details)
details
- Login details received from the UI requestprivate void startRequestActivationCode()
private void startGetSessionManual()
private void startActivateAccount()
private void startLogout()
public boolean retryAutoLogin()
private void setRegistrationComplete(boolean value)
value
- true if registration is completedprivate void newState(LoginEngine.State newState)
newState
- The new stateprivate void onLoginStateChanged(boolean loggedIn)
loggedIn
- true if the user is now logged in, false otherwise.public boolean getLoginRequired()
public static AuthSessionHolder getSession()
public void setActivatedSession(AuthSessionHolder session)
session
- The new session or NULL if the user has logged off.private void handleSignUpResponse(java.util.List<BaseDataType> data)
data
- The received dataprivate void handleNewPublicKeyResponse(java.util.List<BaseDataType> mDataTypes)
mDataTypes
- Response data from server.private void handleCreateSessionManualResponse(java.util.List<BaseDataType> data)
data
- The received dataprivate void handleCreateSessionAutoResponse(java.util.List<BaseDataType> data)
data
- The received dataprivate void handleRequestingActivationResponse(java.util.List<BaseDataType> data)
data
- The received dataprivate void handleActivateAccountResponse(java.util.List<BaseDataType> data)
data
- The received dataprivate void handleServerSimpleTextResponse(java.util.List<BaseDataType> data)
data
- The received dataprivate void handleSmsResponse()
protected void onRequestComplete()
onRequestComplete
in class BaseEngine
protected void onTimeoutEvent()
onTimeoutEvent
in class BaseEngine
public void onReset()
onReset
in class BaseEngine
public static void setTestSession(AuthSessionHolder session)
session
- 'dummy' session supplied to LoginEngine
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc