¶Ô±ÈÐÂÎļþ |
| | |
| | | //package com.vci.ubcs.auth.endpoint; |
| | | // |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | //import org.springframework.http.HttpStatus; |
| | | //import org.springframework.http.ResponseEntity; |
| | | //import org.springframework.security.core.Authentication; |
| | | //import org.springframework.security.oauth2.common.OAuth2AccessToken; |
| | | //import org.springframework.security.oauth2.provider.ClientDetailsService; |
| | | //import org.springframework.security.oauth2.provider.OAuth2RequestFactory; |
| | | //import org.springframework.security.oauth2.provider.TokenGranter; |
| | | //import org.springframework.security.oauth2.provider.TokenRequest; |
| | | //import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint; |
| | | //import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; |
| | | //import org.springframework.stereotype.Component; |
| | | //import org.springframework.util.LinkedMultiValueMap; |
| | | //import org.springframework.util.MultiValueMap; |
| | | //import org.springframework.web.HttpRequestMethodNotSupportedException; |
| | | //import org.springframework.web.bind.annotation.PostMapping; |
| | | //import org.springframework.web.bind.annotation.RequestMapping; |
| | | //import org.springframework.web.bind.annotation.RequestMethod; |
| | | //import org.springframework.web.bind.annotation.RequestParam; |
| | | // |
| | | //import java.util.Map; |
| | | // |
| | | ///** |
| | | // * å
å¯ç»å½ |
| | | // * @author ludc |
| | | // * @date 2023/9/12 18:03 |
| | | // */ |
| | | //@Component |
| | | //public class PwdFreeLoginEndpoint extends TokenEndpoint { |
| | | // |
| | | // |
| | | // @Autowired |
| | | // private AuthorizationServerTokenServices tokenServices; |
| | | // |
| | | // @Autowired |
| | | // private ClientDetailsService clientDetailsService; |
| | | // |
| | | // /*@Autowired |
| | | // private OAuth2RequestFactory requestFactory; |
| | | // |
| | | // @Autowired |
| | | // private TokenGranter tokenGranter;*/ |
| | | // |
| | | // @RequestMapping(value = "/oauth/password-free-login",method = RequestMethod.GET) |
| | | // public ResponseEntity<OAuth2AccessToken> getPasswordFreeLogin(@RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // return postPasswordFreeLogin(parameters); |
| | | // } |
| | | // |
| | | // @RequestMapping(value = "/oauth/password-free-login",method = RequestMethod.POST) |
| | | // public ResponseEntity<OAuth2AccessToken> postPasswordFreeLogin(@RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // // 夿æ¯å¦æ»¡è¶³å
å¯ç»å½çæ¡ä»¶ |
| | | // if (isSkipLogin(parameters)) { |
| | | // // çæè®¿é®ä»¤ç |
| | | // OAuth2AccessToken accessToken = createAccessToken(parameters); |
| | | // // è¿å访é®ä»¤ç |
| | | // return ResponseEntity.ok(accessToken); |
| | | // } |
| | | // |
| | | // // 䏿»¡è¶³å
å¯ç»å½æ¡ä»¶ï¼è¿åéè¯¯ä¿¡æ¯ |
| | | // return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); |
| | | // } |
| | | // |
| | | // private boolean isSkipLogin(Map<String, String> parameters) { |
| | | // // æ ¹æ®å
·ä½éæ±å¤ææ¯å¦æ»¡è¶³å
å¯ç»å½çæ¡ä»¶ |
| | | // // ä¾å¦ï¼å¤æè¯·æ±åæ°ä¸æ¯å¦å
å«æä¸ªç¹å®çæ è¯ç¬¦ |
| | | // return parameters.containsKey("skipLogin"); |
| | | // } |
| | | // |
| | | // private OAuth2AccessToken createAccessToken(Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // // æé 请æ±åæ° |
| | | // MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); |
| | | // for (Map.Entry<String, String> entry : parameters.entrySet()) { |
| | | // params.add(entry.getKey(), entry.getValue()); |
| | | // } |
| | | // |
| | | // // è°ç¨TokenEndpointçpostAccessTokenæ¹æ³çæè®¿é®ä»¤ç |
| | | // //return postAccessToken(PrincipalUtils.getPrincipal(), params).getBody(); |
| | | // return null; |
| | | // } |
| | | // |
| | | // private ResponseEntity<OAuth2AccessToken> postAccessToken(Authentication authentication, MultiValueMap<String, String> parameters) throws HttpRequestMethodNotSupportedException { |
| | | // // æé è¯·æ± |
| | | // // TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, clientDetailsService.loadClientByClientId("your-client-id")); |
| | | // |
| | | // // çæè®¿é®ä»¤ç |
| | | // // OAuth2AccessToken accessToken = tokenGranter.grant("password", tokenRequest); |
| | | // |
| | | // // è¿å访é®ä»¤ç |
| | | // //return ResponseEntity.ok(accessToken); |
| | | // return null; |
| | | // } |
| | | |
| | | //} |