浏览代码

云照护登录修改

LAPTOP-KB9HII50\70708 1 年之前
父节点
当前提交
c9fe6c5a49

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

@ -125,6 +125,16 @@ public class WlyyTokenGranter implements TokenGranter {
                        requestFactory,
                        userDetailsService
                ));
        tokenGranters.put(PwdAndCaptchaTokenGranter.GRANT_TYPE,
                new PwdAndCaptchaTokenGranter(
                        authenticationManager,
                        tokenServices,
                        clientDetailsService,
                        requestFactory,
                        userDetailsService,
                        wlyyRedisVerifyCodeService
                ));
    }
    public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
@ -644,5 +654,73 @@ public class WlyyTokenGranter implements TokenGranter {
            return new OAuth2Authentication(storedOAuth2Request, userAuth);
        }
    }
    /**
     * 密码+验证码登录
     */
    public static class PwdAndCaptchaTokenGranter extends AbstractTokenGranter {
        private static final String GRANT_TYPE = "pwdAndCaptcha";
        private final AuthenticationManager authenticationManager;
        private final UserDetailsService userDetailsService;
        private final WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService;
        private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
        public PwdAndCaptchaTokenGranter(AuthenticationManager authenticationManager,
                                    AuthorizationServerTokenServices tokenServices,
                                    ClientDetailsService clientDetailsService,
                                    OAuth2RequestFactory requestFactory,
                                    UserDetailsService userDetailsService,
                                    WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService) {
            this(authenticationManager, tokenServices, clientDetailsService, requestFactory, userDetailsService,wlyyRedisVerifyCodeService, GRANT_TYPE);
        }
        protected PwdAndCaptchaTokenGranter(AuthenticationManager authenticationManager,
                                       AuthorizationServerTokenServices tokenServices,
                                       ClientDetailsService clientDetailsService,
                                       OAuth2RequestFactory requestFactory,
                                       UserDetailsService userDetailsService,
                                       WlyyRedisVerifyCodeService wlyyRedisVerifyCodeService,
                                       String grantType) {
            super(tokenServices, clientDetailsService, requestFactory, grantType);
            this.authenticationManager = authenticationManager;
            this.wlyyRedisVerifyCodeService = wlyyRedisVerifyCodeService;
            this.userDetailsService = userDetailsService;
        }
        @Override
        protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
            Map<String, String> parameters = new LinkedHashMap<String, String>(tokenRequest.getRequestParameters());
            String client_id = parameters.get("client_id");
            String username = parameters.get("username");
            String captcha = parameters.get("captcha");
            //todo cyx  部署应取消注释(自测试,可注释,不验证短信直接登录)
            if (!wlyyRedisVerifyCodeService.verification(client_id, username, captcha)){
                throw new InvalidGrantException("Invalid captcha");
            }
            String password = parameters.get("password");
            parameters.remove("password");
            Authentication userAuth = new UsernamePasswordAuthenticationToken(username, password);
            ((AbstractAuthenticationToken) userAuth).setDetails(parameters);
            try {
                userAuth = authenticationManager.authenticate(userAuth);
            }
            catch (AccountStatusException ase) {
                throw new InvalidGrantException(ase.getMessage());
            }
            catch (BadCredentialsException e) {
                throw new InvalidGrantException(e.getMessage());
            }
            if (userAuth == null || !userAuth.isAuthenticated()) {
                throw new InvalidGrantException("Could not authenticate user: " + username);
            }
            OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest);
            return new OAuth2Authentication(storedOAuth2Request, userAuth);
        }
    }
}

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

@ -337,11 +337,11 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        String key = parameters.get("key");
        String text = parameters.get("text");
        if(org.apache.commons.lang3.StringUtils.isNotBlank(key)&& org.apache.commons.lang3.StringUtils.isNotBlank(text)){
            if(!verifyCaptcha(key,text)){
                throw new ImgCaptchaException("验证码错误!");
            }
        }
//        if(org.apache.commons.lang3.StringUtils.isNotBlank(key)&& org.apache.commons.lang3.StringUtils.isNotBlank(text)){
//            if(!verifyCaptcha(key,text)){
//                throw new ImgCaptchaException("验证码错误!");
//            }
//        }
        logger.info("login:登录进入2");
        String flag = parameters.get("flag");
@ -404,6 +404,16 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                Oauth2Envelop<WlyyUserSimple> oauth2Envelop = new Oauth2Envelop<>("获取用户手机号失败", -1, null);
                return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
            }
        } else if("1".equals(parameters.get("pwdAndCaptcha"))){
            parameters.put("grant_type", "pwdAndCaptcha");
            if (!testPwd(parameters.get("password"))) {
                throw new PwdException("密码强度低,请用验证码登录,或者修改密码后在重新登录!");
            }else {
            }
//            KeyPair keyPair = (KeyPair) httpSession.getAttribute("privateKey");
//            String password = com.yihu.jw.security.utils.RSAUtils.decryptBase64(parameters.get("password"), keyPair);
//            parameters.put("password", password);
        }else if (StringUtils.isEmpty(parameters.get("captcha"))) {
            parameters.put("grant_type", "password");
            //解密密码
@ -433,7 +443,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
        }
            //账户密码登录的才验证密码强度
        //账户密码登录的才验证密码强度
        if ("hz_yyyzh_wx".equals(wechatId)||
                "iottest".equals(springProfile)||//物联网
                "iotprod".equals(springProfile)||//物联网
@ -442,7 +452,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            String grant_type = parameters.get("grant_type");
            if ("password".equals(grant_type)) {
                if (!testPwd(parameters.get("password"))) {
                    throw new PwdException("密码强度低,请用验证码登录,或者修改密码后在从新登录!");
                    throw new PwdException("密码强度低,请用验证码登录,或者修改密码后在重新登录!");
                }
            }
        }
@ -1093,9 +1103,9 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            }
        }
        if("xm_ykyy_wx".equals(wxId)){
           return sendYKCaptcha(parameters);
            return sendYKCaptcha(parameters);
        }else if("xm_zsyy_wx".equals(wxId)){
           return sendZSCaptcha(parameters);
            return sendZSCaptcha(parameters);
        }else if ("xm_xzzx_wx".equals(wxId)){
            return sendXZCaptcha(parameters);
        }else if ("sd_tnzyy_wx".equals(wxId)){
@ -1547,7 +1557,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            //固定秘钥解密
            String key = "FEA5049E4CCD16A9";
            String result = AesEncryptUtils.decrypt(data,key);
          /*  String result = AES.decrypt(key,data);*/
            /*  String result = AES.decrypt(key,data);*/
            logger.info("wjwLogin :"+result);
@ -2474,7 +2484,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    }*/
    @RequestMapping(value = "/oauth/registerPatientAndLogin", method = RequestMethod.POST)
    public ObjEnvelop registerPatientAndLogin(String name, String mobile, String idcard, String ssc, String pw,String client_id,String login_type,String captcha,String openid,String wxId
    ,String geetestChallenge,String geetestValidate,String geetestSeccode )throws Exception{
            ,String geetestChallenge,String geetestValidate,String geetestSeccode )throws Exception{
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
@ -2651,7 +2661,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    @RequestMapping(value = "/oauth/findDoctorPw", method = RequestMethod.POST)
    public Envelop findDoctorPw(String mobile,String client_id,String captcha,String pw) throws Exception{
        if("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
           String response =  ykyyService.ResetPwd(mobile,pw,captcha);
            String response =  ykyyService.ResetPwd(mobile,pw,captcha);
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(response)){
                JSONObject object = JSONObject.parseObject(response);
                if (object.getString("code").equalsIgnoreCase("10000")){
@ -2780,10 +2790,10 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
            List<BasePatientDO> patientSize = new ArrayList<>();
            switch (type){
                case "idcard":
                     patientSize = basePatientDao.findByIdcard(id);
                    patientSize = basePatientDao.findByIdcard(id);
                    break;
                case "mobile":
                     patientSize = basePatientDao.findByMobile(id);
                    patientSize = basePatientDao.findByMobile(id);
                    break;
            }
            if (patientSize.size()<0){
@ -3275,108 +3285,108 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                        return getFailedResponse(object.getString("msg"),-1,userSimple);
                    }
                }
                    String response = ykyyService.yktLogin(parameters.get("username"),password);
                    if (!StringUtils.isEmpty(response)){
                        JSONObject object = JSONObject.parseObject(response);
                        if (!object.getString("code").equalsIgnoreCase("200")){
                            throw new Exception(object.getString("msg"));
                        }else {
                            JSONObject jsonObject = object.getJSONObject("data");
                            if (jsonObject!=null){
                                String userId= jsonObject.getString("ID");
                                String tel = jsonObject.getString("LOGINID");
                                List<BasePatientDO> basePatientDOS = basePatientDao.findByMobile(tel);
                                if (basePatientDOS==null||basePatientDOS.size()==0){
                                    BasePatientDO basePatientDO = new BasePatientDO();
                                    String familyList = ykyyService.getFamilyList(null,userId);
                                    JSONObject familyJson = JSONObject.parseObject(familyList);
                                    if (familyJson.getString("code").equalsIgnoreCase("200")){
                                        JSONObject object1 = familyJson.getJSONObject("data");
                                        JSONArray list = object1.getJSONArray("list");
                                        List<String> iliness = new ArrayList<>();
                                        if (list!=null&&list.size()!=0){
                                            for (int i=0;i<list.size();i++){
                                                JSONObject family = list.getJSONObject(i);
                                                iliness.add(family.getString("ILLNESS"));
                                                if (family.getString("ILLNESS").equalsIgnoreCase("本人")&&tel.equalsIgnoreCase(family.getString("TEL"))){
                String response = ykyyService.yktLogin(parameters.get("username"),password);
                if (!StringUtils.isEmpty(response)){
                    JSONObject object = JSONObject.parseObject(response);
                    if (!object.getString("code").equalsIgnoreCase("200")){
                        throw new Exception(object.getString("msg"));
                    }else {
                        JSONObject jsonObject = object.getJSONObject("data");
                        if (jsonObject!=null){
                            String userId= jsonObject.getString("ID");
                            String tel = jsonObject.getString("LOGINID");
                            List<BasePatientDO> basePatientDOS = basePatientDao.findByMobile(tel);
                            if (basePatientDOS==null||basePatientDOS.size()==0){
                                BasePatientDO basePatientDO = new BasePatientDO();
                                String familyList = ykyyService.getFamilyList(null,userId);
                                JSONObject familyJson = JSONObject.parseObject(familyList);
                                if (familyJson.getString("code").equalsIgnoreCase("200")){
                                    JSONObject object1 = familyJson.getJSONObject("data");
                                    JSONArray list = object1.getJSONArray("list");
                                    List<String> iliness = new ArrayList<>();
                                    if (list!=null&&list.size()!=0){
                                        for (int i=0;i<list.size();i++){
                                            JSONObject family = list.getJSONObject(i);
                                            iliness.add(family.getString("ILLNESS"));
                                            if (family.getString("ILLNESS").equalsIgnoreCase("本人")&&tel.equalsIgnoreCase(family.getString("TEL"))){
                                                basePatientDO.setDel("1");
                                                basePatientDO.setName(family.getString("NAME"));
                                                basePatientDO.setCreateTime(new Date());
                                                basePatientDO.setUpdateTime(new Date());
                                                basePatientDO.setYktId(family.getString("ID"));
                                                basePatientDO.setUserId(userId);
                                                basePatientDO.setIdcard(family.getString("IDCARD"));
                                                String idcard = family.getString("IDCARD");
                                                Integer age = IdCardUtil.getAgeForIdcard(idcard);
                                                String sex = IdCardUtil.getSexForIdcard_new(idcard);
                                                Integer sexx = null;
                                                if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
                                                    sexx = Integer.parseInt(sex);
                                                }
                                                String birthDay = family.getString("BIRTHDAY");
                                                Date birthday = null;
                                                if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthDay)){
                                                    birthday = DateUtil.strToDate(birthDay+" 00:00:00");;
                                                }
                                                basePatientDO.setBirthday(birthday);
                                                basePatientDO.setSex(sexx);
                                                basePatientDO.setMobile(tel);
                                                String salt = UUID.randomUUID().toString().substring(0,5);
                                                String pw = idcard.substring(idcard.length()-6,idcard.length());
                                                basePatientDO.setIdcard(idcard);
                                                basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                                basePatientDO.setSalt(salt);
                                                basePatientDO.setLocked(0);
                                                basePatientDO.setEnabled(1);
                                                basePatientDO.setVerifyCode(jsonObject.getString("TOKEN"));
                                                basePatientDO.setPatientStatus("1");
                                                basePatientDao.save(basePatientDO);
                                            }else {
                                                List<BasePatientDO> basePatientDOList = basePatientDao.findByMobile(tel);
                                                if(basePatientDOList==null||basePatientDOList.size()==0){
                                                    basePatientDO.setDel("1");
                                                    basePatientDO.setName(family.getString("NAME"));
                                                    if (jsonObject.getString("USERNAME").length()>=2){
                                                        basePatientDO.setName(jsonObject.getString("USERNAME"));
                                                    }else {
                                                        basePatientDO.setName(tel);
                                                    }
                                                    basePatientDO.setCreateTime(new Date());
                                                    basePatientDO.setUpdateTime(new Date());
                                                    basePatientDO.setYktId(family.getString("ID"));
                                                    basePatientDO.setYktId(jsonObject.getString("ID"));
                                                    basePatientDO.setUserId(userId);
                                                    basePatientDO.setIdcard(family.getString("IDCARD"));
                                                    String idcard = family.getString("IDCARD");
                                                    Integer age = IdCardUtil.getAgeForIdcard(idcard);
                                                    String sex = IdCardUtil.getSexForIdcard_new(idcard);
                                                    Integer sexx = null;
                                                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
                                                        sexx = Integer.parseInt(sex);
                                                    }
                                                    String birthDay = family.getString("BIRTHDAY");
                                                    Date birthday = null;
                                                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthDay)){
                                                        birthday = DateUtil.strToDate(birthDay+" 00:00:00");;
                                                    }
                                                    basePatientDO.setBirthday(birthday);
                                                    basePatientDO.setSex(sexx);
                                                    basePatientDO.setMobile(tel);
                                                    String salt = UUID.randomUUID().toString().substring(0,5);
                                                    String pw = idcard.substring(idcard.length()-6,idcard.length());
                                                    basePatientDO.setIdcard(idcard);
                                                    String pw = tel.substring(tel.length()-6,tel.length());
                                                    basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                                    basePatientDO.setSalt(salt);
                                                    basePatientDO.setLocked(0);
                                                    basePatientDO.setEnabled(1);
                                                    basePatientDO.setVerifyCode(jsonObject.getString("TOKEN"));
                                                    basePatientDO.setPatientStatus("1");
                                                    basePatientDao.save(basePatientDO);
                                                }else {
                                                    List<BasePatientDO> basePatientDOList = basePatientDao.findByMobile(tel);
                                                    if(basePatientDOList==null||basePatientDOList.size()==0){
                                                        basePatientDO.setDel("1");
                                                        if (jsonObject.getString("USERNAME").length()>=2){
                                                            basePatientDO.setName(jsonObject.getString("USERNAME"));
                                                        }else {
                                                            basePatientDO.setName(tel);
                                                        }
                                                        basePatientDO.setCreateTime(new Date());
                                                        basePatientDO.setUpdateTime(new Date());
                                                        basePatientDO.setYktId(jsonObject.getString("ID"));
                                                        basePatientDO.setUserId(userId);
                                                        basePatientDO.setMobile(tel);
                                                        String salt = UUID.randomUUID().toString().substring(0,5);
                                                        String pw = tel.substring(tel.length()-6,tel.length());
                                                        basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                                        basePatientDO.setSalt(salt);
                                                        basePatientDO.setLocked(0);
                                                        basePatientDO.setEnabled(1);
                                                        basePatientDO.setPatientStatus("1");
                                                        basePatientDao.save(basePatientDO);
                                                    }
                                                }
                                            }
                                        }else {
                                        }
                                    }else {
                                            if (jsonObject.getString("USERNAME").length()>=2){
                                                basePatientDO.setName(jsonObject.getString("USERNAME"));
                                            }else {
                                                basePatientDO.setName(tel);
                                            }
                                            basePatientDO.setDel("1");
                                            basePatientDO.setCreateTime(new Date());
                                            basePatientDO.setUpdateTime(new Date());
                                            basePatientDO.setUserId(userId);
                                            basePatientDO.setMobile(tel);
                                            String salt = UUID.randomUUID().toString().substring(0,5);
                                            String pw = tel.substring(tel.length()-6,tel.length());
                                            basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                            basePatientDO.setSalt(salt);
                                            basePatientDO.setLocked(0);
                                            basePatientDO.setEnabled(1);
                                            basePatientDO.setPatientStatus("1");
                                            basePatientDao.save(basePatientDO);
                                        if (jsonObject.getString("USERNAME").length()>=2){
                                            basePatientDO.setName(jsonObject.getString("USERNAME"));
                                        }else {
                                            basePatientDO.setName(tel);
                                        }
                                        basePatientDO.setDel("1");
                                        basePatientDO.setCreateTime(new Date());
                                        basePatientDO.setUpdateTime(new Date());
                                        basePatientDO.setUserId(userId);
                                        basePatientDO.setMobile(tel);
                                        String salt = UUID.randomUUID().toString().substring(0,5);
                                        String pw = tel.substring(tel.length()-6,tel.length());
                                        basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                                        basePatientDO.setSalt(salt);
                                        basePatientDO.setLocked(0);
                                        basePatientDO.setEnabled(1);
                                        basePatientDO.setPatientStatus("1");
                                        basePatientDao.save(basePatientDO);
                                    }
                                    /*String birdth = com.yihu.jw.util.idcard.IdCardUtil.getBirthdayForIdcardStr(basePatientDO.getIdcard());
                                    Integer age = com.yihu.jw.util.idcard.IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard());
                                    Integer sex = basePatientDO.getSex()!=null?basePatientDO.getSex():0;
@ -3387,21 +3397,21 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                                    }else {
                                        ykyyService.addFamily(basePatientDO.getUserId(),basePatientDO.getIdcard(),basePatientDO.getName(),sex+"",birdth,age+"",basePatientDO.getMobile());
                                    }*/
                                }
                            }else {
                                logger.info("======"+jsonObject.getString("USERNAME")+"======");
                                logger.info("tel"+jsonObject.getString("USERNAME"));
                                BasePatientDO basePatientDO1 = basePatientDOS.get(0);
                                if (basePatientDO1.getName()==null||basePatientDO1.getName()==""){
                                    if (jsonObject.getString("USERNAME").length()>=2){
                                        basePatientDO1.setName(jsonObject.getString("USERNAME"));
                                    }else {
                                        basePatientDO1.setName(tel);
                                    }
                                }else {
                                    logger.info("======"+jsonObject.getString("USERNAME")+"======");
                                    logger.info("tel"+jsonObject.getString("USERNAME"));
                                    BasePatientDO basePatientDO1 = basePatientDOS.get(0);
                                    if (basePatientDO1.getName()==null||basePatientDO1.getName()==""){
                                        if (jsonObject.getString("USERNAME").length()>=2){
                                            basePatientDO1.setName(jsonObject.getString("USERNAME"));
                                        }else {
                                            basePatientDO1.setName(tel);
                                        }
                                    }
                                    basePatientDO1.setVerifyCode(jsonObject.getString("TOKEN"));
                                    basePatientDO1.setUserId(userId);
                                    basePatientDao.save(basePatientDO1);
                                }
                                basePatientDO1.setVerifyCode(jsonObject.getString("TOKEN"));
                                basePatientDO1.setUserId(userId);
                                basePatientDao.save(basePatientDO1);
                                /*String familyList = ykyyService.getFamilyList(null,userId);
                                JSONObject familyJson = JSONObject.parseObject(familyList);
                                if (familyJson.getString("code").equalsIgnoreCase("200")){
@ -3430,12 +3440,12 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                                    }
                                }*/
                                }
                            }
                        }
                    }
                    parameters.remove("password");
                } else if (!StringUtils.isEmpty(loginType)&&"3".equalsIgnoreCase(loginType)){
                }
                parameters.remove("password");
            } else if (!StringUtils.isEmpty(loginType)&&"3".equalsIgnoreCase(loginType)){
                if (wlyyRedisVerifyCodeService.verification(client_id, username, captcha)) {
                    //验证码正确
                }
@ -3591,7 +3601,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
                    return ObjEnvelop.getError("验证码错误!");
                }
            }else if (wlyyRedisVerifyCodeService.verification(client_id, mobile, captcha)) {
                    //验证码正确
                //验证码正确
            } else {
                return ObjEnvelop.getError("验证码错误!");
            }

+ 1 - 0
server/svr-authentication/src/main/resources/application.yml

@ -97,6 +97,7 @@ spring:
  redis:
    host: 172.26.0.253 # Redis server host.
    port: 6379 # Redis server port.
    password: Kb6wKDQP1W4
  ##发现服务
## i健康用户信息接口,开放出来给互联网医院登录同步用户信息用