springsecurity 企业微信登入的实现示例-亚博电竞手机版

背景

后台系统需要接入 企业微信登入,满足企业员工快速登入系统

流程图

简单代码说明

自定义一套 springsecurity 认证逻辑

主要就是 根据code 获取绑定用户信息 然后返回登入 token ,和qq ,微信 等第 3方登入 一个套路

// 自定义 wechatauthenticationprovider public class wechatauthenticationprovider implements authenticationprovider { private userdetailsservice userdetailsservice; public wechatauthenticationprovider(userdetailsservice userdetailsservice){ this.userdetailsservice = userdetailsservice; } @override public authentication authenticate(authentication authentication) throws authenticationexception { wechatauthenticationtoken authenticationtoken = (wechatauthenthttp://www.cppcns.comicationtoken) authentication; string userid = (string) authenticationtoken.getprincipal(); userdetails userdetails = userdetailsservice.loaduserbyusername(userid); // 此时鉴权成功后,应当重新 new 一个拥有鉴权的 authenticationresult 返回 browserauthenticationtoken authenticationresult = new browserauthenticationtoken(userdetails, userdetails.getauthorities()); authenticationresult.setdetails(authenticationtoken.getdetails()); return authenticationresult; } @override public boolean supports(class authentication) { // 判断 authentication 是不是 smscodeauthenticationtoken 的子类或子接口 return wechatauthenticationtoken.class.isassignablefrom(authentication); } public userdetailsservice getuserdetailsservice() { return userdetailsservice; } public void setuserdetailsservice(userdetailsservice userdetailsservice) { this.userdetailsservice = userdetailsservice; } } // 重写 userdetailsservice @override public userdetails loaduserbyusername(string code) throws usernamenotfoundexception { string wechatuserid = wechatservice.getwechatuserid(code); lambdaquerywrapper lambda = new querywrapper().lambda(); lambda.eq(sysuserwechat::getdeleted, datastatusenum.normal.getcode()); lambda.eq(sysuserwechat::getwechatid,wechatuserid); list sysuserwechats = sysuserwechatservice.list(lambda); if(collectionutils.isempty(sysuserwechats)){ throw new serviceexception(google_authenticator_601001.getmsg(),google_authenticator_601001.getcode()); } sysuserwechat sysuserwechat = sysuserwechats.get(0); long sysuserid = sysuserwechat.getsysuserid(); sysuser sysuser = userservice.selectuserbyid(sysuserid); if (stringutils.isnull(sysuser)) { throw new serviceexception(google_authenticator_601001.getmsg(),google_authenticator_501001.getcode()); } if (userstatus.deleted.getcode().equals(sysuser.getdelflag())) { throw new serviceexception(google_authenticator_601001.getmsg(),google_authenticator_501001.getcodefgzmvv()); } if (userstatus.disable.getcode().equals(sysuser.getstatus())) { throw new serviceexception(google_authenticator_601001.getmsg(),google_authenticator_501001.getcode()); } return createloginuser(sysuser); }

到此这篇关于springsecurity 企业微信登入的实http://www.cppcns.com现示例的文章就介绍到这了,更多相关springsecurity 企业微信登入内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

展开全文
内容来源于互联网和用户投稿,文章中一旦含有亚博电竞手机版的联系方式务必识别真假,本站仅做信息展示不承担任何相关责任,如有侵权或涉及法律问题请联系亚博电竞手机版删除

最新文章

网站地图