securesocial fake log in when developing
Asked Answered
E

2

5

I am using securesocial it works fine but now every time I change some scala code I have to login again. Is there a possibility to fake a user in the session when in development mode, so I don't have to login so often?

Thanks,

Joris Wijlens

Explode answered 1/11, 2012 at 15:5 Comment(3)
Strange... Are you clearing your cookies somewhere (in Global.onStop() or somewhere else) ?Semiconductor
Not that i am aware of. So this is not the default behaviour?Explode
The problem went away after switching to a database implementation for the userserviceExplode
P
-2

That happens because in DEV mode Play restarts the app when you change your code. So, the data in the sample user service is lost.

Palila answered 4/11, 2012 at 3:10 Comment(0)
G
12

SecureSocial by default uses the default Play cache for storing authenticators (that match the cookies to the logged in user). The default play cache is EHCache and it's configured using the ehcache.xml that you can find in the jars. The default configuration is strictly in memory which means that when the app restarts, it loses all the values. Fortunately, it's pretty easy to overwrite the EHCache configuration to write to the disk.

Copy the ehcache.xml in the jars to your configuration directory. Add <diskStore path="java.io.tmpdir"/> and change diskPersistent to true

So mine looks like this:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false">
<diskStore path="java.io.tmpdir"/>
<defaultCache
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="false"
        maxElementsOnDisk="10000000"
        diskPersistent="true"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU"
        />
</ehcache>

If you're interested learning how to configure the rest of it, there is some documentation in the ehcache-failsafe.xml file that's also in the Play jars.

Galliot answered 27/8, 2013 at 1:59 Comment(1)
For Play 2.2, I found the ehcache-default.xml file in play/framework/src/play-cache/src/main/resources/. I renamed it to ehcache.xml and put it in the conf directory of my project. I just set diskPersistent to true and it worked. Not sure if the <diskStore path ...> part is necessary though.Banderilla
P
-2

That happens because in DEV mode Play restarts the app when you change your code. So, the data in the sample user service is lost.

Palila answered 4/11, 2012 at 3:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.