文学起点网
当前位置: 首页 文学百科

怎么进行oauth授权(OA自动化办公管理系统)

时间:2023-07-02 作者: 小编 阅读量: 2 栏目名: 文学百科

怎么进行oauth授权?接下来我们就一起去研究一下吧!

怎么进行oauth授权?环境配置:Jdk1.8Tomcat8.5mysqlEclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持),今天小编就来聊一聊关于怎么进行oauth授权?接下来我们就一起去研究一下吧!

怎么进行oauth授权

一、项目运行

环境配置:

Jdk1.8Tomcat8.5mysqlEclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSPSpringSpringMVCMyBatishtmlcssJavaScriptJQueryAjaxlayuimaven等等

用户管理控制层:

/** * @author yy */ @Controller@RequestMapping("/user")public class UserController extends BaseController{private String prefix = "system/user/";@AutowiredIUserService iUserService;@AutowiredIRoleService iRoleService;@AutowiredIDeptService iDeptService;@AutowiredIPositionService iPositionService;@Autowiredprivate SysPasswordService passwordService;/**** @描述 跳转到用户页面** @date 2018/9/16 10:54*/@RequestMapping("/tolist")@RequiresPermissions("user:list")public String toUserList(){return prefix"user";}/*** @描述 用户数据* @date 2018/9/15 12:30*/@RequestMapping("/tableList")@ResponseBodypublic TableDataInfo list(User user){startPage();List<User> users = iUserService.selectByUser(user);return getDataTable(users);}/*** 编辑用户 system/user/edit/20180914-1*/@RequiresPermissions("user:update")@RequestMapping("/edit/{userId}")public String edit(@PathVariable("userId") String userId, Model model){// 个人信息User user = iUserService.selectByPrimaryKey(userId);Map<String, Object> role_post_dept = getRole_Post_Dept();model.addAttribute("depts", role_post_dept.get("dept"));model.addAttribute("roles", role_post_dept.get("role"));model.addAttribute("positions", role_post_dept.get("position"));model.addAttribute("user", user);return prefix"edit";}/**** @描述 保存用户** @date 2018/9/15 18:53*/@PostMapping("/editSave")@RequiresPermissions("user:update")@Operlog(modal = "用户管理", descr = "修改用户信息")@ResponseBodypublic AjaxResult save(User user){if (StringUtils.isNotNull(user.getUid()) && User.isBoss(user.getUid())){return error("不允许修改管理员用户");}if(user.getPwd()!=null){user.setSalt(ShiroUtils.randomSalt());SimpleHash md5 = new SimpleHash("MD5", user.getPwd(), user.getSalt(), 1024);user.setPwd(md5.toHex());}return result(iUserService.updateByPrimaryKeySelective(user));}/*** @描述 添加用户页面* @date 2018/9/15 18:46*/@RequestMapping("/toAdd")@RequiresPermissions("user:add")public String toaddUser(Model model){Map<String, Object> role_post_dept = getRole_Post_Dept();model.addAttribute("depts", role_post_dept.get("dept"));model.addAttribute("roles", role_post_dept.get("role"));model.addAttribute("positions", role_post_dept.get("position"));return prefix"add";}/**** @描述 添加用户** @date 2018/9/15 20:40*/@RequestMapping("/addSave")@RequiresPermissions("user:add")@Operlog(modal = "用户管理", descr = "添加用户")@ResponseBodypublic AjaxResult addUser(User user){user.setSalt(ShiroUtils.randomSalt());SimpleHash md5 = new SimpleHash("MD5", user.getPwd(), user.getSalt(), 1024);user.setPwd(md5.toHex());user.setAvatar(CsEnum.avatar.USER_AVATAR.getValue());user.setCreateTime(new Date());return result(iUserService.insertSelective(user));}/**** @描述 批量删除** @date 2018/9/16 9:31*/@RequestMapping("/del")@RequiresPermissions("user:del")@Operlog(modal = "用户模块", descr = "删除用户")@ResponseBodypublic AjaxResult delByUserIds(String[] ids){try{int i = iUserService.deleteByPrimaryKeys(ids);}catch (Exception e){return error(e.getMessage());}return success();}/**** @描述 编辑密码修改页面** @date 2018/9/16 10:25*/@RequestMapping("/resetPwd/{userId}")@RequiresPermissions("user:update")public String editPwd(@PathVariable("userId") String id, Model model){model.addAttribute("uid", id);return prefix"resetPwd";}/**** @描述 密码修改** @date 2018/9/16 10:42*/@RequestMapping("/resetPwd")@RequiresPermissions("user:update")@Operlog(modal = "用户模块", descr = "修改密码")@ResponseBodypublic AjaxResult resetPwd(User user){return result(iUserService.resrtPwd(user));}/*** 校验手机号码*/@PostMapping("/checkPhoneUnique")@ResponseBodypublic String checkPhoneUnique(User user){String uniqueFlag = "0";if (user != null){uniqueFlag = iUserService.checkPhoneUnique(user);}return uniqueFlag;}/*** 校验email邮箱*/@PostMapping("/checkEmailUnique")@ResponseBodypublic String checkEmailUnique(User user){String uniqueFlag = "0";if (user != null){uniqueFlag = iUserService.checkEmailUnique(user);}return uniqueFlag;}/**** @描述: 校验登录名唯一性** @params:* @return:* @date: 2018/10/2 17:06*/@PostMapping("/checkLoginNameUnique")@ResponseBodypublic String checkLoginNameUnique(User user){String uniqueFlag = "0";if (user != null){uniqueFlag = iUserService.checkLoginNameUnique(user);}return uniqueFlag;}public Map<String, Object> getRole_Post_Dept(){Map<String, Object> map = new HashMap<>();//角色List<Role> roles = iRoleService.selectRoleList(new Role());//部门信息List<Dept> depts = iDeptService.selectDeptList(new Dept());//岗位List<Position> positions = iPositionService.selectPositionList(new Position());map.put("role", roles);map.put("dept", depts);map.put("position", positions);return map;}/*** 用户个人信息查看页面*/@RequestMapping("/myMsg")public String ToMyMsg(Model model, httpervletRequest request){User user = iUserService.selectByPrimaryKey(getUserId());model.addAttribute("user", user);model.addAttribute("loginIp", HttpHeaderUtil.getIpAddr(request));return prefix"profile/msg";}/*** 密码修改页面*/@RequestMapping("/resetMyPwd")public String toResetPwd(Model model){User user = iUserService.selectByPrimaryKey(getUserId());model.addAttribute("user", user);return prefix"profile/resetPwd";}/*** 密码修改保存*/@RequestMapping("/updateMyPwdSave")@ResponseBody@RequiresPermissions("user:update")@Operlog(modal = "个人信息", descr = "修改密码")public AjaxResult updateMyPwdSave(String password){User user = new User();user.setSalt(ShiroUtils.randomSalt());SimpleHash md5 = new SimpleHash("MD5", password, user.getSalt(), 1024);user.setPwd(md5.toHex());user.setUid(getUserId());int i = iUserService.updateByPrimaryKeySelective(user);if (i > 0){//更新shiro中的信息ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));return success();}return error();}/*** 编辑用户头像修改*/@RequestMapping("/updateAvatar")public String toupdateAvatar(Model model){model.addAttribute("user", getUser());return prefix"profile/avatar";}/*** 修改保存用户头像*/@RequestMapping("/updateAvatarSave")@RequiresPermissions("user:update")@Operlog(modal = "个人信息", descr = "修改头像")@ResponseBodypublic AjaxResult toupdateAvatar(MultipartFile file){try{String imgPath = UploadFile.uploadUserImg(file);if (StringUtils.isEmpty(imgPath)){return error("图片上传失败,稍后再试!");}User user = new User();user.setUid(getUserId());user.setAvatar(imgPath);int i = iUserService.updateByPrimaryKeySelective(user);if (i > 0){ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));}return result(i);}catch (IOException e){return error();}catch (FileSizeException e){//文件过大return error(e.getMsg());}catch (FileNameLengthException e){//文件名字超长return error(e.getMsg());}}/*** 校验密码和原来密码是否相同*/@RequestMapping("/checkPassword")@ResponseBodypublic boolean checkPassword(String password){//加密后与数据库密码比较User user = getUser();SimpleHash md5 = new SimpleHash("MD5", password, user.getSalt(), 1024);String oldPassword = md5.toHex();String pwd = getPwd();if (pwd.equals(oldPassword)){return true;}return false;}}

部门管理控制层:

/** * @author yy */@Controller@RequestMapping("/dept")public class DeptController extends BaseController{private String prefix = "system/dept/";@AutowiredIDeptService iDeptService;@AutowiredIUserService iUserService;/**** @描述 页面跳转到部门** @date 2018/9/16 10:59*/@RequestMapping("/tolist")@RequiresPermissions("dept:list")public String tolist(){return prefix"dept";}/**** @描述 ajax请求的所有部门** @date 2018/9/16 10:48*/@RequestMapping("/ajaxlist")@ResponseBodypublic List<Dept> list(Dept dept){List<Dept> depts = iDeptService.selectDeptList(dept);return depts;}/**** @描述 部门列表页** @date 2018/9/16 10:52*/@RequestMapping("/tableList")@ResponseBodypublic TableDataInfo listPag(Dept dept){//开启分页startPage();List<Dept> depts = iDeptService.selectDeptList(dept);return getDataTable(depts);}/**** @描述 新增页面** @date 2018/9/16 11:37*/@RequiresPermissions("dept:add")@RequestMapping("/toAdd")public String toAdd(Model model){List<User> users = iUserService.selectByUser(new User());model.addAttribute("users", users);return prefix"add";}/**** @描述: 查询所有部门下的所有用户 用户归类 树状数据** @date: 2018/9/27 11:25*/@RequestMapping("/getDeptAndUserTreeData")@ResponseBodypublic List<Object> DeptAndUserTreeData(){List<Dept> depts = iDeptService.selectDeptAndUser();List<User> users=new ArrayList<>();LinkedList<Object> deptList = new LinkedList<>();for (Dept dept : depts){Map<String, Object> deptMap = new HashMap();deptMap.put("name", dept.getDeptName());deptMap.put("id", null);users = dept.getUsers();LinkedList<Object> userlist = new LinkedList<>();for (User user : users){Map<String, Object> userMap = new HashMap();userMap.put("name",user.getName());userMap.put("id",user.getUid());userMap.put("icon","/img/timg.jpg");userlist.add(userMap);}deptMap.put("children",userlist);deptList.add(deptMap);}return deptList;}/**** @描述 批量删除** @date 2018/9/16 11:53*/@RequestMapping("/del")@RequiresPermissions("dept:del")@ResponseBody@Operlog(modal = "部门管理",descr = "删除部门")public AjaxResult del(String[] ids){try{iDeptService.deleteByPrimaryKeys(ids);}catch (Exception e){return error(e.getMessage());}return success();}/**** @描述 执行保存操作** @date 2018/9/16 11:54*/@RequestMapping("/addSave")@Operlog(modal = "部门管理",descr = "添加部门")@RequiresPermissions("dept:add")@ResponseBodypublic AjaxResult addDept(Dept dept){dept.setCreateTime(new Date());returnresult(iDeptService.insertSelective(dept));}/**** @描述 编辑修改页面** @date 2018/9/16 14:06*/@RequestMapping("/edit/{id}")@RequiresPermissions("dept:update")public String edit(@PathVariable("id") String id, Model model){Dept dept = iDeptService.selectByPrimaryKey(id);List<User> users = iUserService.selectByUser(new User());model.addAttribute("users", users);model.addAttribute("Dept", dept);return prefix"edit";}/**** @描述 修改保存** @date 2018/9/16 16:12*/@RequestMapping("/editSave")@RequiresPermissions("dept:update")@Operlog(modal = "部门管理",descr = "修改信息")@ResponseBodypublic AjaxResult save(Dept dept){int i = 0;try{i = iDeptService.updateByPrimaryKeySelective(dept);}catch (Exception e){return error(e.getMessage());}return result(i);}/*** 校验部门名称*/@PostMapping("/checkDeptNameUnique")@ResponseBodypublic String checkDeptNameUnique(Dept dept){String uniqueFlag = "0";if (dept != null){uniqueFlag = iDeptService.checkDeptNameUnique(dept);}return uniqueFlag;}}

角色管理控制层:

/** * @author yy */@Controller@RequestMapping("/role")public class RoleController extends BaseController{private String prefix = "system/role/";@AutowiredIUserService iUserService;@AutowiredIRoleService iRoleService;@AutowiredIPermissionService iPermissionService;/**** @描述 页面跳转** @date 2018/9/16 10:59*/@RequestMapping("/tolist")@RequiresPermissions("role:list")public String tolist(){return prefix"role";}/**** @描述 ajax请求所有** @date 2018/9/16 10:48*/@RequestMapping("/ajaxlist")@ResponseBodypublic List<Role> list(Role role){List<Role> roles = iRoleService.selectRoleList(role);return roles;}/**** @描述 列表** @date 2018/9/16 10:52*/@RequestMapping("/tableList")@ResponseBodypublic TableDataInfo listPag(Role role){//开启分页startPage();List<Role> roles = iRoleService.selectRoleList(role);return getDataTable(roles);}/**** @描述 新增页面** @date 2018/9/16 11:37*/@RequestMapping("/toAdd")@RequiresPermissions("role:add")public String toAdd(Model model){return prefix"add";}/**** @描述 批量删除** @date 2018/9/16 11:53*/@RequestMapping("/del")@RequiresPermissions("role:del")@Operlog(modal = "角色管理",descr = "删除角色")@ResponseBodypublic AjaxResult del(Integer[] ids){try{iRoleService.deleteByPrimaryKeys(ids);}catch (Exception e){return error(e.getMessage());}return success();}/**** @描述 添加保存** @date 2018/9/16 11:54*/@RequestMapping("/addSave")@RequiresPermissions("role:update")@Operlog(modal = "角色管理",descr = "添加角色")@ResponseBodypublic AjaxResult addRole(Role role, Integer[] ids){role.setCreateTime(new Date());int insert = 0;try{if (StringUtils.isEmpty(ids)){ids = new Integer[0];}insert = iRoleService.insert(role, ids);}catch (Exception e){return error(e.getMessage());}//清空缓存ShiroUtils.clearCachedAuthorizationInfo();returnresult(insert);}/**** @描述: 根据ID 获取u他的所有权限 做回显** @params: roleId 角色Id* @return:* @date: 2018/9/27 14:04*/@RequestMapping("/selectById/{roleId}")@ResponseBodypublic Role selectById(@PathVariable("roleId") Integer roleId){Role role = iRoleService.selectByPrimaryKey(roleId);return role;}/**** @描述 编辑修改页面** @date 2018/9/16 14:06*/@RequestMapping("/edit/{id}")@RequiresPermissions("role:update")public String edit(@PathVariable("id") Integer id, Model model){Role role = iRoleService.selectByPrimaryKey(id);model.addAttribute("Role", role);return prefix"edit";}/**** @描述 编辑修改权限页面** @date 2018/9/16 14:06*/@RequestMapping("/editPower/{id}")@RequiresPermissions("role:update")public String editPower(@PathVariable("id") Integer id, Model model){Role role = iRoleService.selectByPrimaryKey(id);model.addAttribute("Role", role);return prefix"editPower";}/**** @描述 修改角色信息保存** @date 2018/9/16 16:12*/@RequestMapping("/editSave")@RequiresPermissions("role:update")@Operlog(modal = "角色管理",descr = "修改角色信息")@ResponseBodypublic AjaxResult save(Role role){int i = 0;try{i = iRoleService.updateByPrimaryKeySelective(role);}catch (Exception e){return error(e.getMessage());}return result(i);}/**** @描述 修改角色权限信息保存** @date 2018/9/16 16:12*/@RequestMapping("/editPowerSave")@RequiresPermissions("role:update")@Operlog(modal = "角色管理",descr = "修改角色权限")@ResponseBodypublic AjaxResult editPowerSave(Role role, Integer[] ids){int i = 0;try{if (StringUtils.isEmpty(ids)){ids = new Integer[0];}i = iRoleService.updateByPrimaryKeyPowerSelective(role, ids);}catch (Exception e){return error(e.getMessage());}//清空缓存ShiroUtils.clearCachedAuthorizationInfo();//如果用户正在修改的角色id 是当前用户的角色id 则刷新 subject的User信息if (role.getRoleId().equals(getRoleId())){ShiroUtils.reloadUser(iUserService.selectByPrimaryKey(getUserId()));}return result(i);}/*** 校验名称唯一*/@PostMapping("/checkRoleNameUnique")@ResponseBodypublic String checkDeptNameUnique(Role role){String uniqueFlag = "0";if (role != null){uniqueFlag = iRoleService.checkRoleNameUnique(role);}return uniqueFlag;}}

项目源码及开发文档

由于限制,这里不能直接放链接,需要项目源码与开发文档的同学转发本文 关注 私信【0221】即可获取

    推荐阅读
  • 苏州旅游攻略景点必去(苏州旅游必去景点有哪些)

    位于苏州市东北街一百七十八号,始建于明朝正德年间。虎丘是AAAAA级景区及全国文明单位,首批十佳文明风景旅游区示范点。中午,周庄最为欢闹,游人穿梭熙熙攘攘,船儿来回摇摇荡荡,各地的游客与热情的商铺融为一体,热闹非凡,安静的古镇着实多了些欢闹的气息。狮子林为苏州四大名园之一,位于苏州市市城东北园林路。

  • 买的玉米种子是瘪的(去年买的玉米种子剩了很多)

    去年买的陈玉米种子建议不要用针对去年的陈玉米种子,大多情况下不建议再次使用,会影响到玉米后期的生长和产量情况。陈年的因为保管的问题,可能会出现很多因素影响玉米的出苗率或者后期的生长。陈玉米种子隔了一年后再种植,种子自身水分含量降低,水分降低严重的情况下,影响播种的效率和玉米的后期生长,由于活性降低,即使能出芽,也不一定能出苗。

  • 173.2亿!国庆消费火爆 国庆消费市场

    今年国庆、重阳两节叠加,全省消费市场呈现平衡较快增长态势,服装、家电、汽车等商品消费亮点突出,大众餐饮、旅行休闲、文体娱乐等主要服务消费备受青睐。根据商务部业务统一平台生存必需品监测系统显示,国庆黄金周期间,全省生存必需品市场供应充沛,价格总体平衡。除了买买买,国庆还是婚庆、团圆、会友高峰,各地亲友聚餐、婚寿宴等大众化餐饮生意兴隆。

  • 吴承恩是怎么写出的西游记(吴承恩怎么写出的西游记)

    吴承恩怎么写出的西游记诸葛长青:吴承恩写西游记诸葛长青:吴承恩怎么写出的《西游记》西游记,广泛流传西游记,作者吴承恩西游记,包含了儒释道大智慧那么,吴承恩是怎么写出的《西游记》呢?诸葛长青把自己对吴承恩写《西游记》,研究成。

  • 李逵扮演者(大家一起来看看吧)

    我们一起去了解并探讨一下这个问题吧!李逵扮演者赵小锐的李逵应该算是很多人印象当中的经典所在了,他的李逵也是很粗犷,但是这种粗犷当中却带着细腻,也是因为这个角色,他开始受到了不少的观众的关注和喜爱。其实之前的他也有出演过一些电视剧的,但是可惜的是一直都没能够真正的红起来,是李逵这个角色,让他一夜成名爆火了。

  • 汽车空间大小怎么看轴距(什么因素会影响车内空间)

    大众速腾,长度4655mm,轴距2651mm。看外观就明白了,因为宝马320i是后驱车,发动机采用纵置布局;而大众速腾是前驱车,发动机采用横置布局。而且由于发动机纵置,后驱设计,对于车内空间侵占较为严重,所以宝马320的长轴距实际上对于空间的帮助是“虚高”的。前面我们就提到了,宝马3系采用了后驱,大众速腾采用了前驱。回到我们的主题,通常来说,麦弗逊与扭力梁对于车辆空间的侵占是最小的,而多连杆和双叉臂对于车辆空间侵占是要更大的。

  • 湖南省医保局2015年工作思路与安排 湖南省医疗保障局领导班子组成人员

    督促指导各统筹地区核实提高缴费基数,强化保险费足额征收。继续加强工伤认定参与,把好工伤入口关。认真核实、积极处理群众举报问题,始终保持高压态势。加强生育医疗服务管理,规范生育津贴发放。二是启动实施工伤保险信息系统改造升级,改进工伤职工异地就医联网结算,方便工伤职工救治。三是加强财务、业务数据清理,提高数据质量;通报全省“三险”基金运行分析,指导市州加强基金运行风险管控。

  • 民国最渣四大渣男(民国著名4大渣男)

    当时很多文人在接受自由恋爱的思想时,家中已经有了父母为之安排的妻子。郁达夫一生有过三位妻子,一位同居情人。郁达夫后来还是和王映霞离婚,1940年在新加坡认识了比他小20岁的播音员李莜英,两人很快就同居了。第二任妻子佐藤富子,是个日本女人,为了和郭沫若在一起,不仅改名为“郭安娜”,还和父母断绝了关系。1937年,郭沫若抛弃妻子回国,和女明星于立群同居,两人于2年后再重庆结婚。

  • 电脑怎么连打印机教程(教会你快速学会电脑如何连接打印机的安装使用方法)

    最近很多网友都在私信给小编,小编也无法一一回复,有些问题也无法简约介绍,所以只能在头条文章内与大家共享。

  • 爱吃鸡蛋的注意了这3种鸡蛋不能买(这些鸡蛋没你想的那么好)

    营养均衡的孩子没必要补这种元素;真正缺乏硒,靠富硒蛋补,根本起不了多大作用。这类蛋再好,也别给孩子吃那就是全生或半熟的蛋,比如溏心蛋。一般溏心蛋的加热时间短,不能完全杀死细菌,生蛋液根本没有处理细菌,对于抵抗力低、易感染的宝宝来说,非常容易被细菌感染。