开发者

Tips for implementation of the spring-oauth RandomValueProviderTokenServices class

开发者 https://www.devze.com 2022-12-13 07:57 出处:网络
I need to implement the oauth spring persistence for RandomValueProviderTokenServices class. The class that needs to be stored according to the abstract protected methods of the RandomValueProviderTok

I need to implement the oauth spring persistence for RandomValueProviderTokenServices class. The class that needs to be stored according to the abstract protected methods of the RandomValueProviderTokenServices is OAuthProviderTokenImpl. however, this class contains a reference to Authentication interface which has various implementations.

I assume that implementations of these methods were done by any who used the spring-oauth library for the开发者_JAVA百科ir projects.

Is there a common practice to achieve that? ( without using the Java built it serialization mechanism).


I am working on this now and I am just storing a reference to the user in the database using their id. Then I generate the Authentication object based on that user object using this:

public Authentication getAuthentication(User user) {

 Object credentials = user.getUsername(); // the username of your user
    GrantedAuthority[] authorities = {new GrantedAuthorityImpl(user.getRole().getName())}; // an array of their role names

    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(user, credentials, authorities);
    auth.setDetails(user);

    return auth;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消