Jelajahi Sumber

Merge branch '2.0' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into 2.0

LAPTOP-KB9HII50\70708 10 bulan lalu
induk
melakukan
d6710d6d28

+ 59 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/WlyyTokenGranter.java

@ -127,6 +127,14 @@ public class WlyyTokenGranter implements TokenGranter {
                        requestFactory,
                        userDetailsService
                ));
        tokenGranters.put(WxAppletsTokenGranter.GRANT_TYPE,
                new WxAppletsTokenGranter(
                        authenticationManager,
                        tokenServices,
                        clientDetailsService,
                        requestFactory,
                        userDetailsService
                ));
        tokenGranters.put(PwdAndCaptchaTokenGranter.GRANT_TYPE,
                new PwdAndCaptchaTokenGranter(
                        authenticationManager,
@ -652,6 +660,57 @@ public class WlyyTokenGranter implements TokenGranter {
                throw new InvalidGrantException("User account is locked");
            }
//            parameters.put("password",userDetails.getPassword());
            Authentication userAuth = new UsernamePasswordAuthenticationToken(username,userDetails.getPassword(),  this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()));
            ((AbstractAuthenticationToken) userAuth).setDetails(parameters);
            OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);
            return new OAuth2Authentication(storedOAuth2Request, userAuth);
        }
    }
    /**
     * 微信小程序登录
     */
    public static class WxAppletsTokenGranter extends AbstractTokenGranter {
        private static final String GRANT_TYPE = "wxApplets";
        private final AuthenticationManager authenticationManager;
        private final UserDetailsService userDetailsService;
        private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
        public WxAppletsTokenGranter(AuthenticationManager authenticationManager,
                                    AuthorizationServerTokenServices tokenServices,
                                    ClientDetailsService clientDetailsService,
                                    OAuth2RequestFactory requestFactory,
                                    UserDetailsService userDetailsService) {
            this(authenticationManager, tokenServices, clientDetailsService, requestFactory, userDetailsService, GRANT_TYPE);
        }
        protected WxAppletsTokenGranter(AuthenticationManager authenticationManager,
                                       AuthorizationServerTokenServices tokenServices,
                                       ClientDetailsService clientDetailsService,
                                       OAuth2RequestFactory requestFactory,
                                       UserDetailsService userDetailsService,
                                       String grantType) {
            super(tokenServices, clientDetailsService, requestFactory, grantType);
            this.authenticationManager = authenticationManager;
            this.userDetailsService = userDetailsService;
        }
        @Override
        protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
            Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters());
            String username = parameters.get("username");
            SaltUser userDetails = (SaltUser)userDetailsService.loadUserByUsername(username);
            if (!userDetails.isEnabled()) {
                throw new InvalidGrantException("User is disabled");
            }
            if (!userDetails.isAccountNonLocked()) {
                throw new InvalidGrantException("User account is locked");
            }
//            parameters.put("password",userDetails.getPassword());
            Authentication userAuth = new UsernamePasswordAuthenticationToken(username,userDetails.getPassword(),  this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()));
            ((AbstractAuthenticationToken) userAuth).setDetails(parameters);

+ 9 - 4
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -390,13 +390,18 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
            }
        } else if ("wxApplets".equals(flag)) {
            KeyPair keyPair = (KeyPair) httpSession.getAttribute("privateKey");
            String mobile = com.yihu.jw.security.utils.RSAUtils.decryptBase64(parameters.get("mobile"), keyPair);
            //微信小程序登录
            parameters.put("grant_type", "dingTalk");
            parameters.put("grant_type", "wxApplets");
            String authCode = parameters.get("authCode");
            if (org.apache.commons.lang3.StringUtils.isBlank(authCode)) {
                throw new InvalidRequestException("请求参数错误");
            String userPhone = "";
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(authCode)){
                userPhone = wechatService.getUserPhoneByApplets(authCode);
            }
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(mobile)){
                userPhone = mobile;
            }
            String userPhone = wechatService.getUserPhoneByApplets(authCode);
            if (!StringUtils.isEmpty(userPhone)) {
                //判断手机号是否注册
                int count = userDetailsService.checkMobile(userPhone,loginType);