Commit 99b1500e0d9011c938436b22953ffe4415c1d307

Authored by fangcheng
1 parent f0d827da10
Exists in master

登录模块功能提交

Showing 20 changed files with 390 additions and 393 deletions

parent/base.common/src/main/java/com/lyms/base/common/service/role/PermissionsService.java View file @ 99b1500
... ... @@ -48,6 +48,17 @@
48 48 * <li>修改时间:
49 49 */
50 50 public Set<String> getUserPermissionSet(String uid);
  51 +
  52 + /**
  53 + * <li>@Description:权限列表Set,方便Shiro使用
  54 + * <li>@param uid
  55 + * <li>@return
  56 + * <li>创建人:方承
  57 + * <li>创建时间:2017年3月9日
  58 + * <li>修改人:
  59 + * <li>修改时间:
  60 + */
  61 + public List<Permissions> getUserPermission(String uid);
51 62  
52 63 }
parent/base.common/src/main/java/com/lyms/base/common/service/role/impl/PermissionsServiceImpl.java View file @ 99b1500
... ... @@ -142,6 +142,7 @@
142 142 * <li>修改人:
143 143 * <li>修改时间:
144 144 */
  145 + @Override
145 146 public List<Permissions> getUserPermission(String uid) {
146 147 return baseMapper.getUserPermission(uid);
147 148 }
parent/core.sdk/src/main/java/com/lyms/exception/handler/DefaultExceptionHandler.java View file @ 99b1500
... ... @@ -32,7 +32,7 @@
32 32 json.setSuccess(false);
33 33 json.setStatus("exception");
34 34 json.setMessage("没有权限 " + e.getMessage());
35   - json.setObj(e.getClass().getName());
  35 + json.setData(e.getClass().getName());
36 36 return json;
37 37 }
38 38  
... ... @@ -50,7 +50,7 @@
50 50 json.setSuccess(false);
51 51 json.setStatus("exception");
52 52 json.setMessage("操作不允许 " + e.getMessage());
53   - json.setObj(e.getClass().getName());
  53 + json.setData(e.getClass().getName());
54 54 return json;
55 55 }
56 56  
... ... @@ -68,7 +68,7 @@
68 68 json.setSuccess(false);
69 69 json.setStatus("exception");
70 70 json.setMessage("业务异常 " + e.getMessage());
71   - json.setObj(e.getClass().getName());
  71 + json.setData(e.getClass().getName());
72 72 return json;
73 73 }
74 74  
parent/core.sdk/src/main/java/com/lyms/web/bean/AjaxResult.java View file @ 99b1500
... ... @@ -8,7 +8,7 @@
8 8 private boolean success;
9 9 private String status;
10 10 private String message;
11   - private Object obj;
  11 + private Object data;
12 12  
13 13 public AjaxResult(){
14 14  
15 15  
16 16  
17 17  
18 18  
19 19  
20 20  
21 21  
... ... @@ -26,32 +26,36 @@
26 26 return success;
27 27 }
28 28  
29   - public void setSuccess(boolean success) {
  29 + public AjaxResult setSuccess(boolean success) {
30 30 this.success = success;
  31 + return this;
31 32 }
32 33  
33 34 public String getStatus() {
34 35 return status;
35 36 }
36 37  
37   - public void setStatus(String status) {
  38 + public AjaxResult setStatus(String status) {
38 39 this.status = status;
  40 + return this;
39 41 }
40 42  
41 43 public String getMessage() {
42 44 return message;
43 45 }
44 46  
45   - public void setMessage(String message) {
  47 + public AjaxResult setMessage(String message) {
46 48 this.message = message;
  49 + return this;
47 50 }
48 51  
49   - public Object getObj() {
50   - return obj;
  52 + public Object getData() {
  53 + return data;
51 54 }
52 55  
53   - public void setObj(Object obj) {
54   - this.obj = obj;
  56 + public AjaxResult setData(Object data) {
  57 + this.data = data;
  58 + return this;
55 59 }
56 60  
57 61 }
parent/core.sdk/src/main/java/com/lyms/web/controller/BaseController.java View file @ 99b1500
... ... @@ -28,6 +28,7 @@
28 28 import com.baomidou.mybatisplus.plugins.pagination.Pagination;
29 29 import com.lyms.common.StringEscapeEditor;
30 30 import com.lyms.exception.BusinessException;
  31 +import com.lyms.spring.SpringContextHolder;
31 32 import com.lyms.util.HttpUtils;
32 33 import com.lyms.util.StrUtils;
33 34 import com.lyms.web.bean.AjaxResult;
... ... @@ -367,6 +368,6 @@
367 368 }
368 369 return ip;
369 370 }
370   -
  371 +
371 372 }
parent/hospital.mac/src/main/java/com/lyms/hospital/service/token/TokenService.java View file @ 99b1500
1   -package com.lyms.hospital.service.token;
2   -
3   -/**
4   - * Created by riecard on 15/9/22.
5   - */
6   -public interface TokenService
7   -{
8   -
9   -
10   - String createToken(String userId);
11   -
12   - String createToken(String userId, Integer second);
13   -
14   - boolean resetToken(String token);
15   -
16   - boolean validToken(String token);
17   -
18   - boolean validToken(String token, Integer second);
19   -
20   - String getUserId(String token);
21   -
22   - void deleteAllToken(String userId);
23   -
24   - void deleteAllToken(String userId, String prefix);
25   -
26   - void deleteToken(String token);
27   -
28   -}
parent/hospital.mac/src/main/java/com/lyms/hospital/service/token/impl/TokenServiceImpl.java View file @ 99b1500
1   -package com.lyms.hospital.service.token.impl;
2   -
3   -import com.lyms.hospital.service.token.TokenService;
4   -import com.lyms.util.SerializeUtils;
5   -import com.lyms.util.TokenUtils;
6   -import org.springframework.beans.factory.annotation.Autowired;
7   -import org.springframework.beans.factory.annotation.Value;
8   -import org.springframework.data.redis.core.RedisTemplate;
9   -import org.springframework.stereotype.Service;
10   -
11   -import java.io.Serializable;
12   -import java.util.ArrayList;
13   -import java.util.List;
14   -import java.util.UUID;
15   -
16   -/**
17   - * Created by riecard on 15/9/22.
18   - */
19   -@Service
20   -public class TokenServiceImpl implements TokenService
21   -{
22   -
23   - static final Integer seconds = 7 * 24 * 60 * 60;
24   - static final Integer ams_seconds = 60 * 60;
25   - @Value("${token.prefix}")
26   - private String tokenPrefix;
27   -
28   - @Autowired
29   - private RedisTemplate<Serializable, Serializable> redisTemplate;
30   -
31   - private String prefix = null;
32   -
33   - private String getPrefix()
34   - {
35   - return tokenPrefix;
36   - }
37   -
38   - private Integer getSeconds()
39   - {
40   - if ("ams".equals(prefix))
41   - {
42   - return ams_seconds;
43   - } else
44   - {
45   - return seconds;
46   - }
47   - }
48   -
49   - @Override
50   - public String createToken(String userId, Integer second)
51   - {
52   - String token = getPrefix() + TokenUtils.getToken(UUID.randomUUID().toString());
53   -
54   - redisTemplate.opsForValue().set(token, userId, second);
55   -
56   - List<Serializable> list = new ArrayList<Serializable>();
57   - List<Serializable> delList = new ArrayList<Serializable>();
58   - String tempKey = getPrefix() + "_tokenlist_" + userId;
59   - Object obj = redisTemplate.opsForValue().get(tempKey);
60   - if (obj != null)
61   - {
62   - list = (List<Serializable>) obj;
63   - }
64   - for (Serializable key : list)
65   - {
66   - if (!redisTemplate.hasKey(key))
67   - {
68   - delList.add(key);
69   - }
70   - }
71   - list.removeAll(delList);
72   - list.add(token);
73   - redisTemplate.opsForValue().set(tempKey, SerializeUtils.serialize(list), second);
74   - return token;
75   - }
76   -
77   - @Override
78   - public String createToken(String userId)
79   - {
80   - return createToken(userId, seconds);
81   - }
82   -
83   - @Override
84   - public boolean resetToken(String token)
85   - {
86   - Object obj = redisTemplate.opsForValue().get(token);
87   - if (obj != null)
88   - {
89   - redisTemplate.opsForValue().set(token, SerializeUtils.serialize(obj), seconds);
90   - return true;
91   - }
92   - return false;
93   - }
94   -
95   - @Override
96   - public boolean validToken(String token)
97   - {
98   - return validToken(token, seconds);
99   - }
100   -
101   - @Override
102   - public boolean validToken(String token, Integer second)
103   - {
104   - Object obj = redisTemplate.opsForValue().get(token);
105   - if (obj != null)
106   - {
107   - redisTemplate.opsForValue().set(token, SerializeUtils.serialize(obj), second);
108   - return true;
109   - }
110   - return false;
111   - }
112   -
113   - @Override
114   - public String getUserId(String token)
115   - {
116   - Object obj = redisTemplate.opsForValue().get(token);
117   - if (obj != null)
118   - {
119   - redisTemplate.opsForValue().set(token, SerializeUtils.serialize(obj), getSeconds());
120   - return (String) obj;
121   - }
122   - return null;
123   - }
124   -
125   - @Override
126   - public void deleteToken(String token)
127   - {
128   - redisTemplate.delete(token);
129   - }
130   -
131   - @Override
132   - public void deleteAllToken(String userId)
133   - {
134   - String tempKey = getPrefix() + "_tokenlist_" + userId;
135   - Object obj = redisTemplate.opsForValue().get(tempKey);
136   - if (obj != null)
137   - {
138   - List<Serializable> list = (List<Serializable>) obj;
139   - redisTemplate.delete(list);
140   - redisTemplate.delete(tempKey);
141   - }
142   - }
143   -
144   - @Override
145   - public void deleteAllToken(String userId, String prefix)
146   - {
147   - String tempKey = prefix + "_tokenlist_" + userId;
148   - Object obj = redisTemplate.opsForValue().get(tempKey);
149   - if (obj != null)
150   - {
151   - List<Serializable> list = (List<Serializable>) obj;
152   - redisTemplate.delete(list);
153   - redisTemplate.delete(tempKey);
154   - }
155   - }
156   -}
parent/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java View file @ 99b1500
1 1 package com.lyms.hospital.controller;
2 2  
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import javax.servlet.http.HttpServletResponse;
  7 +
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.springframework.beans.factory.annotation.Autowired;
3 10 import org.springframework.web.bind.annotation.RequestBody;
4 11 import org.springframework.web.bind.annotation.RequestMapping;
5 12 import org.springframework.web.bind.annotation.RequestMethod;
  13 +import org.springframework.web.bind.annotation.RequestParam;
6 14 import org.springframework.web.bind.annotation.ResponseBody;
7 15 import org.springframework.web.bind.annotation.RestController;
8 16  
9 17 import com.alibaba.fastjson.JSON;
10   -import com.alibaba.fastjson.JSONObject;
  18 +import com.lyms.annotation.TokenRequired;
  19 +import com.lyms.base.common.entity.organ.Organizations;
  20 +import com.lyms.base.common.entity.role.Permissions;
  21 +import com.lyms.base.common.entity.role.Roles;
11 22 import com.lyms.base.common.entity.user.Users;
  23 +import com.lyms.base.common.service.organ.OrganizationsService;
  24 +import com.lyms.base.common.service.role.PermissionsService;
  25 +import com.lyms.base.common.service.role.RolesService;
  26 +import com.lyms.base.common.service.user.UsersService;
  27 +import com.lyms.hospital.service.token.TokenService;
  28 +import com.lyms.util.InstanceUtils;
  29 +import com.lyms.util.MD5Utils;
  30 +import com.lyms.web.bean.AjaxResult;
12 31 import com.lyms.web.controller.BaseController;
13 32  
14 33 import io.swagger.annotations.Api;
... ... @@ -20,6 +39,17 @@
20 39 @RequestMapping(value = "/login")
21 40 @Api(value = "/api", description = "登录的相关操作")
22 41 public class LoginController extends BaseController {
  42 +
  43 + @Autowired
  44 + private UsersService usersService;
  45 + @Autowired
  46 + private OrganizationsService organizationsService;
  47 + @Autowired
  48 + private RolesService rolesService;
  49 + @Autowired
  50 + private TokenService tokenService;
  51 + @Autowired
  52 + private PermissionsService permissionsService;
23 53  
24 54 @ApiOperation(value = "测试登录", notes = "测试登录说明")
25 55 @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
... ... @@ -61,6 +91,60 @@
61 91 private Users getRequestUsersEntity(String reqJson){
62 92 //users.setId(reqJson.getString("id"));
63 93 return JSON.parseObject(reqJson, Users.class);
  94 + }
  95 +
  96 +
  97 + @RequestMapping(value = "/tokens", method = RequestMethod.POST)
  98 + @ResponseBody
  99 + public AjaxResult usersLogin(@RequestParam(value = "account") String account,
  100 + @RequestParam(value = "vercode", required = false) String code,
  101 + @RequestParam(value = "password", required = false) String password,
  102 + AjaxResult ajaxResult,
  103 + HttpServletResponse response) {
  104 + ajaxResult.setSuccess(false);
  105 + if (StringUtils.isEmpty(account) && (StringUtils.isEmpty(code) || StringUtils.isEmpty(password))) {
  106 + ajaxResult.setMessage("登录账户或者验证码为空,请输入!");
  107 + return ajaxResult;
  108 + }
  109 + Users users = usersService.getUserByUsername(account);
  110 + if(users == null){
  111 + ajaxResult.setMessage("用户不存在!");
  112 + return ajaxResult;
  113 + }
  114 + if(!users.getPwd().equals(MD5Utils.md5(password))){
  115 + ajaxResult.setMessage("密码不正确!");
  116 + return ajaxResult;
  117 + }
  118 + if(users.getEnable() < 1){
  119 + ajaxResult.setMessage("用户被禁用!");
  120 + return ajaxResult;
  121 + }
  122 + //Organizations organizations = organizationsService.selectById( users.getOrgId());
  123 + Map<String, Object> result = InstanceUtils.newHashMap();
  124 + String token = tokenService.createToken(users.getId());
  125 + List<Roles> roles = rolesService.selectBatchIds(usersService.getRoleIdListByUserid(users.getId()));
  126 + List<Permissions> permissions = permissionsService.getUserPermission(users.getId());
  127 + Organizations org = organizationsService.selectById(users.getOrgId());
  128 + result.put("token", token);
  129 + result.put("user",users);
  130 + result.put("roles",roles);
  131 + result.put("organization",org);
  132 + result.put("organizations",org);
  133 + result.put("permissions", permissions);
  134 + result.put("watermark", "water");
  135 + ajaxResult.setData(result);
  136 + ajaxResult.setSuccess(true);
  137 + return ajaxResult;
  138 + }
  139 +
  140 +
  141 + @RequestMapping(value = "/tokensCheck", method = RequestMethod.POST)
  142 + @ResponseBody
  143 + @TokenRequired
  144 + public AjaxResult usersLogin(
  145 + HttpServletResponse response) {
  146 + System.out.println(1111111);
  147 + return null;
64 148 }
65 149 }
parent/hospital.web/src/main/java/com/lyms/hospital/dao/sys/UserMapper.java View file @ 99b1500
1   -package com.lyms.hospital.dao.sys;
2   -
3   -import org.springframework.stereotype.Repository;
4   -
5   -import com.baomidou.mybatisplus.mapper.BaseMapper;
6   -import com.lyms.hospital.entity.sys.User;
7   -
8   -/**
9   - * <p>
10   - * Mapper接口
11   - * </p>
12   - *
13   - * @author 风车车
14   - * @since 2016-12-12
15   - */
16   -@Repository
17   -public interface UserMapper extends BaseMapper<User> {
18   -
19   -}
parent/hospital.web/src/main/java/com/lyms/hospital/dao/sys/UserMapper.xml View file @ 99b1500
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.hospital.dao.sys.UserMapper">
4   -
5   -
6   -</mapper>
parent/hospital.web/src/main/java/com/lyms/hospital/entity/sys/User.java View file @ 99b1500
1   -package com.lyms.hospital.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   -}
parent/hospital.web/src/main/java/com/lyms/hospital/inteceptor/TokenValidateInteceptor.java View file @ 99b1500
... ... @@ -5,6 +5,7 @@
5 5 import com.lyms.constants.Constants;
6 6 import com.lyms.context.ContextHolder;
7 7 import com.lyms.exception.LoginException;
  8 +import com.lyms.hospital.service.token.TokenService;
8 9 import com.lyms.hospital.session.SessionProvider;
9 10 import com.lyms.web.controller.BaseController;
10 11 import org.apache.commons.lang.StringUtils;
... ... @@ -31,7 +32,7 @@
31 32 {
32 33  
33 34 @Autowired
34   - private SessionProvider sessionProvider;
  35 + private TokenService tokenService;
35 36  
36 37 public static boolean isSiteController(Object handler) {
37 38 return handler instanceof HandlerMethod && (((HandlerMethod) handler).getBean() instanceof BaseController);
... ... @@ -76,8 +77,7 @@
76 77 if (StringUtils.isEmpty(token)) {
77 78 throw new LoginException("miss auth.");
78 79 }
79   -
80   - return sessionProvider.checkSession(httpServletRequest, httpServletResponse, token);
  80 + return tokenService.validToken(token);
81 81 }
82 82  
83 83 /**
parent/hospital.web/src/main/java/com/lyms/hospital/service/sys/UserService.java View file @ 99b1500
1   -package com.lyms.hospital.service.sys;
2   -
3   -import com.lyms.hospital.entity.sys.User;
4   -import com.lyms.web.service.BaseService;
5   -
6   -
7   -/**
8   - * <p>
9   - * 服务类
10   - * </p>
11   - *
12   - * @author 风车车
13   - * @since 2016-12-12
14   - */
15   -public interface UserService extends BaseService<User> {
16   -
17   -}
parent/hospital.web/src/main/java/com/lyms/hospital/service/sys/impl/UserServiceImpl.java View file @ 99b1500
1   -package com.lyms.hospital.service.sys.impl;
2   -
3   -import org.springframework.stereotype.Service;
4   -
5   -import com.baomidou.mybatisplus.service.impl.ServiceImpl;
6   -import com.lyms.hospital.dao.sys.UserMapper;
7   -import com.lyms.hospital.entity.sys.User;
8   -import com.lyms.hospital.service.sys.UserService;
9   -
10   -/**
11   - * <p>
12   - * 服务实现类
13   - * </p>
14   - *
15   - * @author 风车车
16   - * @since 2016-12-12
17   - */
18   -@Service
19   -public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
20   -
21   -}
parent/hospital.web/src/main/java/com/lyms/hospital/service/token/TokenService.java View file @ 99b1500
  1 +package com.lyms.hospital.service.token;
  2 +
  3 +/**
  4 + * Created by riecard on 15/9/22.
  5 + */
  6 +public interface TokenService
  7 +{
  8 +
  9 +
  10 + String createToken(String userId);
  11 +
  12 + String createToken(String userId, Integer second);
  13 +
  14 + boolean resetToken(String token);
  15 +
  16 + boolean validToken(String token);
  17 +
  18 + boolean validToken(String token, Integer second);
  19 +
  20 + String getUserId(String token);
  21 +
  22 + void deleteAllToken(String userId);
  23 +
  24 + void deleteAllToken(String userId, String prefix);
  25 +
  26 + void deleteToken(String token);
  27 +
  28 +}
parent/hospital.web/src/main/java/com/lyms/hospital/service/token/impl/TokenServiceImpl.java View file @ 99b1500
  1 +package com.lyms.hospital.service.token.impl;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +import java.util.UUID;
  6 +import java.util.concurrent.TimeUnit;
  7 +
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.beans.factory.annotation.Value;
  10 +import org.springframework.data.redis.core.RedisTemplate;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +import com.lyms.hospital.service.token.TokenService;
  14 +import com.lyms.util.SerializeUtils;
  15 +import com.lyms.util.TokenUtils;
  16 +
  17 +/**
  18 + * Created by riecard on 15/9/22.
  19 + */
  20 +@Service
  21 +public class TokenServiceImpl implements TokenService
  22 +{
  23 +
  24 + static final Integer seconds = 7 * 24 * 60 * 60;
  25 + static final Integer ams_seconds = 60 * 60;
  26 + @Value("${token.prefix}")
  27 + private String tokenPrefix;
  28 +
  29 + @Autowired
  30 + private RedisTemplate<Serializable, Serializable> redisTemplate;
  31 +
  32 + private String prefix = null;
  33 +
  34 + private String getPrefix()
  35 + {
  36 + return tokenPrefix;
  37 + }
  38 +
  39 + private Integer getSeconds()
  40 + {
  41 + if ("ams".equals(prefix))
  42 + {
  43 + return ams_seconds;
  44 + } else
  45 + {
  46 + return seconds;
  47 + }
  48 + }
  49 +
  50 + @Override
  51 + public String createToken(String userId, Integer second)
  52 + {
  53 + String token = getPrefix() + TokenUtils.getToken(UUID.randomUUID().toString());
  54 + redisTemplate.opsForValue().set(token, userId);
  55 + redisTemplate.expire(token, second, TimeUnit.SECONDS);
  56 +
  57 +// List<Serializable> list = new ArrayList<Serializable>();
  58 +// List<Serializable> delList = new ArrayList<Serializable>();
  59 +// String tempKey = getPrefix() + userId;
  60 +// Object obj = redisTemplate.opsForValue().get(tempKey);
  61 +// if (obj != null)
  62 +// {
  63 +// list = (List<Serializable>) obj;
  64 +// }
  65 +// for (Serializable key : list)
  66 +// {
  67 +// if (!redisTemplate.hasKey(key))
  68 +// {
  69 +// delList.add(key);
  70 +// }
  71 +// }
  72 +// list.removeAll(delList);
  73 +// list.add(token);
  74 +// redisTemplate.opsForValue().set(tempKey, SerializeUtils.serialize(list), second);
  75 + return token;
  76 + }
  77 +
  78 + @Override
  79 + public String createToken(String userId)
  80 + {
  81 + return createToken(userId, getSeconds());
  82 + }
  83 +
  84 + @Override
  85 + public boolean resetToken(String token)
  86 + {
  87 + Object obj = redisTemplate.opsForValue().get(token);
  88 + if (obj != null)
  89 + {
  90 + redisTemplate.opsForValue().set(token, SerializeUtils.serialize(obj));
  91 + redisTemplate.expire(token, getSeconds(), TimeUnit.SECONDS);
  92 + return true;
  93 + }
  94 + return false;
  95 + }
  96 +
  97 + @Override
  98 + public boolean validToken(String token)
  99 + {
  100 + return validToken(token, getSeconds());
  101 + }
  102 +
  103 + @Override
  104 + public boolean validToken(String token, Integer second)
  105 + {
  106 + Object obj = redisTemplate.opsForValue().get(token);
  107 + if (obj != null)
  108 + {
  109 + //redisTemplate.opsForValue().set(token, SerializeUtils.serialize(obj));
  110 + redisTemplate.expire(token, second, TimeUnit.SECONDS);
  111 + return true;
  112 + }
  113 + return false;
  114 + }
  115 +
  116 + @Override
  117 + public String getUserId(String token)
  118 + {
  119 + Object obj = redisTemplate.opsForValue().get(token);
  120 + if (obj != null)
  121 + {
  122 + //redisTemplate.opsForValue().set(token, SerializeUtils.serialize(obj));
  123 + redisTemplate.expire(token, getSeconds(), TimeUnit.SECONDS);
  124 + return (String) obj;
  125 + }
  126 + return null;
  127 + }
  128 +
  129 + @Override
  130 + public void deleteToken(String token)
  131 + {
  132 + redisTemplate.delete(token);
  133 + }
  134 +
  135 + @Override
  136 + public void deleteAllToken(String userId)
  137 + {
  138 + String tempKey = getPrefix() + "_tokenlist_" + userId;
  139 + Object obj = redisTemplate.opsForValue().get(tempKey);
  140 + if (obj != null)
  141 + {
  142 + List<Serializable> list = (List<Serializable>) obj;
  143 + redisTemplate.delete(list);
  144 + redisTemplate.delete(tempKey);
  145 + }
  146 + }
  147 +
  148 + @Override
  149 + public void deleteAllToken(String userId, String prefix)
  150 + {
  151 + String tempKey = prefix + "_tokenlist_" + userId;
  152 + Object obj = redisTemplate.opsForValue().get(tempKey);
  153 + if (obj != null)
  154 + {
  155 + List<Serializable> list = (List<Serializable>) obj;
  156 + redisTemplate.delete(list);
  157 + redisTemplate.delete(tempKey);
  158 + }
  159 + }
  160 +}
parent/hospital.web/src/main/resources/app-context.xml View file @ 99b1500
... ... @@ -56,6 +56,11 @@
56 56  
57 57 <bean class = "com.lyms.aop.SysLogAop"/>
58 58  
  59 +
  60 + <mvc:interceptors>
  61 + <bean id="tokenValidateInteceptor" class="com.lyms.hospital.inteceptor.TokenValidateInteceptor"/>
  62 + </mvc:interceptors>
  63 +
59 64 <import resource="xml/app-*.xml" />
60 65 </beans>
parent/hospital.web/src/main/resources/dev/redis.properties View file @ 99b1500
1   -redis.host1=119.90.57.26
  1 +redis.host1=127.0.0.1
2 2 redis.port1=6379
3   -redis.password1=Lyms123456
  3 +redis.password1=
4 4 #redis.host1=127.0.0.1
5 5 #redis.port1=6379
6 6 #redis.password1=Lyms123456
parent/hospital.web/src/test/java/test/hospital/crud/CrudTest.java View file @ 99b1500
1   -package test.hospital.crud;
2   -
3   -import java.util.List;
4   -
5   -import org.junit.Test;
6   -import org.springframework.beans.factory.annotation.Autowired;
7   -
8   -import com.baomidou.mybatisplus.mapper.EntityWrapper;
9   -import com.baomidou.mybatisplus.plugins.Page;
10   -import com.lyms.hospital.entity.sys.User;
11   -import com.lyms.hospital.service.sys.UserService;
12   -
13   -import test.hospital.BaseTest;
14   -
15   -/**
16   - * 详情参考:http://mp.baomidou.com/
17   - *
18   - */
19   -public class CrudTest extends BaseTest{
20   -
21   -
22   - @Autowired
23   - UserService userService;
24   -
25   - @Test
26   - public void selectById(){
27   - outJson(userService.selectById("0D1FF49672D74899A0B441EAF9D6AC17"));
28   - }
29   -
30   - @Test
31   - public void getPage(){
32   - Page<User> page = new Page<User>(4,3);
33   - outJson(userService.selectPage(page));
34   - }
35   -
36   - @Test
37   - public void search(){
38   - // 查询姓名为‘张三’的所有用户记录
39   - List<User> userList = userService.selectList(new EntityWrapper<User>().eq("username", "张三"));
40   - outJson(userList);
41   - EntityWrapper<User> ew = new EntityWrapper<User>();
42   - ew.where("name={0}", "'zhangsan'").and("id=1")
43   - .orNew("status={0}", "0").or("status=1")
44   - .notLike("nlike", "notvalue")
45   - .andNew("new=xx").like("hhh", "ddd")
46   - .andNew("pwd=11").isNotNull("n1,n2").isNull("n3")
47   - .groupBy("x1").groupBy("x2,x3")
48   - .having("x1=11").having("x3=433")
49   - .orderBy("dd").orderBy("d1,d2");
50   - outPrint(ew.getSqlSegment());
51   - }
52   -
53   -
54   -}
  1 +//package test.hospital.crud;
  2 +//
  3 +//import java.util.List;
  4 +//
  5 +//import org.junit.Test;
  6 +//import org.springframework.beans.factory.annotation.Autowired;
  7 +//
  8 +//import com.baomidou.mybatisplus.mapper.EntityWrapper;
  9 +//import com.baomidou.mybatisplus.plugins.Page;
  10 +//import com.lyms.hospital.entity.sys.User;
  11 +//import com.lyms.hospital.service.sys.UserService;
  12 +//
  13 +//import test.hospital.BaseTest;
  14 +//
  15 +///**
  16 +// * 详情参考:http://mp.baomidou.com/
  17 +// *
  18 +// */
  19 +//public class CrudTest extends BaseTest{
  20 +//
  21 +//
  22 +// @Autowired
  23 +// UserService userService;
  24 +//
  25 +// @Test
  26 +// public void selectById(){
  27 +// outJson(userService.selectById("0D1FF49672D74899A0B441EAF9D6AC17"));
  28 +// }
  29 +//
  30 +// @Test
  31 +// public void getPage(){
  32 +// Page<User> page = new Page<User>(4,3);
  33 +// outJson(userService.selectPage(page));
  34 +// }
  35 +//
  36 +// @Test
  37 +// public void search(){
  38 +// // 查询姓名为‘张三’的所有用户记录
  39 +// List<User> userList = userService.selectList(new EntityWrapper<User>().eq("username", "张三"));
  40 +// outJson(userList);
  41 +// EntityWrapper<User> ew = new EntityWrapper<User>();
  42 +// ew.where("name={0}", "'zhangsan'").and("id=1")
  43 +// .orNew("status={0}", "0").or("status=1")
  44 +// .notLike("nlike", "notvalue")
  45 +// .andNew("new=xx").like("hhh", "ddd")
  46 +// .andNew("pwd=11").isNotNull("n1,n2").isNull("n3")
  47 +// .groupBy("x1").groupBy("x2,x3")
  48 +// .having("x1=11").having("x3=433")
  49 +// .orderBy("dd").orderBy("d1,d2");
  50 +// outPrint(ew.getSqlSegment());
  51 +// }
  52 +//
  53 +//
  54 +//}
parent/hospital.web/src/test/java/test/hospital/token/TokenTest.java View file @ 99b1500
  1 +package test.hospital.token;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.concurrent.TimeUnit;
  5 +
  6 +import org.junit.Test;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.data.redis.core.RedisTemplate;
  9 +import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
  10 +
  11 +import test.hospital.BaseServiceTest;
  12 +
  13 +public class TokenTest extends BaseServiceTest{
  14 +
  15 +@Autowired
  16 + private RedisTemplate<Serializable, Serializable> redisTemplate;
  17 + @Test
  18 + public void test(){
  19 + String key = "token:user:asd3";
  20 + redisTemplate.opsForValue().set(key, "123");
  21 + redisTemplate.expire(key, 1000000,TimeUnit.SECONDS);
  22 + outJson(redisTemplate.opsForValue().get(key));
  23 + }
  24 +}