| | |
| | | import org.springframework.security.oauth2.provider.*; |
| | | import org.springframework.security.oauth2.provider.token.*; |
| | | import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; |
| | | //import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | |
| | |
| | | @Deprecated |
| | | public class SingleTokenServices implements AuthorizationServerTokenServices, ResourceServerTokenServices, ConsumerTokenServices, InitializingBean { |
| | | private int refreshTokenValiditySeconds = 2592000; |
| | | private int accessTokenValiditySeconds = 43200; |
| | | private int accessTokenValiditySeconds = 10800;//43200 //登录时,给的默认值;一段时间后,用的查询数据库中的oauth_client_details的表的access_token_validity; |
| | | private boolean supportRefreshToken = false; |
| | | private boolean reuseRefreshToken = true; |
| | | private TokenStore tokenStore; |
| | |
| | | public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException, InvalidTokenException { |
| | | OAuth2AccessToken accessToken = this.tokenStore.readAccessToken(accessTokenValue); |
| | | if (accessToken == null) { |
| | | throw new InvalidTokenException("Invalid access token: " + accessTokenValue); |
| | | throw new InvalidTokenException("Invalid access token:1 " + accessTokenValue); |
| | | } else if (accessToken.isExpired()) { |
| | | this.tokenStore.removeAccessToken(accessToken); |
| | | throw new InvalidTokenException("Access token expired: " + accessTokenValue); |
| | | } else { |
| | | OAuth2Authentication result = this.tokenStore.readAuthentication(accessToken); |
| | | if (result == null) { |
| | | throw new InvalidTokenException("Invalid access token: " + accessTokenValue); |
| | | throw new InvalidTokenException("Invalid access token:2 " + accessTokenValue); |
| | | } else { |
| | | if (this.clientDetailsService != null) { |
| | | String clientId = result.getOAuth2Request().getClientId(); |
| | |
| | | public String getClientId(String tokenValue) { |
| | | OAuth2Authentication authentication = this.tokenStore.readAuthentication(tokenValue); |
| | | if (authentication == null) { |
| | | throw new InvalidTokenException("Invalid access token: " + tokenValue); |
| | | throw new InvalidTokenException("Invalid access token:3 " + tokenValue); |
| | | } else { |
| | | OAuth2Request clientAuth = authentication.getOAuth2Request(); |
| | | if (clientAuth == null) { |