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

2 Answers2

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.

David Weinberg
  • 543
  • 3
  • 9
  • 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 part is necessary though. – Raymond26 Dec 25 '13 at 07:55
-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.

Jorge
  • 1,403
  • 10
  • 12