Search in sources :

Example 11 with AuthSessionHolder

use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.

the class LoginEngine method handleCreateSessionManualResponse.

/**
 * Called when a response to the GetSessionByCredentials API is received
 * (manual login). In case of success, tries to activate the account using
 * the activation code received by SMS.
 *
 * @param data The received data
 */
private void handleCreateSessionManualResponse(List<BaseDataType> data) {
    LogUtils.logD("LoginEngine.handleCreateSessionManualResponse()");
    ServiceStatus errorStatus = getResponseStatus(BaseDataType.AUTH_SESSION_HOLDER_TYPE, data);
    if (errorStatus == ServiceStatus.SUCCESS && (data.size() > 0)) {
        setActivatedSession((AuthSessionHolder) data.get(0));
        startActivateAccount();
        return;
    }
    completeUiRequest(errorStatus, null);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 12 with AuthSessionHolder

use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.

the class Request method calculateAuth.

/**
 * Calculate the Auth value for this Requester. TODO: Throttle by
 * timestamp/function to prevent automatic backend log out
 */
private void calculateAuth() {
    String ts = null;
    if (null != mParameters) {
        ts = (String) mParameters.get("timestamp");
    }
    if (null == ts) {
        mAuthTimestamp = System.currentTimeMillis();
        ts = "" + (mAuthTimestamp / 1000);
    }
    AuthSessionHolder session = LoginEngine.getSession();
    if (session != null) {
        addData("auth", SettingsManager.getProperty(Settings.APP_KEY_ID) + "::" + session.sessionID + "::" + ts);
    } else {
        addData("auth", SettingsManager.getProperty(Settings.APP_KEY_ID) + "::" + ts);
    }
    addData("auth", AuthUtils.calculateAuth(mApiMethodName, mParameters, ts, session));
/**
 * if (mNeedsUserAuthentication) { addData("auth",
 * AuthUtils.calculateAuth(mApiMethodName, mParameters, ts, session)); }
 * else { // create the final auth without the session addData("auth",
 * AuthUtils.calculateAuth(mApiMethodName, mParameters, ts, null)); }
 */
}
Also used : AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder)

Example 13 with AuthSessionHolder

use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.

the class LoginEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "LoginEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case LOGIN_REQUEST:
        case SMS_RESPONSE_SIGNIN:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine FETCH ids");
            StatusMsg msg = new StatusMsg();
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            mState = LoginTestState.LOGIN_REQUEST_VALID;
            break;
        case LOGIN_REQUEST_VALID:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine FETCH ids");
            AuthSessionHolder sesh = new AuthSessionHolder();
            data.add(sesh);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            mState = LoginTestState.SMS_RESPONSE_SIGNIN;
            break;
        case REGISTRATION:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine Registration");
            data.add(mTestModule.createDummyContactData());
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SIGNUP_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case REGISTRATION_ERROR:
            data.add(new ServerError(ServerError.ErrorType.UNKNOWN));
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_T_AND_C:
        case FETCH_PRIVACY:
        case USER_NAME_STATE:
            SimpleText txt = new SimpleText();
            txt.addText("Simple text");
            data.add(txt);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_T_AND_C_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SERVER_ERROR:
            data.add(new ServerError(ServerError.ErrorType.UNKNOWN));
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) SimpleText(com.vodafone360.people.datatypes.SimpleText) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue)

Example 14 with AuthSessionHolder

use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.

the class HeartbeatSenderThread method sendHeartbeat.

/**
 * Prepares the necessary Hessian payload and writes it directly to the open
 * output-stream of the socket.
 *
 * @throws Exception Thrown if there was an unknown problem writing to the
 *             output-stream.
 * @throws IOException Thrown if there was a problem regarding IO while
 *             writing to the output-stream.
 */
public void sendHeartbeat() throws IOException, Exception {
    byte[] rpgMsg = null;
    try {
        rpgMsg = getHeartbeatHessianPayload();
    } catch (NullPointerException e) {
        // Stop connnection and log out
        ConnectionManager.getInstance().onLoginStateChanged(false);
        EngineManager.getInstance().getLoginEngine().logoutAndRemoveUser();
    }
    try {
        // Try and issue the request
        if (Settings.sEnableProtocolTrace) {
            Long userID = null;
            AuthSessionHolder auth = LoginEngine.getSession();
            if (auth != null) {
                userID = auth.userID;
            }
            HttpConnectionThread.logI("RpgTcpHeartbeatSender.sendHeartbeat()", "\n  * Sending a heartbeat for user ID " + userID + "----------------------------------------" + HessianUtils.getInHessian(new ByteArrayInputStream(rpgMsg), true) + "\n");
        }
        if (null != mOs) {
            synchronized (mOs) {
                mOs.write(rpgMsg);
                mOs.flush();
            }
        }
    } catch (IOException ioe) {
        HttpConnectionThread.logE("RpgTcpHeartbeatSender.sendHeartbeat()", "Could not write HB to OS!", ioe);
        throw ioe;
    } catch (Exception e) {
        HttpConnectionThread.logE("RpgTcpHeartbeatSender.sendHeartbeat()", "Could not send HB to OS! Unknown: ", e);
        throw e;
    } finally {
        rpgMsg = null;
    }
}
Also used : AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 15 with AuthSessionHolder

use of com.vodafone360.people.datatypes.AuthSessionHolder in project 360-Engine-for-Android by 360.

the class StateTable method fetchSession.

/**
 * Fetches the current session from the database.
 *
 * @param readableDb Readable SQLite database for fetching the information
 * @return The session object or null if the session was not available.
 */
public static AuthSessionHolder fetchSession(final SQLiteDatabase readableDb) {
    Cursor cursor = null;
    try {
        cursor = readableDb.rawQuery("SELECT " + Field.SESSIONID + "," + Field.SESSIONSECRET + "," + Field.SESSIONUSERID + "," + Field.SESSIONUSERNAME + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
        if (!cursor.moveToFirst()) {
            LogUtils.logE("StateTable.fetchSession() " + "Unable to find session info in the database");
            return null;
        }
        if (cursor.isNull(cursor.getColumnIndex(Field.SESSIONID.toString())) || cursor.isNull(cursor.getColumnIndex(Field.SESSIONSECRET.toString())) || cursor.isNull(cursor.getColumnIndex(Field.SESSIONUSERID.toString())) || cursor.isNull(cursor.getColumnIndex(Field.SESSIONUSERNAME.toString()))) {
            LogUtils.logE("StateTable.fetchSession() " + "Unable to find session data in the database");
            return null;
        }
        final AuthSessionHolder session = new AuthSessionHolder();
        session.sessionID = SqlUtils.setString(cursor, Field.SESSIONID.toString());
        session.sessionSecret = SqlUtils.setString(cursor, Field.SESSIONSECRET.toString());
        session.userID = SqlUtils.setLong(cursor, Field.SESSIONUSERID.toString(), -1L);
        session.userName = SqlUtils.setString(cursor, Field.SESSIONUSERNAME.toString());
        DatabaseHelper.trace(false, "StateTable.fetchSession() " + "Fetched session[" + session.sessionID + "]");
        return session;
    } catch (Exception e) {
        LogUtils.logE("StateTable.fetchSession() Exception - " + "Unable to fetch session from database", e);
        return null;
    } finally {
        CloseUtils.close(cursor);
    }
}
Also used : AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteException(android.database.sqlite.SQLiteException)

Aggregations

AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)15 IOException (java.io.IOException)6 MediumTest (android.test.suitebuilder.annotation.MediumTest)4 ServiceStatus (com.vodafone360.people.service.ServiceStatus)4 ArrayList (java.util.ArrayList)4 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)3 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)3 Hashtable (java.util.Hashtable)3 ServerError (com.vodafone360.people.datatypes.ServerError)2 RpgHeader (com.vodafone360.people.service.io.rpg.RpgHeader)2 DecoderThread (com.vodafone360.people.service.transport.DecoderThread)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteException (android.database.sqlite.SQLiteException)1 Bundle (android.os.Bundle)1 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)1 Identity (com.vodafone360.people.datatypes.Identity)1 SimpleText (com.vodafone360.people.datatypes.SimpleText)1