有些新收获,先写下来。
1、在表中,access_token 验证的对应字段是token_id,refresh_token验证的对应字段也是token_id,传入的参数均需要加密进行比对。
2、关于具体的持久化流程:首先是Authentication创建出refreshToken,refreshToken中包含Id、序列化的实例,序列化的Authentication。 然后用Authentication+refreshToken创建出access_token, access_token中包含Id,序列化的实例,序列化的Authentication以及refreshToken的Id。也就是说access_token表和refresh_token中的Authentication是一模一样的。
3、当利用refreshToken获取token时,会直接删掉对应的access_token,后面再生成新的。refresh_token是否需要删除要看属性中的是否复用refresh_token的配置。
4、关于过期时间,在token生成的时候,就利用有效时间和当前时间计算出了一个过期时间戳,所以后面更改token的有效时间是没有用的,必须直接更改过期时间戳。需要用DefaultOAuth2AccessToken这个类包装起来才能set属性,最后还原成AccessToken的时候需要用:(OAuth2AccessToken) (this.accessTokenEnhancer != null ? this.accessTokenEnhancer.enhance(token, authentication) : token)