spring mvc store data in server without using database - spring

i am working on a chatbot and need to save context of the previous conversation so that it can be sent to the next message. Now i m integrating it with facebook where facebook doesn't send context and need to store this context somewhere in a server. my client doesn't want to use DB. i tried sessions but technically i dont have a UI (facebook is the UI) . Next i tried ehcache but not able to retrieve data of previous webhook calls. Please let me know if any there is a method to store data and retrieve it latter without using DB.

What you describe is not really a cache usage from what I can tell. That is you do not want to have entries disappear (eviction) and they do not get stale (expiration).
If that is correct, you will need to use the appropriate in-memory data structure so that you can store that information.
being more specific would require a bit more information about your system, the volume of data (per entry and max entries at once), etc ...

Related

Where to store client_id and client_secret in Oauth2?

I would like to bring a login with Github and Facebook to my single page web app, the server is under my control.
In this tutorial
https://spring.io/guides/tutorials/spring-boot-oauth2/
they store the client_id and client_secret in a file.
Wouldn't it be more convenient if I stored these 2 in my backend database ?
Let's say someone who's not a programmer would like to register the web app to a new service , he could do that easily opening the database, he doesn't have to crawl into the backend project code.
If not then where should these 2 be stored ?
If you talk about the convenience, storing these in a property file is a good option. By doing so, the properties can be easily loaded into the application during the startup. If you change the values, all you need to do is just restart the app and the new values will be reflected.
I am not sure I understand your non-programmer related comment 100%. But IMO, for a non-programmer, modifying a file is much easier than modifying the DB.
Just to be more clear, the client id and the client secret represents the credentials of your application registered with the social media (like facebook).
Ans yes, you can store these in DB as well. But then, you need to write code to fetch these values from the DB and load into your application.

Reconciling browser-side and server-side authentication

apologies if this has been asked but I'm trying to figure out this kind of stuff for the first time -
I'm developing an app where I want to divide the authenticated content from the web-facing side, completely; therefore I am not using a simple backbone.js-style "keep all views in one file" (unless I'm wrong about this, please illuminate!) but actually divided server files (using PHP).
Current flow: the user logs in client-side (using the Parse.com Todo app as an example) and, if successful, I store cookie (via POST/AJAX) with user email and the returned sessionToken on client side. I then thought that when user next visits site, the server can read cookie and shuffle the user to the private/locked portion of site, which, again, is a different set of PHP files.
Here I get lost -- how do I then tell Parse.com that the user is logged in, if I don't have her username/password (only email), and start grabbing data from the classes? Is there a way to do this that I'm not recognizing? I guess I can load different .JS files, read if a session exists, and JS-redirect to a different url, but that seems to me to be a weird way of going about it.
Is there a general philosophy/methodology to my questions that I should read up on, along concrete advice dealing with Parse.com questions?
I believe the Parse User session management functions should be good for you.
Check out https://parse.com/docs/cloud_code_guide#webapp-users
There is an example at the bottom of their announcement blog post here: http://blog.parse.com/2013/09/04/new-cloud-modules-for-images-and-users/
It gives you user session management with minimal effort.

when is the session data sent to server

HttpSession session=requestObj.getSession();
ArrayList<String> items=(ArrayList<String>)session.getAttribute("itemlist");
items.add(newitem);
In this code, why don't I need to set attribute
setAttribute("itemlist",items)
back to session object eventhough I updated the data in this session.
And as far as I know, session data are stored in server. So, when these data are sent to server?
You don't have to do ----setAttribute("itemlist",items)---because you have a reference to itemlist which you have stored in items.
ArrayList<String> items=(ArrayList<String>)session.getAttribute("itemlist");
So any changes you make to "items" will be visible in the "itemlist" attribute.
The data are sent to the server when you submit the form. A form could be submitted by clicking a submit button.
Your code is in Java, so I'm guessing it is running on the server already?
If you only have one server process, then you are directly modifying the same in-memory reference to the list which is already stored in the server session, so you will automatically see the changes.
However, you should actually call setAttribute any time you modify the state. If you are running in a cluster, or a cloud environment like Google App Engine which may be running multiple copies of your app, then this call will be used to propagate changes to the other processes.

is there a way to do session manage using sinatra framework with cloudfoundry?

none of the tutorials I found online seem to cover this. I mean that do but I'm not seeing what they say I should be seeing when I do the check. is this because I'm on the cloudfoundry platform? if you could direct me to some literature or give me a hint that would be great! I am trying to implement session control by some storing information in a cookie,review that cookie, and compare it to a session table in my db each time the user makes a HTTP request.
This is pretty straight forward. Just make sure you have sessions enabled in Sinatra and use the session_id as a key in your database. I created a little example at https://gist.github.com/danhigham/4943057
The example gets a tweet from twitter as json and retrieves a collection from Redis using the session_id as a key, adds the tweet to the collection as json and then stores it back in the same record.
I have also pushed the example to http://session-tweet.cloudfoundry.com

How to store additional user info?

Here's the issue at hand: I have developed an ASP.NET MVC3 application using Razor. I have also implemented a custom membership provider and overridden the ValidateUser() method. Within, I query my db and get a lot of user information in addition to the password auth.
At the moment, I am pushing this information, i.e. companyId, to static properties of a class. This works and I can display/use this information throughout my app. The problem arises when a user closes their browser tab. Upon re-opening the app, the user is authenticated via a cookie, so they don't need to re-login; however, those static variables are blown away.
So guys and girls, how would/do you conquer this issue? Should I append the extra info to the session cookie? Or perhaps a better solution?
Use the ProfileProvider in ASP.NET.
For application level variables, they are going to be subject to application pool recycles and similar "simulated" restarts related to users starting all over. These variables should be completely independent of user usage and should be able to be recreated easily. If you have variables that are user dependent or that can't be restored easily without some sort of outside intervention then you will definitely need a different method of storage.
If the data is user specific, storing it in the session cookie is probably the best idea. If the data is user-related but branches multiple users it should be stored in a database or a flat file somewhere. If the data has nothing to do with users specifically then it should just be in a database or configuration file.

Resources