packageorg.springframework.security.oauth2.provider.endpoint;publicclassTokenEndpointextendsAbstractEndpoint{/*** 登录方法,获取token信息*/@RequestMapping(value ="/oauth/token", method=RequestMethod.GET)publicResponseEntity<OAuth2AccessToken>getAccessToken(Principal principal,@RequestParamMap<String,String> parameters)throwsHttpRequestMethodNotSupportedException{if(!allowedRequestMethods.contains(HttpMethod.GET)){thrownewHttpRequestMethodNotSupportedException("GET");}returnpostAccessToken(principal, parameters);}@RequestMapping(value ="/oauth/token", method=RequestMethod.POST)publicResponseEntity<OAuth2AccessToken>postAccessToken(Principal principal,@RequestParamMap<String,String> parameters)throwsHttpRequestMethodNotSupportedException{if(!(principal instanceofAuthentication)){thrownewInsufficientAuthenticationException("There is no client authentication. Try adding an appropriate authentication filter.");}String clientId =getClientId(principal);ClientDetails authenticatedClient =getClientDetailsService().loadClientByClientId(clientId);TokenRequest tokenRequest =getOAuth2RequestFactory().createTokenRequest(parameters, authenticatedClient);if(clientId !=null&&!clientId.equals("")){// Only validate the client details if a client authenticated during this// request.if(!clientId.equals(tokenRequest.getClientId())){// double check to make sure that the client ID in the token request is the same as that in the// authenticated clientthrownewInvalidClientException("Given client ID does not match authenticated client");}}if(authenticatedClient !=null){oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);}if(!StringUtils.hasText(tokenRequest.getGrantType())){thrownewInvalidRequestException("Missing grant type");}if(tokenRequest.getGrantType().equals("implicit")){thrownewInvalidGrantException("Implicit grant type not supported from token endpoint");}if(isAuthCodeRequest(parameters)){// The scope was requested or determined during the authorization stepif(!tokenRequest.getScope().isEmpty()){logger.debug("Clearing scope of incoming token request");tokenRequest.setScope(Collections.<String>emptySet());}}if(isRefreshTokenRequest(parameters)){// A refresh token has its own default scopes, so we should ignore any added by the factory here.tokenRequest.setScope(OAuth2Utils.parseParameterList(parameters.get(OAuth2Utils.SCOPE)));}OAuth2AccessToken token =getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);if(token ==null){thrownewUnsupportedGrantTypeException("Unsupported grant type: "+ tokenRequest.getGrantType());}returngetResponse(token);}}