How to mantain the LTPA Token after closing the application? - android

I have implemented WASLTPAAuthentication (with WASLTPALoginModule and Realm) and it works well.
I can call my JAX-RS and they took the identity by the cookie.
My problem is: after I tap the Home button and open the menu of recent applications to swipe and quit the application, then once I open it again the session is destroyed and the cookie is lost and I need to insert my credentials and login again.
Is there a way to prevent this? Do I need to store the cookie on the localStorage in some way?

It looks like even though your LTPA cookie is still valid, when you close the application and the session dies, the cookies are being cleared. You will need to save the LTPA cookie in local storage and then set the cookie manually if you want it to use it for multiple sessions.
The LTPA cookie is included in the attributes object of the UserIdentity returned after successfully logging into the WASLTPARealm, so you should already have access to it. Its just a matter of saving and retrieving it.

Related

NativeStorage gets cleared when I clear the cookie

I am trying to remove cookie using $.removeCookie() in my phonegap application, but it removes the NativeStorage (using the plugin cordova-plugin-native-storage) in my android.
The same problem repeats in IOS. But in IOS NativeStorage gets cleared once app is closed (even if I don't clear the cookie).
FYI : I am storing my login access token and few more details in cookies.
Any suggestion to keep the data to retain even if cookie is cleared?

Session time-out in webservices

I am developing a Restful Webservice using Eclipse and an android application. User logs in using its username and password on the android application which is checked against the database at the server side(using this web service).
Now, I want to maintain a session for which the user will remain logged in, that is, the user does not have to log in again and again whenever he re-opens the application.
How to do it? I searched on net but I could not find an accurate solution. Kindly help with the appropriate solution. Ask if more information is required.
use Shared Preferences to save session data .
there are good tutorials :
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
http://androidexample.com/Android_Session_Management_Using_SharedPreferences_-_Android_Example/index.php?view=article_discription&aid=127
This can be done in two ways. One is storing them in a global variables and second is storing the data in shared preferences. The problem with storing data in global variable is data will be lost once user closes the application, but storing the data in shared preferences will be persistent even though user closes the application. Here is the complete example:
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/

Setting cookies when php is accessed by android app

(I'm asking this partly for learning purposes, I realize what I'm trying to do might be entirely wrong!)
I have a php file on my website that handles log in and sets a cookie for the user if log in is successful. if setcookie() fails, I error out instead of displaying the rest of the page.
When I try to access this page using my android app (which uses HttpURLConnection with POST), the setcookie() fails. I'm guessing this is because the client isn't a browser and can't handle cookies.
so first of all, is there away for my app to be able to receive cookies from the server and store them? if not, how do you handle maintaining a login session with the user so you dont have to send a username and password, every time you want to access data from the server?
THanks
A couple of notes before the workaround:
The function is called setcookie() not set_cookie()
Android browsers do support cookies afaik, so you probably should look into this further. Perhaps the format of your setcookie call is not valid?
If you can't use cookies, then the workaround is to simulate your own session mechanism by passing your cookie value as a url parameter on every request.

How to store the cookie info when android killed my app

I have an app need login, I use a singleton http client to do everything, so it can track the cookies for me.
But when I launch a browser intent in my app to view some html pages, the app sometimes be killed by low memory, when user come back from the browser, my app activity would be recreated, but the new http client would not contains that login session id.
So I think what I need is to cache the cookies when my app get killed, and then restore it back when the app got recreated. I know there is a CookieSyncManager, but I do not have a full picture of how to use that.
(1) So How can I do that? is Cookie seralizable, I just thought to cache it in the sdcard, maybe a bad idea.
Another more general question maybe:
(2) How to share httpclient with webview/system browser? Not just pass cookies from httpclient to webiew/browser, but also get the cookies when initialize the cookies, How to make the http client and webview/browser share just ONE copy of cookie store in any time?
Use SharedPreferences to store cookies as string.
Take a look at this; http://developer.android.com/reference/android/app/Activity.html#SavingPersistentState
Also android developers use parcelable class, rather than serializable class. I think the reason is performance issues # mobile devices...

Why is Android's DefaultHttpClient not restoring session as expected?

I am using Android's DefaultHttpClient to communicate with my server, I run into this weird problem.
This is basically what I want to achieve: When one of my activity is closed(onPause is called), I store all my Cookies into SharedPreferences. And when another activity is activated, I restore the Cookies from SharedPreferences. By doing so, I can persist session between activities.
I achieved this by calling httpClient.getCookieStore().getCookies() and store all their information into SharedPrefenrences in my Activity's onPause mehod.
I restore it by retrieving cookies from SharedPrefenrences and call httpClient.getCookieStore().addCookie().
I have logged all the progress and saw no difference between the cookies when I stored them and the cookies when I retrieved then from SharedPrefrence.
The problem is it's not working, the server still thinks I am not logged in(I have logged in before I cleared all cookies and restore then from file).

Categories

Resources