securesocial fake log in when developing

2020-03-03 07:17发布

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条回答
Anthone
2楼-- · 2020-03-03 08:07

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.

查看更多
叛逆
3楼-- · 2020-03-03 08:11

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.

查看更多
登录 后发表回答