From 4a2835ddadb796c69f180097b95f971dbab4687d Mon Sep 17 00:00:00 2001 From: ludc Date: 星期三, 13 九月 2023 09:09:14 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/endpoint/PwdFreeLoginEndpoint.java | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 95 insertions(+), 0 deletions(-) diff --git a/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/endpoint/PwdFreeLoginEndpoint.java b/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/endpoint/PwdFreeLoginEndpoint.java new file mode 100644 index 0000000..df1a80c --- /dev/null +++ b/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/endpoint/PwdFreeLoginEndpoint.java @@ -0,0 +1,95 @@ +//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鐨刾ostAccessToken鏂规硶鐢熸垚璁块棶浠ょ墝 +// //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; +// } + +//} -- Gitblit v1.9.3