|
15 | 15 | * |
16 | 16 | */ |
17 | 17 |
|
18 | | -package org.minbox.framework.api.boot.plugin.oauth; |
| 18 | +package org.minbox.framework.api.boot.plugin.oauth.grant; |
19 | 19 |
|
20 | | -import org.minbox.framework.api.boot.plugin.oauth.grant.ApiBootOauthTokenGranter; |
21 | | -import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; |
22 | | -import org.springframework.security.oauth2.common.OAuth2AccessToken; |
23 | | -import org.springframework.security.oauth2.provider.ClientDetailsService; |
24 | | -import org.springframework.security.oauth2.provider.OAuth2RequestFactory; |
25 | | -import org.springframework.security.oauth2.provider.TokenRequest; |
| 20 | +import org.springframework.security.authentication.AbstractAuthenticationToken; |
| 21 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| 22 | +import org.springframework.security.core.Authentication; |
| 23 | +import org.springframework.security.core.userdetails.UserDetails; |
| 24 | +import org.springframework.security.oauth2.provider.*; |
26 | 25 | import org.springframework.security.oauth2.provider.token.AbstractTokenGranter; |
27 | 26 | import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; |
28 | 27 |
|
@@ -60,25 +59,22 @@ public DefaultApiBootOauthTokenGranter(AuthorizationServerTokenServices tokenSer |
60 | 59 | } |
61 | 60 |
|
62 | 61 | /** |
63 | | - * grant access token |
| 62 | + * get oauth2 authentication |
64 | 63 | * |
65 | | - * @param grantType grant type |
66 | | - * @param tokenRequest create token parameter |
67 | | - * @return |
| 64 | + * @param client client detail |
| 65 | + * @param tokenRequest token request |
| 66 | + * @return oauth2 authentication |
68 | 67 | */ |
69 | 68 | @Override |
70 | | - public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) { |
71 | | - // create token request parameters |
72 | | - Map<String, String> parameters = new LinkedHashMap(tokenRequest.getRequestParameters()); |
| 69 | + protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) { |
| 70 | + Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters()); |
73 | 71 |
|
74 | | - // valid |
75 | | - apiBootOauthTokenGranter.valid(parameters); |
| 72 | + UserDetails userDetails = apiBootOauthTokenGranter.loadByParameter(parameters); |
76 | 73 |
|
77 | | - // create token |
78 | | - OAuth2AccessToken token = super.grant(grantType, tokenRequest); |
79 | | - if (token != null) { |
80 | | - token = new DefaultOAuth2AccessToken(token); |
81 | | - } |
82 | | - return token; |
| 74 | + Authentication userAuth = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); |
| 75 | + ((AbstractAuthenticationToken) userAuth).setDetails(parameters); |
| 76 | + |
| 77 | + OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest); |
| 78 | + return new OAuth2Authentication(storedOAuth2Request, userAuth); |
83 | 79 | } |
84 | 80 | } |
0 commit comments