Does JpaTokenStore have any downsides when compared to JdbcTokenStore for spring security oauth

妖精的绣舞 提交于 2019-12-19 21:52:50

问题


I currently use Jpa via Hibernate in my application. Since spring security oauth2 provides JdbcTokenStore, I started using it. But the problem with that is, I cannot use cache (which all my entities in the application currently share).

It hits the database in a separate flow.

I am thinking implementing JpaTokenStore thats backed by Jpa & leverage the cache advantages that comes with it.

Did anyone try implementing this/see any downsides using this approach?


回答1:


There is nothing stopping you from doing it, and plenty of people do use JPA for all sorts of things, but IMO JPA is not ideal for handling storage of identity data. JPA is designed and optimized for cacheing data for the duration of a JDBC connection (a transaction basically), while identity data have a typically different and much longer lifetime. If you store long lived data using JPA, you have to deal with the consequences of what happens when you access it outside its normal lifetime, e.g. use DTOs, which ends up negating the benefits of using it in the first place to some extent.




回答2:


In one project I've implmented org.springframework.security.oauth2.client.token.ClientTokenServices with JPA and didn't notice any problems. I was able to use all standard features of JPA including @Transactional for JPAClientTokenServices#saveAccessToken



来源:https://stackoverflow.com/questions/38355194/does-jpatokenstore-have-any-downsides-when-compared-to-jdbctokenstore-for-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!