Commit 8eaeb3c360d50090fea26754f8742b38f5c6fbcf

Authored by fangcheng
1 parent adba8e2709
Exists in master

删除不必要的老文件

Showing 20 changed files with 201 additions and 1021 deletions

center.manager/src/main/java/com/lyms/cm/controller/LoginController.java View file @ 8eaeb3c
1   -package com.lyms.cm.controller;
2   -
3   -import java.util.List;
4   -
5   -import org.apache.shiro.SecurityUtils;
6   -import org.apache.shiro.authc.AccountException;
7   -import org.apache.shiro.authc.AuthenticationException;
8   -import org.apache.shiro.authc.AuthenticationToken;
9   -import org.apache.shiro.authc.LockedAccountException;
10   -import org.apache.shiro.authc.UnknownAccountException;
11   -import org.apache.shiro.authc.UsernamePasswordToken;
12   -import org.springframework.beans.factory.annotation.Autowired;
13   -import org.springframework.stereotype.Controller;
14   -import org.springframework.ui.Model;
15   -import org.springframework.web.bind.annotation.RequestMapping;
16   -import org.springframework.web.bind.annotation.RequestMethod;
17   -import org.springframework.web.bind.annotation.RequestParam;
18   -
19   -import com.lyms.cm.entity.sys.TreeNode;
20   -import com.lyms.cm.entity.sys.User;
21   -import com.lyms.cm.service.sys.ResourceService;
22   -import com.lyms.cm.service.sys.UserService;
23   -import com.lyms.constants.Constants;
24   -import com.lyms.constants.SysResourceType;
25   -import com.lyms.shiro.ShiroWebUtils;
26   -import com.lyms.util.StrUtils;
27   -import com.lyms.web.controller.BaseController;
28   -
29   -@Controller
30   -public class LoginController extends BaseController {
31   -
32   - private static final String VIEW_LOGIN = "/login/login";
33   -
34   -
35   -
36   - @Autowired
37   - private UserService userService;
38   -
39   - @Autowired
40   - private ResourceService resourceService;
41   -
42   - @RequestMapping("/")
43   - public String index(Model model) {
44   - if(!ShiroWebUtils.isLogin()){
45   - return redirectTo(VIEW_LOGIN);
46   - }
47   - String username = ShiroWebUtils.getCurrentUserName();
48   - User user = userService.getUserByUserName(username);
49   - List<TreeNode> menus = resourceService.getPermissionMenuTreeByPid(SysResourceType.MANAGER_ROOT_MENU_RESOURCE_ID,user);
50   - model.addAttribute("menus", menus);
51   - return "/index";
52   - }
53   -
54   - @RequestMapping("/home")
55   - public String home() {
56   - return "/home";
57   - }
58   - /**
59   - * <li>@Description:导航到登录(GET)
60   - * <li>@param model
61   - * <li>@return
62   - * <li>创建人:方承
63   - * <li>创建时间:2016年11月27日
64   - * <li>修改人:
65   - * <li>修改时间:
66   - */
67   - @RequestMapping(value = "/login", method = RequestMethod.GET)
68   - public String login(Model model){
69   - model.addAttribute(Constants.CAPTCHA_TOKEN, StrUtils.uuid());
70   - return VIEW_LOGIN;
71   - }
72   -
73   - /**
74   - * <li>@Description:登录验证方法,详细查看ShiroRealm.class
75   - * <li>@param req
76   - * <li>@param model
77   - * <li>@return
78   - * <li>创建人:方承
79   - * <li>创建时间:2016年11月25日
80   - * <li>修改人:
81   - * <li>修改时间:
82   - */
83   - @RequestMapping(value = "/login", method = RequestMethod.POST)
84   - public String login(String username, String password,@RequestParam(value = "rememberMe",defaultValue = "0") int rememberMe, Model model) {
85   - String view = VIEW_LOGIN;
86   - if(StrUtils.isEmpty(username) || StrUtils.isEmpty(password)){
87   - model.addAttribute(Constants.CAPTCHA_TOKEN, StrUtils.uuid());
88   - return view;
89   - }
90   - AuthenticationToken token = new UsernamePasswordToken(username, password);
91   - if (rememberMe == 1) {
92   - ((UsernamePasswordToken) token).setRememberMe(true);
93   - }
94   - try {
95   - //查看ShiroRealm.class
96   - SecurityUtils.getSubject().login(token);
97   - return redirectTo("/");
98   - } catch (AuthenticationException e) {
99   - if (e instanceof UnknownAccountException) {
100   - model.addAttribute("message", "用户不存在");
101   - } else if (e instanceof AccountException) {
102   - model.addAttribute("message", "用户名密码错误");
103   - } else if (e instanceof LockedAccountException) {
104   - model.addAttribute("message", "用户被禁用");
105   - } else {
106   - model.addAttribute("message", "用户认证失败");
107   - }
108   - }
109   - model.addAttribute(Constants.CAPTCHA_TOKEN, StrUtils.uuid());
110   - return view;
111   - }
112   -
113   -}
  1 +//package com.lyms.cm.controller;
  2 +//
  3 +//import java.util.List;
  4 +//
  5 +//import org.apache.shiro.SecurityUtils;
  6 +//import org.apache.shiro.authc.AccountException;
  7 +//import org.apache.shiro.authc.AuthenticationException;
  8 +//import org.apache.shiro.authc.AuthenticationToken;
  9 +//import org.apache.shiro.authc.LockedAccountException;
  10 +//import org.apache.shiro.authc.UnknownAccountException;
  11 +//import org.apache.shiro.authc.UsernamePasswordToken;
  12 +//import org.springframework.beans.factory.annotation.Autowired;
  13 +//import org.springframework.stereotype.Controller;
  14 +//import org.springframework.ui.Model;
  15 +//import org.springframework.web.bind.annotation.RequestMapping;
  16 +//import org.springframework.web.bind.annotation.RequestMethod;
  17 +//import org.springframework.web.bind.annotation.RequestParam;
  18 +//
  19 +//import com.lyms.cm.entity.sys.TreeNode;
  20 +//import com.lyms.cm.entity.sys.User;
  21 +//import com.lyms.cm.service.sys.ResourceService;
  22 +//import com.lyms.cm.service.sys.UserService;
  23 +//import com.lyms.constants.Constants;
  24 +//import com.lyms.constants.SysResourceType;
  25 +//import com.lyms.shiro.ShiroWebUtils;
  26 +//import com.lyms.util.StrUtils;
  27 +//import com.lyms.web.controller.BaseController;
  28 +//
  29 +//@Controller
  30 +//public class LoginController extends BaseController {
  31 +//
  32 +// private static final String VIEW_LOGIN = "/login/login";
  33 +//
  34 +//
  35 +//
  36 +// @Autowired
  37 +// private UserService userService;
  38 +//
  39 +// @Autowired
  40 +// private ResourceService resourceService;
  41 +//
  42 +// @RequestMapping("/")
  43 +// public String index(Model model) {
  44 +// if(!ShiroWebUtils.isLogin()){
  45 +// return redirectTo(VIEW_LOGIN);
  46 +// }
  47 +// String username = ShiroWebUtils.getCurrentUserName();
  48 +// User user = userService.getUserByUserName(username);
  49 +// List<TreeNode> menus = resourceService.getPermissionMenuTreeByPid(SysResourceType.MANAGER_ROOT_MENU_RESOURCE_ID,user);
  50 +// model.addAttribute("menus", menus);
  51 +// return "/index";
  52 +// }
  53 +//
  54 +// @RequestMapping("/home")
  55 +// public String home() {
  56 +// return "/home";
  57 +// }
  58 +// /**
  59 +// * <li>@Description:导航到登录(GET)
  60 +// * <li>@param model
  61 +// * <li>@return
  62 +// * <li>创建人:方承
  63 +// * <li>创建时间:2016年11月27日
  64 +// * <li>修改人:
  65 +// * <li>修改时间:
  66 +// */
  67 +// @RequestMapping(value = "/login", method = RequestMethod.GET)
  68 +// public String login(Model model){
  69 +// model.addAttribute(Constants.CAPTCHA_TOKEN, StrUtils.uuid());
  70 +// return VIEW_LOGIN;
  71 +// }
  72 +//
  73 +// /**
  74 +// * <li>@Description:登录验证方法,详细查看ShiroRealm.class
  75 +// * <li>@param req
  76 +// * <li>@param model
  77 +// * <li>@return
  78 +// * <li>创建人:方承
  79 +// * <li>创建时间:2016年11月25日
  80 +// * <li>修改人:
  81 +// * <li>修改时间:
  82 +// */
  83 +// @RequestMapping(value = "/login", method = RequestMethod.POST)
  84 +// public String login(String username, String password,@RequestParam(value = "rememberMe",defaultValue = "0") int rememberMe, Model model) {
  85 +// String view = VIEW_LOGIN;
  86 +// if(StrUtils.isEmpty(username) || StrUtils.isEmpty(password)){
  87 +// model.addAttribute(Constants.CAPTCHA_TOKEN, StrUtils.uuid());
  88 +// return view;
  89 +// }
  90 +// AuthenticationToken token = new UsernamePasswordToken(username, password);
  91 +// if (rememberMe == 1) {
  92 +// ((UsernamePasswordToken) token).setRememberMe(true);
  93 +// }
  94 +// try {
  95 +// //查看ShiroRealm.class
  96 +// SecurityUtils.getSubject().login(token);
  97 +// return redirectTo("/");
  98 +// } catch (AuthenticationException e) {
  99 +// if (e instanceof UnknownAccountException) {
  100 +// model.addAttribute("message", "用户不存在");
  101 +// } else if (e instanceof AccountException) {
  102 +// model.addAttribute("message", "用户名密码错误");
  103 +// } else if (e instanceof LockedAccountException) {
  104 +// model.addAttribute("message", "用户被禁用");
  105 +// } else {
  106 +// model.addAttribute("message", "用户认证失败");
  107 +// }
  108 +// }
  109 +// model.addAttribute(Constants.CAPTCHA_TOKEN, StrUtils.uuid());
  110 +// return view;
  111 +// }
  112 +//
  113 +//}
center.manager/src/main/java/com/lyms/cm/controller/sys/ResourceController.java View file @ 8eaeb3c
1   -package com.lyms.cm.controller.sys;
2   -
3   -import java.util.Map;
4   -
5   -import org.springframework.beans.factory.annotation.Autowired;
6   -import org.springframework.stereotype.Controller;
7   -import org.springframework.web.bind.annotation.RequestMapping;
8   -import org.springframework.web.bind.annotation.ResponseBody;
9   -
10   -import com.baomidou.mybatisplus.mapper.EntityWrapper;
11   -import com.baomidou.mybatisplus.plugins.Page;
12   -import com.lyms.cm.entity.sys.Resource;
13   -import com.lyms.cm.service.sys.ResourceService;
14   -import com.lyms.web.controller.BaseController;
15   -
16   -@Controller
17   -@RequestMapping("/resource")
18   -public class ResourceController extends BaseController {
19   -
20   - @Autowired
21   - private ResourceService resourceService;
22   -
23   - @RequestMapping("/list")
24   - public String list() {
25   - return "/resource/resource_list";
26   - }
27   -
28   - @RequestMapping("/getResourceList")
29   - @ResponseBody
30   - public Map<String, Object> getResourceList(){
31   - Page<Resource> page = getPage();
32   - return toGridData(resourceService.selectPage(page, new EntityWrapper<Resource>().orderBy("sorted")));
33   - }
34   -}
center.manager/src/main/java/com/lyms/cm/controller/sys/RoleController.java View file @ 8eaeb3c
1   -package com.lyms.cm.controller.sys;
2   -
3   -import java.util.Map;
4   -
5   -import org.springframework.beans.factory.annotation.Autowired;
6   -import org.springframework.stereotype.Controller;
7   -import org.springframework.web.bind.annotation.RequestMapping;
8   -import org.springframework.web.bind.annotation.ResponseBody;
9   -
10   -import com.baomidou.mybatisplus.plugins.Page;
11   -import com.lyms.cm.entity.sys.Role;
12   -import com.lyms.cm.service.sys.RoleService;
13   -import com.lyms.web.controller.BaseController;
14   -
15   -@Controller
16   -@RequestMapping("/role")
17   -public class RoleController extends BaseController {
18   -
19   - @Autowired
20   - private RoleService roleService;
21   -
22   -
23   - @RequestMapping("/list")
24   - public String list() {
25   - return "/role/role_list";
26   - }
27   -
28   - @RequestMapping("/getRoleList")
29   - @ResponseBody
30   - public Map<String, Object> getRoleList(){
31   - Page<Role> page = getPage();
32   - return toGridData(roleService.selectPage(page, null));
33   - }
34   -}
center.manager/src/main/java/com/lyms/cm/controller/sys/UserController.java View file @ 8eaeb3c
1   -package com.lyms.cm.controller.sys;
2   -
3   -import java.util.Map;
4   -
5   -import org.apache.shiro.authz.annotation.RequiresPermissions;
6   -import org.springframework.beans.factory.annotation.Autowired;
7   -import org.springframework.stereotype.Controller;
8   -import org.springframework.ui.Model;
9   -import org.springframework.util.StringUtils;
10   -import org.springframework.web.bind.annotation.PathVariable;
11   -import org.springframework.web.bind.annotation.RequestMapping;
12   -import org.springframework.web.bind.annotation.ResponseBody;
13   -
14   -import com.baomidou.mybatisplus.plugins.Page;
15   -import com.lyms.cm.entity.sys.User;
16   -import com.lyms.cm.service.sys.UserService;
17   -import com.lyms.constants.OperationName;
18   -import com.lyms.shiro.HashUtils;
19   -import com.lyms.util.StrUtils;
20   -import com.lyms.web.bean.AjaxResult;
21   -import com.lyms.web.controller.BaseController;
22   -
23   -@Controller
24   -@RequestMapping("/user")
25   -public class UserController extends BaseController{
26   - @Autowired
27   - private UserService userService;
28   -
29   - @RequiresPermissions("user:view")
30   - @RequestMapping("/list")
31   - public String list() {
32   - return "/user/user_list";
33   - }
34   -
35   - /**
36   - * 概要.
37   - * <br>
38   - * @param id
39   - * @param model
40   - * @return
41   - * @return String
42   - * @author 自己的中文名
43   - * @date 2016年7月7日 下午4:35:09
44   - */
45   - @RequestMapping(value = "/{id}/toEdit")
46   - public String toEdit(@PathVariable String id, Model model) {
47   - model.addAttribute("user", userService.selectById(id));
48   - return "/user/user_edit";
49   - }
50   -
51   - @RequestMapping(value = "/create")
52   - @ResponseBody
53   - public AjaxResult create(User user, AjaxResult ajaxResult) {
54   - user.setId(StrUtils.uuid());
55   - user.setPassword(HashUtils.md5(user.getPassword()));
56   - boolean rs = userService.insert(user);
57   - return handleAjaxResult(ajaxResult, rs, OperationName.CREATE);
58   - }
59   -
60   - @RequestMapping(value = "/update")
61   - @ResponseBody
62   - public AjaxResult update(User user, AjaxResult ajaxResult) {
63   - if (!StringUtils.isEmpty(user.getPassword())) {
64   - user.setPassword(HashUtils.md5(user.getPassword()));
65   - }
66   - boolean ret = userService.updateById(user);
67   - return handleAjaxResult(ajaxResult, ret, OperationName.UPDATE);
68   - }
69   -
70   - @RequestMapping(value = "/{id}/delete")
71   - @ResponseBody
72   - public AjaxResult delete(@PathVariable String id, AjaxResult ajaxResult) {
73   - if ("1".equals(id))
74   - return new AjaxResult(false, "不能删除超级管理员");
75   - boolean rs = userService.deleteById(id);
76   - return handleAjaxResult(ajaxResult, rs, OperationName.DELETE);
77   - }
78   -
79   - @RequestMapping("/getUserList")
80   - @ResponseBody
81   - public Map<String, Object> getUserList(){
82   - Page<User> page = getPage();
83   - return toGridData(userService.selectPage(page, null));
84   - }
85   -}
center.manager/src/main/java/com/lyms/cm/dao/sys/ResourceMapper.java View file @ 8eaeb3c
1   -package com.lyms.cm.dao.sys;
2   -
3   -import java.util.List;
4   -
5   -import org.springframework.stereotype.Repository;
6   -
7   -import com.baomidou.mybatisplus.mapper.BaseMapper;
8   -import com.lyms.cm.entity.sys.Resource;
9   -import com.lyms.cm.entity.sys.TreeNode;
10   -
11   -/**
12   - * <p>
13   - * Mapper接口
14   - * </p>
15   - *
16   - * @author 风车车
17   - * @since 2016-12-12
18   - */
19   -@Repository
20   -public interface ResourceMapper extends BaseMapper<Resource> {
21   -
22   - List<TreeNode> getMenuTreeByPid(String pid);
23   -
24   -}
center.manager/src/main/java/com/lyms/cm/dao/sys/ResourceMapper.xml View file @ 8eaeb3c
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3   -<mapper namespace="com.lyms.cm.dao.sys.ResourceMapper">
4   -
5   -
6   - <select id="getMenuTreeByPid" resultType="TreeNode">
7   - SELECT id, name as text, url, icon FROM resource where pid = #{pid} and type=0 ORDER BY sorted
8   - </select>
9   -
10   -</mapper>
center.manager/src/main/java/com/lyms/cm/dao/sys/RoleMapper.java View file @ 8eaeb3c
1   -package com.lyms.cm.dao.sys;
2   -
3   -
4   -import org.springframework.stereotype.Repository;
5   -
6   -import com.baomidou.mybatisplus.mapper.BaseMapper;
7   -import com.lyms.cm.entity.sys.Role;
8   -
9   -/**
10   - * <p>
11   - * Mapper接口
12   - * </p>
13   - *
14   - * @author 风车车
15   - * @since 2016-12-12
16   - */
17   -@Repository
18   -public interface RoleMapper extends BaseMapper<Role> {
19   -
20   -}
center.manager/src/main/java/com/lyms/cm/dao/sys/RoleMapper.xml View file @ 8eaeb3c
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3   -<mapper namespace="com.lyms.cm.dao.sys.RoleMapper">
4   -
5   -
6   -</mapper>
center.manager/src/main/java/com/lyms/cm/dao/sys/UserMapper.java View file @ 8eaeb3c
1   -package com.lyms.cm.dao.sys;
2   -
3   -import org.springframework.stereotype.Repository;
4   -import com.baomidou.mybatisplus.mapper.BaseMapper;
5   -import com.lyms.cm.entity.sys.User;
6   -
7   -/**
8   - * <p>
9   - * Mapper接口
10   - * </p>
11   - *
12   - * @author 风车车
13   - * @since 2017-12-12
14   - */
15   -@Repository
16   -public interface UserMapper extends BaseMapper<User> {
17   -
18   -}
center.manager/src/main/java/com/lyms/cm/dao/sys/UserMapper.xml View file @ 8eaeb3c
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3   -<mapper namespace="com.lyms.cm.dao.sys.UserMapper">
4   -
5   -
6   -</mapper>
center.manager/src/main/java/com/lyms/cm/entity/sys/Resource.java View file @ 8eaeb3c
1   -package com.lyms.cm.entity.sys;
2   -
3   -import java.io.Serializable;
4   -
5   -import com.baomidou.mybatisplus.activerecord.Model;
6   -
7   -/**
8   - * <p>
9   - *
10   - * </p>
11   - *
12   - * @author 风车车
13   - * @since 2016-12-12
14   - */
15   -public class Resource extends Model<Resource> {
16   -
17   - private static final long serialVersionUID = 1L;
18   -
19   - /**
20   - *
21   - */
22   - private String id;
23   - /**
24   - *
25   - */
26   - private String name;
27   - /**
28   - *
29   - */
30   - private String description;
31   - /**
32   - *
33   - */
34   - private Integer type;
35   - /**
36   - *
37   - */
38   - private String permissions;
39   - /**
40   - *
41   - */
42   - private String url;
43   - /**
44   - *
45   - */
46   - private String icon;
47   - /**
48   - *
49   - */
50   - private String pid;
51   - /**
52   - *
53   - */
54   - private String sorted;
55   -
56   -
57   - public String getId() {
58   - return id;
59   - }
60   -
61   - public void setId(String id) {
62   - this.id = id;
63   - }
64   -
65   - public String getName() {
66   - return name;
67   - }
68   -
69   - public void setName(String name) {
70   - this.name = name;
71   - }
72   -
73   - public String getDescription() {
74   - return description;
75   - }
76   -
77   - public void setDescription(String description) {
78   - this.description = description;
79   - }
80   -
81   - public Integer getType() {
82   - return type;
83   - }
84   -
85   - public void setType(Integer type) {
86   - this.type = type;
87   - }
88   -
89   - public String getPermissions() {
90   - return permissions;
91   - }
92   -
93   - public void setPermissions(String permissions) {
94   - this.permissions = permissions;
95   - }
96   -
97   - public String getUrl() {
98   - return url;
99   - }
100   -
101   - public void setUrl(String url) {
102   - this.url = url;
103   - }
104   -
105   - public String getIcon() {
106   - return icon;
107   - }
108   -
109   - public void setIcon(String icon) {
110   - this.icon = icon;
111   - }
112   -
113   - public String getPid() {
114   - return pid;
115   - }
116   -
117   - public void setPid(String pid) {
118   - this.pid = pid;
119   - }
120   -
121   - public String getSorted() {
122   - return sorted;
123   - }
124   -
125   - public void setSorted(String sorted) {
126   - this.sorted = sorted;
127   - }
128   -
129   - @Override
130   - protected Serializable pkVal() {
131   - return this.id;
132   - }
133   -
134   -}
center.manager/src/main/java/com/lyms/cm/entity/sys/Role.java View file @ 8eaeb3c
1   -package com.lyms.cm.entity.sys;
2   -
3   -import java.io.Serializable;
4   -
5   -import com.baomidou.mybatisplus.activerecord.Model;
6   -
7   -/**
8   - * <p>
9   - *
10   - * </p>
11   - *
12   - * @author 风车车
13   - * @since 2016-12-12
14   - */
15   -public class Role extends Model<Role> {
16   -
17   - private static final long serialVersionUID = 1L;
18   -
19   - /**
20   - *
21   - */
22   - private String id;
23   - /**
24   - *
25   - */
26   - private String name;
27   - /**
28   - *
29   - */
30   - private String description;
31   - /**
32   - *
33   - */
34   - private String resources;
35   -
36   -
37   - public String getId() {
38   - return id;
39   - }
40   -
41   - public void setId(String id) {
42   - this.id = id;
43   - }
44   -
45   - public String getName() {
46   - return name;
47   - }
48   -
49   - public void setName(String name) {
50   - this.name = name;
51   - }
52   -
53   - public String getDescription() {
54   - return description;
55   - }
56   -
57   - public void setDescription(String description) {
58   - this.description = description;
59   - }
60   -
61   - public String getResources() {
62   - return resources;
63   - }
64   -
65   - public void setResources(String resources) {
66   - this.resources = resources;
67   - }
68   -
69   - @Override
70   - protected Serializable pkVal() {
71   - return this.id;
72   - }
73   -
74   -}
center.manager/src/main/java/com/lyms/cm/entity/sys/User.java View file @ 8eaeb3c
1   -package com.lyms.cm.entity.sys;
2   -
3   -import java.io.Serializable;
4   -
5   -import com.baomidou.mybatisplus.activerecord.Model;
6   -
7   -/**
8   - * <p>
9   - *
10   - * </p>
11   - *
12   - * @author 风车车
13   - * @since 2016-12-12
14   - */
15   -public class User extends Model<User> {
16   -
17   - private static final long serialVersionUID = 1L;
18   -
19   - /**
20   - *
21   - */
22   - private String id;
23   - /**
24   - *
25   - */
26   - private String username;
27   - /**
28   - *
29   - */
30   - private String password;
31   - /**
32   - *
33   - */
34   - private String roles;
35   -
36   -
37   - public String getId() {
38   - return id;
39   - }
40   -
41   - public void setId(String id) {
42   - this.id = id;
43   - }
44   -
45   - public String getUsername() {
46   - return username;
47   - }
48   -
49   - public void setUsername(String username) {
50   - this.username = username;
51   - }
52   -
53   - public String getPassword() {
54   - return password;
55   - }
56   -
57   - public void setPassword(String password) {
58   - this.password = password;
59   - }
60   -
61   - public String getRoles() {
62   - return roles;
63   - }
64   -
65   - public void setRoles(String roles) {
66   - this.roles = roles;
67   - }
68   -
69   - @Override
70   - protected Serializable pkVal() {
71   - return this.id;
72   - }
73   -
74   -}
center.manager/src/main/java/com/lyms/cm/service/sys/ResourceService.java View file @ 8eaeb3c
1   -package com.lyms.cm.service.sys;
2   -
3   -import java.util.List;
4   -import java.util.Set;
5   -
6   -import com.lyms.cm.entity.sys.Resource;
7   -import com.lyms.cm.entity.sys.TreeNode;
8   -import com.lyms.cm.entity.sys.User;
9   -import com.lyms.web.service.BaseService;
10   -
11   -
12   -/**
13   - * <p>
14   - * 服务类
15   - * </p>
16   - *
17   - * @author 风车车
18   - * @since 2016-12-12
19   - */
20   -public interface ResourceService extends BaseService<Resource> {
21   -
22   - List<TreeNode> getMenuTreeByPid(String pid);
23   -
24   - /**
25   - * <li>@Description:TODO(方法描述)
26   - * <li>@param managerRootMenuResourceId
27   - * <li>@param user
28   - * <li>@return
29   - * <li>创建人:方承
30   - * <li>创建时间:2016年9月21日
31   - * <li>修改人:
32   - * <li>修改时间:
33   - */
34   - List<TreeNode> getPermissionMenuTreeByPid(String managerRootMenuResourceId, User user);
35   -
36   - Set<String> getResourcePermissionSet(Set<String> resourceIds);
37   -
38   -}
center.manager/src/main/java/com/lyms/cm/service/sys/RoleService.java View file @ 8eaeb3c
1   -package com.lyms.cm.service.sys;
2   -
3   -import com.lyms.cm.entity.sys.Role;
4   -import com.lyms.web.service.BaseService;
5   -
6   -/**
7   - * <p>
8   - * 服务类
9   - * </p>
10   - *
11   - * @author 风车车
12   - * @since 2016-12-12
13   - */
14   -public interface RoleService extends BaseService<Role> {
15   -
16   -}
center.manager/src/main/java/com/lyms/cm/service/sys/UserService.java View file @ 8eaeb3c
1   -package com.lyms.cm.service.sys;
2   -
3   -import java.util.Map;
4   -import java.util.Set;
5   -
6   -import com.lyms.cm.entity.sys.User;
7   -import com.lyms.web.service.BaseService;
8   -
9   -
10   -/**
11   - * <p>
12   - * 服务类
13   - * </p>
14   - *
15   - * @author 风车车
16   - * @since 2016-12-12
17   - */
18   -public interface UserService extends BaseService<User> {
19   -
20   - public User getUserByUserName(String username);
21   -
22   - public Map<String, String> getUserResourceIdMap(User user);
23   -
24   - public Set<String> getUserResourceIdSet(User user);
25   -
26   -}
center.manager/src/main/java/com/lyms/cm/service/sys/impl/ResourceServiceImpl.java View file @ 8eaeb3c
1   -package com.lyms.cm.service.sys.impl;
2   -
3   -import java.util.List;
4   -import java.util.Map;
5   -import java.util.Set;
6   -
7   -import org.springframework.beans.factory.annotation.Autowired;
8   -import org.springframework.stereotype.Service;
9   -import org.springframework.util.StringUtils;
10   -
11   -import com.baomidou.mybatisplus.mapper.EntityWrapper;
12   -import com.baomidou.mybatisplus.service.impl.ServiceImpl;
13   -import com.lyms.cm.dao.sys.ResourceMapper;
14   -import com.lyms.cm.entity.sys.Resource;
15   -import com.lyms.cm.entity.sys.TreeNode;
16   -import com.lyms.cm.entity.sys.User;
17   -import com.lyms.cm.service.sys.ResourceService;
18   -import com.lyms.cm.service.sys.UserService;
19   -import com.lyms.util.InstanceUtils;
20   -import com.lyms.util.SqlUtils;
21   -
22   -/**
23   - * <p>
24   - * 服务实现类
25   - * </p>
26   - *
27   - * @author 风车车
28   - * @since 2016-12-12
29   - */
30   -@Service
31   -public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {
32   -
33   - @Autowired
34   - private UserService userService;
35   -
36   - @Autowired
37   - private ResourceMapper resourceMapper;
38   -
39   -
40   - @Override
41   - public List<TreeNode> getMenuTreeByPid(String pid) {
42   - List<TreeNode> allMenu = resourceMapper.getMenuTreeByPid(pid);
43   - //迭代获取子节点
44   - for (TreeNode menuNode : allMenu) {
45   - List<TreeNode> subMenu = resourceMapper.getMenuTreeByPid(menuNode.getId()+"");
46   - if(subMenu != null && subMenu.size() > 0){
47   - menuNode.setChildren(subMenu);
48   - getSubMenuTreeByNodeList(subMenu);
49   - }
50   - }
51   - return allMenu;
52   - }
53   -
54   - /**
55   - * @param treeNodeList 迭代处理子节点
56   - */
57   - private void getSubMenuTreeByNodeList(List<TreeNode> treeNodeList) {
58   - if(treeNodeList != null && treeNodeList.size() > 0){
59   - //迭代获取子节点
60   - for (TreeNode menuNode : treeNodeList) {
61   - List<TreeNode> subMenu = resourceMapper.getMenuTreeByPid(menuNode.getId()+"");
62   - if(subMenu != null && subMenu.size() > 0){
63   - menuNode.setChildren(subMenu);
64   - getSubMenuTreeByNodeList(subMenu);
65   - }
66   - }
67   - }
68   - }
69   -
70   - //权限菜单
71   - @Override
72   - public List<TreeNode> getPermissionMenuTreeByPid(String pid, User user) {
73   - //用户权限列表
74   - Map<String,String> permissionsMap = userService.getUserResourceIdMap(user);
75   - //所有菜单
76   - List<TreeNode> allMenu = resourceMapper.getMenuTreeByPid(pid);
77   - //初始化要返回的有权限的菜单
78   - List<TreeNode> allPermissionMenu = InstanceUtils.newArrayList();
79   - //迭代获取子节点
80   - for (TreeNode menuNode : allMenu) {
81   - if(permissionsMap.get(menuNode.getId()) != null){
82   - allPermissionMenu.add(menuNode);
83   - List<TreeNode> subMenus = resourceMapper.getMenuTreeByPid(menuNode.getId()+"");
84   - if(subMenus != null && subMenus.size() > 0){
85   - List<TreeNode> permissionSubMenu = InstanceUtils.newArrayList();
86   - for(TreeNode submenu : subMenus){
87   - if(permissionsMap.get(submenu.getId()) != null){
88   - permissionSubMenu.add(submenu);
89   - }
90   - }
91   - menuNode.setChildren(permissionSubMenu);
92   - getPermissionSubMenuTreeByNodeList(permissionSubMenu,permissionsMap);
93   - }
94   - }
95   - }
96   - return allPermissionMenu;
97   -
98   - }
99   -
100   - /**
101   - * @param treeNodeList 迭代处理获取有权限的子节点
102   - */
103   - private void getPermissionSubMenuTreeByNodeList(List<TreeNode> treeNodeList,Map<String,String> permissionMap) {
104   - if(treeNodeList != null && treeNodeList.size() > 0){
105   - //迭代获取子节点
106   - for (TreeNode menuNode : treeNodeList) {
107   - List<TreeNode> subMenus = resourceMapper.getMenuTreeByPid(menuNode.getId()+"");
108   - if(subMenus != null && subMenus.size() > 0){
109   - List<TreeNode> permissionSubMenu = InstanceUtils.newArrayList();
110   - for(TreeNode subMenu : subMenus){
111   - if(permissionMap.get(subMenu.getId()) != null){
112   - permissionSubMenu.add(subMenu);
113   - }
114   - }
115   - menuNode.setChildren(permissionSubMenu);
116   - getPermissionSubMenuTreeByNodeList(permissionSubMenu,permissionMap);
117   - }
118   - }
119   - }
120   - }
121   - @Override
122   - public Set<String> getResourcePermissionSet(Set<String> resourceIds) {
123   - EntityWrapper<Resource> ew = new EntityWrapper<Resource>();
124   - ew.where("id in (" + SqlUtils.handleIdsInsql(resourceIds,"'") + ")");
125   - List<Resource> resources = resourceMapper.selectList(ew);
126   - Set<String> permissionSet = InstanceUtils.newHashSet();
127   - for(Resource resource: resources){
128   - if(!StringUtils.isEmpty(resource.getPermissions()))
129   - permissionSet.add(resource.getPermissions());
130   - }
131   -
132   - return permissionSet;
133   - }
134   -}
center.manager/src/main/java/com/lyms/cm/service/sys/impl/RoleServiceImpl.java View file @ 8eaeb3c
1   -package com.lyms.cm.service.sys.impl;
2   -
3   -import org.springframework.stereotype.Service;
4   -
5   -import com.baomidou.mybatisplus.service.impl.ServiceImpl;
6   -import com.lyms.cm.dao.sys.RoleMapper;
7   -import com.lyms.cm.entity.sys.Role;
8   -import com.lyms.cm.service.sys.RoleService;
9   -
10   -/**
11   - * <p>
12   - * 服务实现类
13   - * </p>
14   - *
15   - * @author 风车车
16   - * @since 2016-12-12
17   - */
18   -@Service
19   -public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
20   -
21   -}
center.manager/src/main/java/com/lyms/cm/service/sys/impl/UserServiceImpl.java View file @ 8eaeb3c
1   -package com.lyms.cm.service.sys.impl;
2   -
3   -import java.util.Arrays;
4   -import java.util.HashSet;
5   -import java.util.List;
6   -import java.util.Map;
7   -import java.util.Set;
8   -
9   -import org.springframework.beans.factory.annotation.Autowired;
10   -import org.springframework.stereotype.Service;
11   -
12   -import com.baomidou.mybatisplus.mapper.EntityWrapper;
13   -import com.baomidou.mybatisplus.service.impl.ServiceImpl;
14   -import com.lyms.cm.dao.sys.RoleMapper;
15   -import com.lyms.cm.dao.sys.UserMapper;
16   -import com.lyms.cm.entity.sys.Role;
17   -import com.lyms.cm.entity.sys.User;
18   -import com.lyms.cm.service.sys.UserService;
19   -import com.lyms.util.InstanceUtils;
20   -import com.lyms.util.SqlUtils;
21   -
22   -/**
23   - * <p>
24   - * 服务实现类
25   - * </p>
26   - *
27   - * @author 风车车
28   - * @since 2016-12-12
29   - */
30   -@Service
31   -public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
32   -
33   - @Autowired
34   - private RoleMapper roleMapper;
35   -
36   - @Override
37   - public User getUserByUserName(String username) {
38   - return selectOne(new EntityWrapper<User>().where("username={0}", username));
39   - }
40   -
41   - @SuppressWarnings({ "rawtypes", "unchecked" })
42   - @Override
43   - public Set<String> getUserResourceIdSet(User user) {
44   - EntityWrapper<Role> ew = new EntityWrapper<Role>();
45   - ew.where("id in ({0})", SqlUtils.handleIdsInsql(user.getRoles(),"'"));
46   - List<Role> roles = roleMapper.selectList(ew);
47   - List<String> allResourceList = InstanceUtils.newArrayList();
48   - for(Role role : roles){
49   - String[] resources = role.getResources().split(",");
50   - List<String> rlist = Arrays.asList(resources);
51   - allResourceList.addAll(rlist);
52   - }
53   - return new HashSet(allResourceList);
54   - }
55   -
56   -
57   - @Override
58   - public Map<String,String> getUserResourceIdMap(User user){
59   - Set<String> resourceId = getUserResourceIdSet(user);
60   - Map<String,String> resourceMap = InstanceUtils.newHashMap();
61   - for(String p : resourceId){
62   - resourceMap.put(p, "");
63   - }
64   - return resourceMap;
65   - }
66   -}
center.manager/src/main/java/com/lyms/cm/shiro/ShiroRealm.java View file @ 8eaeb3c
1   -package com.lyms.cm.shiro;
2   -
3   -import java.util.Arrays;
4   -import java.util.HashSet;
5   -
6   -import org.apache.shiro.authc.AccountException;
7   -import org.apache.shiro.authc.AuthenticationException;
8   -import org.apache.shiro.authc.AuthenticationInfo;
9   -import org.apache.shiro.authc.AuthenticationToken;
10   -import org.apache.shiro.authc.SimpleAuthenticationInfo;
11   -import org.apache.shiro.authc.UnknownAccountException;
12   -import org.apache.shiro.authc.UsernamePasswordToken;
13   -import org.apache.shiro.authc.credential.AllowAllCredentialsMatcher;
14   -import org.apache.shiro.authz.AuthorizationInfo;
15   -import org.apache.shiro.authz.SimpleAuthorizationInfo;
16   -import org.apache.shiro.realm.AuthorizingRealm;
17   -import org.apache.shiro.subject.PrincipalCollection;
18   -import org.slf4j.Logger;
19   -import org.slf4j.LoggerFactory;
20   -import org.springframework.beans.factory.annotation.Autowired;
21   -
22   -import com.lyms.cm.entity.sys.User;
23   -import com.lyms.cm.service.sys.ResourceService;
24   -import com.lyms.cm.service.sys.UserService;
25   -import com.lyms.shiro.HashUtils;
26   -import com.lyms.shiro.ShiroWebUtils;
27   -import com.lyms.util.StrUtils;
28   -
29   -/**
30   - * <li>@ClassName: ShiroRealm
31   - * <li>@Description: 自定义Realm授权与验证实现
32   - * <li>@author 方承
33   - * <li>@date 2015年12月29日
34   - * <li>
35   - */
36   -public class ShiroRealm extends AuthorizingRealm {
37   -
38   - @SuppressWarnings("unused")
39   - private static Logger logger = LoggerFactory.getLogger(ShiroRealm.class);
40   -
41   -
42   - public ShiroRealm() {
43   - super(new AllowAllCredentialsMatcher());
44   - setAuthenticationTokenClass(UsernamePasswordToken.class);
45   - //FIXME: 暂时禁用Cache
46   - setCachingEnabled(false);
47   - }
48   -
49   - @Autowired
50   - private UserService userService;
51   -
52   - @Autowired
53   - private ResourceService resourceService;
54   -
55   - @Override
56   - protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
57   - String username = (String) principals.getPrimaryPrincipal();
58   - User user = userService.getUserByUserName(username);
59   - // 授权
60   - SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
61   - if(StrUtils.isNotEmpty(user.getRoles())){
62   - authorizationInfo.setRoles(new HashSet<String>(Arrays.asList(user.getRoles().split(","))));
63   - }
64   - authorizationInfo.setStringPermissions(resourceService.getResourcePermissionSet(userService.getUserResourceIdSet(user)));
65   - return authorizationInfo;
66   - }
67   -
68   - @Override
69   - protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
70   - UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
71   - String username = token.getUsername();
72   - User user = userService.getUserByUserName(username);
73   - if (user == null) {
74   - throw new UnknownAccountException("未知用户");
75   - }
76   - StringBuilder pwd = new StringBuilder(100);
77   - for (int i = 0; i < token.getPassword().length; i++) {
78   - pwd.append(token.getPassword()[i]);
79   - }
80   - if (!StrUtils.equals(user.getPassword(), HashUtils.md5(pwd.toString()))) {
81   - throw new AccountException("用户名密码不一致");
82   - }
83   - ShiroWebUtils.saveCurrentUser(user);
84   - AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
85   - return authcInfo;
86   - }
87   -
88   -}
  1 +//package com.lyms.cm.shiro;
  2 +//
  3 +//import java.util.Arrays;
  4 +//import java.util.HashSet;
  5 +//
  6 +//import org.apache.shiro.authc.AccountException;
  7 +//import org.apache.shiro.authc.AuthenticationException;
  8 +//import org.apache.shiro.authc.AuthenticationInfo;
  9 +//import org.apache.shiro.authc.AuthenticationToken;
  10 +//import org.apache.shiro.authc.SimpleAuthenticationInfo;
  11 +//import org.apache.shiro.authc.UnknownAccountException;
  12 +//import org.apache.shiro.authc.UsernamePasswordToken;
  13 +//import org.apache.shiro.authc.credential.AllowAllCredentialsMatcher;
  14 +//import org.apache.shiro.authz.AuthorizationInfo;
  15 +//import org.apache.shiro.authz.SimpleAuthorizationInfo;
  16 +//import org.apache.shiro.realm.AuthorizingRealm;
  17 +//import org.apache.shiro.subject.PrincipalCollection;
  18 +//import org.slf4j.Logger;
  19 +//import org.slf4j.LoggerFactory;
  20 +//import org.springframework.beans.factory.annotation.Autowired;
  21 +//
  22 +//import com.lyms.cm.entity.sys.User;
  23 +//import com.lyms.cm.service.sys.ResourceService;
  24 +//import com.lyms.cm.service.sys.UserService;
  25 +//import com.lyms.shiro.HashUtils;
  26 +//import com.lyms.shiro.ShiroWebUtils;
  27 +//import com.lyms.util.StrUtils;
  28 +//
  29 +///**
  30 +// * <li>@ClassName: ShiroRealm
  31 +// * <li>@Description: 自定义Realm授权与验证实现
  32 +// * <li>@author 方承
  33 +// * <li>@date 2015年12月29日
  34 +// * <li>
  35 +// */
  36 +//public class ShiroRealm extends AuthorizingRealm {
  37 +//
  38 +// @SuppressWarnings("unused")
  39 +// private static Logger logger = LoggerFactory.getLogger(ShiroRealm.class);
  40 +//
  41 +//
  42 +// public ShiroRealm() {
  43 +// super(new AllowAllCredentialsMatcher());
  44 +// setAuthenticationTokenClass(UsernamePasswordToken.class);
  45 +// //FIXME: 暂时禁用Cache
  46 +// setCachingEnabled(false);
  47 +// }
  48 +//
  49 +// @Autowired
  50 +// private UserService userService;
  51 +//
  52 +// @Autowired
  53 +// private ResourceService resourceService;
  54 +//
  55 +// @Override
  56 +// protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  57 +// String username = (String) principals.getPrimaryPrincipal();
  58 +// User user = userService.getUserByUserName(username);
  59 +// // 授权
  60 +// SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
  61 +// if(StrUtils.isNotEmpty(user.getRoles())){
  62 +// authorizationInfo.setRoles(new HashSet<String>(Arrays.asList(user.getRoles().split(","))));
  63 +// }
  64 +// authorizationInfo.setStringPermissions(resourceService.getResourcePermissionSet(userService.getUserResourceIdSet(user)));
  65 +// return authorizationInfo;
  66 +// }
  67 +//
  68 +// @Override
  69 +// protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
  70 +// UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
  71 +// String username = token.getUsername();
  72 +// User user = userService.getUserByUserName(username);
  73 +// if (user == null) {
  74 +// throw new UnknownAccountException("未知用户");
  75 +// }
  76 +// StringBuilder pwd = new StringBuilder(100);
  77 +// for (int i = 0; i < token.getPassword().length; i++) {
  78 +// pwd.append(token.getPassword()[i]);
  79 +// }
  80 +// if (!StrUtils.equals(user.getPassword(), HashUtils.md5(pwd.toString()))) {
  81 +// throw new AccountException("用户名密码不一致");
  82 +// }
  83 +// ShiroWebUtils.saveCurrentUser(user);
  84 +// AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
  85 +// return authcInfo;
  86 +// }
  87 +//
  88 +//}