Spring HttpSession on Redis change key name - spring

I have my multiservices app that use spring HttpSession on Redis.
All works fine but I want to know if is there a way to change the key value.
To understand better, spring stores session data on redis on key "spring:session:......"
I want to append the name of my app on the head:
"myappname:spring:session:...."
Someone knows if is it possible?
Thanks

In your properties file try to add :
spring.session.redis.namespace= myapp # Namespace for keys used to store sessions.
you will have somthing like:
spring:session:myapp

Related

aspnetboilerplate session timeout & redis implementation

I am using ABP framework with MVC 5 and deployed into Azure. I have listed few session related questions below.
I used HttpContext.Current.Session in WebMpa project and AbpSession in Application services, but unable to get the data from AbpSession using HttpContext.Current.Session in WebMpa project, both are saving data in different place?
Am using static helper class and static property to Get/Set HttpContext.Current.Session value, if i want to remove the HttpContext.Current.Session any easiest way is available(with minimal code change), it could be better if we can get AbpSession from that static class?
I want to alert users 20 secs prior to session expired, is there any build in option available in ABP?
If I enable to Redis Cache implementation in my application, Cache, HttpContext.Current.Session, AbpSession and TempData will works without any issues and all should Get/Set values from Redis datasource?
AbpSession is not extending HttpContext.Current.Session. So the answer is yes you cannot share data btw AbpSession and Session.
Don't use static for injectable types. bad practise!
There's no built-in function for that. You can achieve this with a javascript function. When you finish a request, start timer. You know the session timeout duration. So when it reaches to 20secs, show an alert window to continue session. If answer is Yes then make a new request to slide session.
No! As i stated, Session and AbpSession is totally different things and you cannot share btw them.
PS: AbpSession stores claims. And it's extendable. So you can store any item in AbpSession. See the link to understand how to extend AbpSession https://gist.github.com/hikalkan/67469e05475c2d18cb88

How to encrypt mongo db password with jasypt?

spring.data.mongodb.uri=mongodb://user:secret#mongo1.example.com:12345,mongo2.e
xample.com:12345/mydb?replicaSet=rsdb
Here i want to encript the password(secret)with jasypt.So the url should be
like:
spring.data.mongodb.uri=mongodb://user:ENC(xIZhIV7nvOv5LqHfAKnvmjhyeecOT0lO)#mongo1.example.com:12345,mongo2.example.com:12345/mydb?replicaSet=rsdb
but mongo is not understanding the password even if the jasypt encryption logic is already implemented.
I got the solution:
Since it is not resolving encrypted value from url, we can put it in it's own property and then reference that property in the url.
spring.data.mongodb.password=ENC(xIZhIV7nvOv5LqHfAKnvmjhyeecOT0lO)
spring.data.mongodb.uri=mongodb://user:${spring.data.mongodb.password}#mongo1.example.com:12345,mongo2.example.com:12345/mydb?replicaSet=rsdb

Persist a Spring Java Object into Magnolia repository

If i had an additional Spring application extending my Magnolia, which gets some Java Object, which will be used inside my application, how can i save it ???
I already learned to do queries, but i cannot use it yet to put something in or change it. I can only fetch data. into nodes.
where or how do i persist ??
For Info: I have a repository which shall store the special data and i have a nodetype declared for this. As it is now the spring social UserConnection i have the workspace "connections" with nodeType mgnl:userConnection
My JavaObject is a UserConnection, designed near to MgnlUser, so i also add properties, but i don't know yet, what to do with path and uuid.
i don't know yet how to declare it or where to get it.
You can store the data same way as you fetch it. Assuming you are running your spring app through Magnolia filter chain you have MgnlContext setup for given thread and can easily call MgnlContext.getJCRSession("connections") to obtain the session and node same way you do to retrieve your data, to add subnodes or set properties on given node you just call node.addNode("myNewNode") or node.setProperty("myProp", "newValue") on the node and follow that with call to session.save() to persist the session info. But I guess you already know all that.
If you want to get whole object serialised into repo for you by system instead, you can use JackRabbit OCM for this, or even easier - use integration of OCM into Magnolia - http://jira.magnolia-cms.com/browse/MJROCM
. It's already used in Shop module of Magnolia if you are looking for examples on how to work with OCM.
HTH,
Jan

How do I get the Session ID in a Symfony action?

I'm using Symfony 1.4 and Doctrine 1.2. I need to get the session ID inside an action.
I'm using doctrine session storage and that works fine. I'm also using sfDoctrineGuardPlugin and am able to get and set session variables in the user according to recommended practice, using code like this:
$this->getUser()->setAttribute('variable_name', $value);
$value = $this->getUser()->getAttribute('variable_name');
But how do I get the session id of the current user?
It seems like you can't access the sfStorage from the user object. The sfSessionStorage stores the user data in the session...
So the only way I currently see is calling the 'native' session_id().
If you want to it perfectly you should extends the sfSessionStorage adding a method to retrieve the session id. Then assign this storage to the user, and you would be able to call $this->getUser()->getStorage()->getSessionId();.

Using Session Vars in a MVC Domain Model library

I have a IQueryable function. In that function, I need to store and retrieve data to Session; can you guys point me in the right direction.
I've looked at the HttpSessionStatBase where the session is usually taken from HttpContext.Current but this doesnt seem possible to do in the library. Am I missing something?
Thanks in advance.
I would avoid having a dependency on the static HttpContext. My preferred strategy would be to extract the information from the session in the controller and pass it as parameters (or set as properties) on your data access layer/repository. If you feel that you must use the Session directly, then I would provide it to the DAL/repository in the same manner -- as a property or as a parameter. Note, however, that you are increasing the coupling between your DAL/repository and the controller. This will make it much more difficult to re-use in a non-web setting, i.e., you'd have to create a fake session just to interact with the DAL/repository if you ever needed to work with it from a windows service or console app, for example.

Resources