Commit bd4264e33a82d113fd1fcbef2ad20ced97f936b6

Authored by yangfei
Exists in master

Merge branch 'master' of https://git.healthbaby.com.cn/jiangjiazhi/center

Showing 16 changed files

parent/center.manager/src/main/java/com/lyms/cm/controller/sys/SysRemoteController.java View file @ bd4264e
1 1 package com.lyms.cm.controller.sys;
2 2  
3   -import java.io.IOException;
4   -
5 3 import javax.servlet.http.HttpServletRequest;
6 4  
7 5 import org.springframework.http.MediaType;
... ... @@ -22,7 +20,7 @@
22 20  
23 21 @RequestMapping(value = "/sycn", produces = { MediaType.APPLICATION_JSON_VALUE })
24 22 @ResponseBody
25   - public Object push(HttpServletRequest request) throws ClassNotFoundException, IOException {
  23 + public Object push(HttpServletRequest request) throws Exception {
26 24 ChannelData model = SyncUtils.conver(request);
27 25 Object object = SyncHandler.handler(model);
28 26 model.setData(ParamsAdpter.builder().push(object).toJsonString());
parent/center.manager/src/main/java/com/lyms/cm/job/SyncFixJob.java View file @ bd4264e
... ... @@ -96,18 +96,22 @@
96 96 LOG.info("拉取到本地任务: " + ToStringBuilder.reflectionToString(oldData));
97 97 LOG.info("返回结果: " + result);
98 98 System.out.println("执行: " + ToStringBuilder.reflectionToString(data));
99   - Object handlResult = SyncHandler.handler(data);
100   - // 要求处理成功都必须返回true | false;
101   - Boolean tag = (Boolean) handlResult;
102   - if (tag) {
103   - data.setRemote(oldData.getRemote());
104   - data.setData(ParamsAdpter.builder().push(data.getId()).toJsonString());
105   - data.setAck(true);
106   - // 处理成功回执消息
107   - data.setRemoteClazz("com.lyms.hospital.service.sys.impl.SyncDataBasicServiceImpl");
108   - data.setRemoteMethod("updateBasic");
109   - work.ack(data);
110   - }
  99 + try{
  100 + Object handlResult = SyncHandler.handler(data);
  101 + // 要求处理成功都必须返回true | false;
  102 + Boolean tag = (Boolean) handlResult;
  103 + if (tag) {
  104 + data.setRemote(oldData.getRemote());
  105 + data.setData(ParamsAdpter.builder().push(data.getId()).toJsonString());
  106 + data.setAck(true);
  107 + // 处理成功回执消息
  108 + data.setRemoteClazz("com.lyms.hospital.service.sys.impl.SyncDataBasicServiceImpl");
  109 + data.setRemoteMethod("updateBasic");
  110 + work.ack(data);
  111 + }
  112 + }catch (Exception e) {
  113 + LOG.error("拉取任务执行失败:{}",e);
  114 + }
111 115 }
112 116 }
113 117 }
parent/center.manager/src/main/java/com/lyms/cm/job/SyncTableJob.java View file @ bd4264e
  1 +package com.lyms.cm.job;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +import java.util.concurrent.atomic.AtomicBoolean;
  6 +
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.data.redis.core.RedisTemplate;
  11 +
  12 +import com.alibaba.druid.support.json.JSONUtils;
  13 +import com.alibaba.fastjson.JSONObject;
  14 +import com.baomidou.mybatisplus.mapper.EntityWrapper;
  15 +import com.lyms.base.common.entity.sys.SyncDataBasic;
  16 +import com.lyms.base.common.service.sys.SyncDataBasicService;
  17 +import com.lyms.sync.ParamsAdpter;
  18 +import com.lyms.sync.SyncCallback;
  19 +import com.lyms.sync.SyncCenter;
  20 +import com.lyms.sync.SyncHandler;
  21 +import com.lyms.sync.SyncCenter.Work;
  22 +import com.lyms.sync.channel.ChannelData;
  23 +import com.lyms.sync.queue.SyncQueue;
  24 +import com.lyms.util.HttpUtils;
  25 +import com.lyms.util.JsonUtils;
  26 +
  27 +/**
  28 + * <li>@ClassName: SyncTableJob
  29 + * <li>@Description: 同步任务执行器,获取SYNC_DATA_BASIC表格的数据进行处理
  30 + * <li>@author 方承
  31 + * <li>@date 2017年5月5日
  32 + * <li>
  33 + */
  34 +public class SyncTableJob {
  35 +
  36 + private static Logger log = LoggerFactory.getLogger(SyncTableJob.class);
  37 +
  38 + @Autowired
  39 + private SyncDataBasicService syncDataBasicService;
  40 +
  41 + public void excute() {
  42 + List<SyncDataBasic> dataList = syncDataBasicService.selectList(new EntityWrapper<SyncDataBasic>().where("IFSUC=0"));
  43 + if(dataList != null ){
  44 + log.debug("=======开始进行 SYNC_DATA_BASIC 表格数据的同步=======");
  45 + for(SyncDataBasic entity : dataList){
  46 + try{
  47 + ChannelData data = JsonUtils.jsonToBean(entity.getData(), ChannelData.class);
  48 + Object handResult = SyncHandler.handler(data);
  49 + if (data.getLoop()) {
  50 + data = (ChannelData) handResult;
  51 + } else {
  52 + data.setData(ParamsAdpter.builder().push(handResult).toJsonString());
  53 + }
  54 + entity.setIfsuc(1);
  55 + syncDataBasicService.updateById(entity);
  56 + }catch (Exception e) {
  57 + log.error("【SYNC_DATA_BASIC】表格数据的同步错误:SyncDataBasic = {} {}",JSONObject.toJSON(entity),e);
  58 + }
  59 + }
  60 + }
  61 + }
  62 +
  63 +
  64 +}
parent/center.manager/src/main/java/com/lyms/cm/job/SyncTmpJob.java View file @ bd4264e
1 1 package com.lyms.cm.job;
2 2  
  3 +import java.io.Serializable;
3 4 import java.util.concurrent.atomic.AtomicBoolean;
4 5  
5 6 import org.slf4j.Logger;
6 7 import org.slf4j.LoggerFactory;
7 8 import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.data.redis.core.RedisTemplate;
8 10  
  11 +import com.alibaba.fastjson.JSONObject;
9 12 import com.lyms.sync.SyncCallback;
10 13 import com.lyms.sync.SyncCenter;
11 14 import com.lyms.sync.SyncCenter.Work;
12 15 import com.lyms.sync.channel.ChannelData;
  16 +import com.lyms.sync.queue.SyncQueue;
13 17 import com.lyms.util.HttpUtils;
14 18 import com.lyms.util.JsonUtils;
15 19  
16 20  
... ... @@ -28,8 +32,20 @@
28 32  
29 33 @Autowired
30 34 public SyncCenter center;
  35 +
  36 + @Autowired
  37 + public RedisTemplate<Serializable, Serializable> template;
  38 +
  39 + /**
  40 + * 初始化的时候将错误队列内容迁移到临时任务队列
  41 + */
  42 + private static boolean initLoadErrorToTempWork = true;
31 43  
32 44 public void excute() {
  45 + if(initLoadErrorToTempWork){
  46 + errorWorkToTempWork();
  47 + }
  48 +
33 49 if (reset.get()) {
34 50 return;
35 51 }
... ... @@ -64,6 +80,34 @@
64 80 } finally {
65 81 reset.set(false);
66 82 }
  83 + }
  84 +
  85 +
  86 + /**
  87 + * <li>@Description:错误队列迁移到临时任务队列
  88 + * <li>
  89 + * <li>创建人:方承
  90 + * <li>创建时间:2017年5月5日
  91 + * <li>修改人:
  92 + * <li>修改时间:
  93 + */
  94 + public void errorWorkToTempWork(){
  95 + initLoadErrorToTempWork = false;
  96 + LOG.info("=============开始==迁移同步队列【错误队列 转移到 临时任务队列】============");
  97 + boolean hasNext = true;
  98 + while(hasNext){
  99 + Serializable object = template.opsForList().rightPop(SyncQueue.TMP_WORK_ERROR);
  100 + if(object != null){
  101 + ChannelData data = (ChannelData) object;
  102 + LOG.info(JSONObject.toJSONString(data));
  103 + data.setErrorRetryCount(0);
  104 + template.opsForList().leftPush(SyncQueue.TMP_WORK, data);
  105 + }else{
  106 + hasNext = false;
  107 + }
  108 + }
  109 + LOG.info("=============结束==迁移同步队列【错误队列 转移到 临时任务队列】============");
  110 + return;
67 111 }
68 112 }
parent/center.manager/src/main/resources/dev/redis.properties View file @ bd4264e
1   -#redis.host1=119.90.57.26
2   -#redis.port1=6379
3   -#redis.password1=Lyms123456
4   -redis.host1=127.0.0.1
  1 +redis.host1=119.90.57.26
5 2 redis.port1=6379
6   -redis.password1=
  3 +redis.password1=Lyms123456
7 4 #redis.host1=127.0.0.1
8 5 #redis.port1=6379
  6 +#redis.password1=
  7 +#redis.host1=127.0.0.1
  8 +#redis.port1=6379
9 9 #redis.password1=Lyms123456
10 10  
11 11  
... ... @@ -32,6 +32,6 @@
32 32 redis.maxActive=600
33 33 redis.maxWait=1000
34 34 redis.testOnBorrow=true
35   -redis.HttpSession.redisNamespace=hospital.mac
  35 +redis.HttpSession.redisNamespace=center
36 36 spring.redis.cluster.max-redirects= 3
parent/center.manager/src/main/resources/xml/app-timer.xml View file @ bd4264e
... ... @@ -16,10 +16,12 @@
16 16 <task:scheduled-tasks>
17 17 <task:scheduled ref="syncTmpJob" method="excute" cron="*/10 * * * * ?"/>
18 18 <task:scheduled ref="syncFixJob" method="excute" cron="*/30 * * * * ?"/>
  19 + <task:scheduled ref="syncTableJob" method="excute" cron="*/30 * * * * ?"/>
19 20 </task:scheduled-tasks>
20 21  
21 22 <bean class="com.lyms.cm.job.SyncTmpJob" id="syncTmpJob"/>
22 23 <bean class="com.lyms.cm.job.SyncFixJob" id="syncFixJob"/>
  24 + <bean class="com.lyms.cm.job.SyncTableJob" id="syncTableJob"/>
23 25  
24 26 </beans>
parent/core.sdk/src/main/java/com/lyms/common/db/DBPasswordCallback.java View file @ bd4264e
... ... @@ -15,10 +15,11 @@
15 15 import com.lyms.util.Base64Utils;
16 16  
17 17 /**
18   - * 数据库密码回调解密
19   - *
20   - * @author ShenHuaJie
21   - * @version 2016年5月20日 下午3:18:25
  18 + * <li>@ClassName: DBPasswordCallback
  19 + * <li>@Description: 数据库密码回调解密
  20 + * <li>@author 方承
  21 + * <li>@date 2017年5月5日
  22 + * <li>
22 23 */
23 24 @SuppressWarnings("serial")
24 25 public class DBPasswordCallback extends DruidPasswordCallback {
... ... @@ -39,7 +40,19 @@
39 40 }
40 41 }
41 42  
42   - // 请使用该方法加密后,把密文写入classpath:/config/jdbc.properties
  43 + /**
  44 + * 数据库密码回调解密
  45 + * <!--数据源加密操作-->
  46 + <bean id="dbPasswordCallback" class="com.lyms.common.db.DBPasswordCallback" lazy-init="true"/>
  47 +
  48 + <bean id="readDataSource" class="com.alibaba.druid.pool.DruidDataSource"
  49 + destroy-method="close" init-method="init" lazy-init="true">
  50 + <property name="password" value="${password}"/>
  51 +
  52 + <property name="connectionProperties" value="password=${password}"/>
  53 + <property name="passwordCallback" ref="dbPasswordCallback"/>
  54 + </bean>
  55 + */
43 56 public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, Exception {
44 57 String encrypt = Base64Utils.encode(DES.encrypt("root".getBytes(), key));
45 58 System.out.println(encrypt);
parent/core.sdk/src/main/java/com/lyms/sync/SyncHandler.java View file @ bd4264e
... ... @@ -32,12 +32,12 @@
32 32 */
33 33 private static final SyncCenter center = SyncCenter.install();
34 34  
35   - public static Object handler(ChannelData data) {
  35 + public static Object handler(ChannelData data) throws Exception{
36 36 try {
37 37 return invoke(data);
38 38 } catch (Exception e) {
39 39 LOG.error("执行方法错误: {}", e);
40   - return false;
  40 + throw e;
41 41 }
42 42 }
43 43  
parent/core.sdk/src/main/java/com/lyms/sync/channel/ChannelData.java View file @ bd4264e
... ... @@ -64,6 +64,11 @@
64 64 * 创建时间
65 65 */
66 66 private Long ts;
  67 +
  68 + /**
  69 + * 出错重试次数
  70 + */
  71 + private int errorRetryCount;
67 72  
68 73 public ChannelData(String remote, String remoteClazz, String remoteMethod, String data, boolean loop) {
69 74 this.id = StrUtils.uuid();
... ... @@ -166,6 +171,16 @@
166 171 public String toJsonString() {
167 172 return JsonUtils.beanToJson(this);
168 173 }
  174 +
  175 + public int getErrorRetryCount() {
  176 + return errorRetryCount;
  177 + }
  178 +
  179 + public void setErrorRetryCount(int errorRetryCount) {
  180 + this.errorRetryCount = errorRetryCount;
  181 + }
  182 +
  183 +
169 184  
170 185 }
parent/core.sdk/src/main/java/com/lyms/sync/queue/SyncQueue.java View file @ bd4264e
... ... @@ -48,6 +48,17 @@
48 48 * 临时任务
49 49 */
50 50 public static final String TMP_WORK = "TMP_WORK";
  51 +
  52 + /**
  53 + * 错误重试次数
  54 + */
  55 + public static final int ERROR_RETRY_COUNT = 3;
  56 +
  57 +
  58 + /**
  59 + * 临时任务出错一定次数后放入此任务队列
  60 + */
  61 + public static final String TMP_WORK_ERROR = "TMP_WORK_ERROR";
51 62  
52 63 /**
53 64 * 回执消息任务
... ... @@ -112,7 +123,13 @@
112 123 * <li>修改时间:
113 124 */
114 125 private boolean pushTempWork(ChannelData data) {
115   - Long tag = template.opsForList().leftPush(TMP_WORK, data);
  126 + Long tag = 0l;
  127 + if(data.getErrorRetryCount() > ERROR_RETRY_COUNT){
  128 + tag = template.opsForList().leftPush(TMP_WORK_ERROR, data);
  129 + }else{
  130 + data.setErrorRetryCount(data.getErrorRetryCount() + 1);
  131 + tag = template.opsForList().leftPush(TMP_WORK, data);
  132 + }
116 133 return tag >= 1;
117 134 }
118 135  
parent/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java View file @ bd4264e
... ... @@ -6,6 +6,13 @@
6 6 import javax.servlet.http.HttpServletResponse;
7 7  
8 8 import org.apache.commons.lang3.StringUtils;
  9 +import org.apache.shiro.SecurityUtils;
  10 +import org.apache.shiro.authc.AccountException;
  11 +import org.apache.shiro.authc.AuthenticationException;
  12 +import org.apache.shiro.authc.AuthenticationToken;
  13 +import org.apache.shiro.authc.LockedAccountException;
  14 +import org.apache.shiro.authc.UnknownAccountException;
  15 +import org.apache.shiro.authc.UsernamePasswordToken;
9 16 import org.springframework.beans.factory.annotation.Autowired;
10 17 import org.springframework.web.bind.annotation.RequestBody;
11 18 import org.springframework.web.bind.annotation.RequestMapping;
12 19  
... ... @@ -14,7 +21,9 @@
14 21 import org.springframework.web.bind.annotation.ResponseBody;
15 22 import org.springframework.web.bind.annotation.RestController;
16 23  
  24 +import com.alibaba.druid.support.json.JSONUtils;
17 25 import com.alibaba.fastjson.JSON;
  26 +import com.alibaba.fastjson.JSONObject;
18 27 import com.lyms.annotation.TokenRequired;
19 28 import com.lyms.base.common.entity.organ.Organizations;
20 29 import com.lyms.base.common.entity.role.Permissions;
21 30  
22 31  
... ... @@ -24,10 +33,13 @@
24 33 import com.lyms.base.common.service.role.PermissionsService;
25 34 import com.lyms.base.common.service.role.RolesService;
26 35 import com.lyms.base.common.service.user.UsersService;
  36 +import com.lyms.constants.Constants;
27 37 import com.lyms.hospital.service.token.TokenService;
  38 +import com.lyms.shiro.ShiroWebUtils;
28 39 import com.lyms.util.DateTimeUtils;
29 40 import com.lyms.util.InstanceUtils;
30 41 import com.lyms.util.MD5Utils;
  42 +import com.lyms.util.StrUtils;
31 43 import com.lyms.web.bean.AjaxResult;
32 44 import com.lyms.web.controller.BaseController;
33 45  
34 46  
35 47  
... ... @@ -105,24 +117,30 @@
105 117 @RequestParam(value = "password", required = false) String password,
106 118 AjaxResult ajaxResult,
107 119 HttpServletResponse response) {
  120 + System.out.println(JSONObject.toJSON(ShiroWebUtils.getCurrentUser()));
108 121 ajaxResult.setSuccess(false);
109 122 if (StringUtils.isEmpty(account) && (StringUtils.isEmpty(code) || StringUtils.isEmpty(password))) {
110 123 ajaxResult.setMessage("登录账户或者验证码为空,请输入!");
111 124 return ajaxResult;
112 125 }
113   - Users users = usersService.getUserByUsername(account);
114   - if(users == null){
115   - ajaxResult.setMessage("用户不存在!");
116   - return ajaxResult;
  126 + AuthenticationToken authenticationToken = new UsernamePasswordToken(account, password);
  127 + try {
  128 + // 查看ShiroRealm.class
  129 + SecurityUtils.getSubject().login(authenticationToken);
  130 + } catch (AuthenticationException e) {
  131 + if (e instanceof UnknownAccountException) {
  132 + ajaxResult.setMessage("用户不存在!");
  133 + return ajaxResult;
  134 + } else if (e instanceof AccountException) {
  135 + ajaxResult.setMessage("密码不正确!");
  136 + return ajaxResult;
  137 + } else if (e instanceof LockedAccountException) {
  138 + ajaxResult.setMessage("用户被禁用!");
  139 + return ajaxResult;
  140 + }
117 141 }
118   - if(!users.getPwd().equals(MD5Utils.md5(password))){
119   - ajaxResult.setMessage("密码不正确!");
120   - return ajaxResult;
121   - }
122   - if(users.getEnable() < 1){
123   - ajaxResult.setMessage("用户被禁用!");
124   - return ajaxResult;
125   - }
  142 + System.out.println(ShiroWebUtils.getCurrentUser());
  143 + Users users = ShiroWebUtils.getCurrentUser();
126 144 //Organizations organizations = organizationsService.selectById( users.getOrgId());
127 145 Map<String, Object> result = InstanceUtils.newHashMap();
128 146 String token = tokenService.createToken(users);
129 147  
... ... @@ -141,13 +159,13 @@
141 159 result.put("watermark", "water");
142 160 ajaxResult.setData(result);
143 161 ajaxResult.setSuccess(true);
  162 + getSession().setAttribute(Constants.CURRENT_USER, users);
144 163 return ajaxResult;
145 164 }
146 165  
147 166  
148 167 @RequestMapping(value = "/tokensCheck", method = RequestMethod.POST)
149 168 @ResponseBody
150   - @TokenRequired
151 169 public AjaxResult usersLogin(
152 170 HttpServletResponse response) {
153 171 System.out.println(1111111);
parent/hospital.web/src/main/java/com/lyms/hospital/controller/RouterController.java View file @ bd4264e
... ... @@ -31,7 +31,7 @@
31 31 private static final Logger log = LoggerFactory.getLogger(RouterController.class);
32 32  
33 33 @RequestMapping(value = "/pull", produces = { MediaType.APPLICATION_JSON_VALUE })
34   - public Object pull(HttpServletRequest request) throws ClassNotFoundException, IOException {
  34 + public Object pull(HttpServletRequest request) throws Exception {
35 35 ChannelData data = SyncUtils.conver(request);
36 36 log.debug("节点数据被中心拉取:" + ToStringBuilder.reflectionToString(data));
37 37 Object handResult = SyncHandler.handler(data);
38 38  
... ... @@ -45,10 +45,10 @@
45 45 }
46 46  
47 47 @RequestMapping(value = "/push", produces = { MediaType.APPLICATION_JSON_VALUE })
48   - public Object push(HttpServletRequest request) throws ClassNotFoundException, IOException {
  48 + public Object push(HttpServletRequest request) throws Exception {
49 49 ChannelData data = SyncUtils.conver(request);
50 50 log.debug("中心推送数据到节点:" + ToStringBuilder.reflectionToString(data));
51   - Object handResult = SyncHandler.handler(data);
  51 + Object handResult = SyncHandler.handler(data);
52 52 if (data.getLoop()) {
53 53 data = (ChannelData) handResult;
54 54 } else {
parent/hospital.web/src/main/java/com/lyms/hospital/shiro/ShiroRealm.java View file @ bd4264e
  1 +package com.lyms.hospital.shiro;
  2 +
  3 +import java.util.HashSet;
  4 +import java.util.List;
  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.LockedAccountException;
  11 +import org.apache.shiro.authc.SimpleAuthenticationInfo;
  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.base.common.entity.user.Users;
  23 +import com.lyms.base.common.enums.StatusEnum;
  24 +import com.lyms.base.common.service.role.PermissionsService;
  25 +import com.lyms.base.common.service.user.UsersService;
  26 +import com.lyms.shiro.ShiroWebUtils;
  27 +import com.lyms.util.CollectionUtils;
  28 +import com.lyms.util.MD5Utils;
  29 +import com.lyms.util.StrUtils;
  30 +
  31 +/**
  32 + * <li>@ClassName: ShiroRealm
  33 + * <li>@Description: 自定义Realm授权与验证实现
  34 + * <li>@author 方承
  35 + * <li>@date 2015年12月29日
  36 + * <li>
  37 + */
  38 +public class ShiroRealm extends AuthorizingRealm {
  39 +
  40 + @SuppressWarnings("unused")
  41 + private static Logger logger = LoggerFactory.getLogger(ShiroRealm.class);
  42 +
  43 + public ShiroRealm() {
  44 + super(new AllowAllCredentialsMatcher());
  45 + setAuthenticationTokenClass(UsernamePasswordToken.class);
  46 + // FIXME: 暂时禁用Cache
  47 + setCachingEnabled(false);
  48 + }
  49 +
  50 + @Autowired
  51 + private UsersService sysUsersService;
  52 +
  53 + private PermissionsService sysPermissionsService;
  54 +
  55 + // @Autowired
  56 + // private ResourceService resourceService;
  57 +
  58 + @Override
  59 + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  60 + String username = (String) principals.getPrimaryPrincipal();
  61 + Users user = sysUsersService.getUserByUsername(username);
  62 + // 授权
  63 + SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
  64 + List<String> roleIdList = sysUsersService.getRoleIdListByUserid(user.getId());
  65 + if (CollectionUtils.isNotEmpty(roleIdList)) {
  66 + authorizationInfo.setRoles(new HashSet<String>(roleIdList));
  67 + }
  68 + authorizationInfo.setStringPermissions(sysPermissionsService.getUserPermissionSet(user.getId(),"1"));
  69 + return authorizationInfo;
  70 + }
  71 +
  72 + @Override
  73 + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
  74 + throws AuthenticationException {
  75 + UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
  76 + String username = token.getUsername();
  77 + Users user = sysUsersService.getUserByUsername(username);
  78 + if (StatusEnum.isDisEnabled(user.getEnable())) {
  79 + throw new LockedAccountException("用户已经被禁用,请联系管理员!");
  80 + }
  81 + StringBuilder pwd = new StringBuilder(100);
  82 + for (int i = 0; i < token.getPassword().length; i++) {
  83 + pwd.append(token.getPassword()[i]);
  84 + }
  85 + if (!StrUtils.equals(user.getPwd(), MD5Utils.md5(pwd.toString()))) {
  86 + throw new AccountException("用户名密码不一致");
  87 + }
  88 + ShiroWebUtils.saveCurrentUser(user);
  89 + AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, pwd.toString(), username);
  90 + return authcInfo;
  91 + // User user = userService.getUserByUserName(username);
  92 + // if (user == null) {
  93 + // throw new UnknownAccountException("未知用户");
  94 + // }
  95 + // StringBuilder pwd = new StringBuilder(100);
  96 + // for (int i = 0; i < token.getPassword().length; i++) {
  97 + // pwd.append(token.getPassword()[i]);
  98 + // }
  99 + // if (!StrUtils.equals(user.getPassword(),
  100 + // HashUtils.md5(pwd.toString()))) {
  101 + // throw new AccountException("用户名密码不一致");
  102 + // }
  103 + // ShiroWebUtils.saveCurrentUser(user);
  104 + // AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username,
  105 + // pwd.toString(), username);
  106 + // return authcInfo;
  107 + }
  108 +
  109 +}
parent/hospital.web/src/main/resources/dev/redis.properties View file @ bd4264e
... ... @@ -29,6 +29,6 @@
29 29 redis.maxActive=600
30 30 redis.maxWait=1000
31 31 redis.testOnBorrow=true
32   -redis.HttpSession.redisNamespace=hospital.mac
  32 +redis.HttpSession.redisNamespace=hospital
33 33 spring.redis.cluster.max-redirects= 3
parent/hospital.web/src/main/resources/xml/app-shiro.xml View file @ bd4264e
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop"
  4 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5 + xsi:schemaLocation="
  6 + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7 + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
  8 + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
  9 +
  10 + <!-- 开启Apache Shiro注解 否则使用SHIRO的注解后 @Autowired注解将会失效 -->
  11 + <aop:config proxy-target-class="true"></aop:config>
  12 + <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
  13 + <property name="securityManager" ref="securityManager"/>
  14 + </bean>
  15 +
  16 + <!-- rememberMe-->
  17 + <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
  18 + <constructor-arg value="rememberMe"/>
  19 + <property name="httpOnly" value="true"/>
  20 + <property name="maxAge" value="2592000"/><!-- 30天 -->
  21 + </bean>
  22 +
  23 + <!-- rememberMe管理器 -->
  24 + <bean id="rememberMeManager"
  25 + class="org.apache.shiro.web.mgt.CookieRememberMeManager">
  26 + <!--<property name="cipherKey" value="\#{T(org.apache.shiro.codec.Base64).decode('4AvVhmFLUs0KTA3Kprsdag==')}"/>-->
  27 + <property name="cookie" ref="rememberMeCookie"/>
  28 + </bean>
  29 +
  30 + <bean id="shiroRealm" class="com.lyms.hospital.shiro.ShiroRealm"/>
  31 + <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
  32 + <property name="realm" ref="shiroRealm" />
  33 + <property name="rememberMeManager" ref="rememberMeManager"/>
  34 + </bean>
  35 +
  36 + <bean id="forceLogoutFilter" class="com.lyms.web.filter.ForceLogoutFilter"/>
  37 + <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  38 + <property name="securityManager" ref="securityManager" />
  39 + <property name="loginUrl" value="/login/tokens" />
  40 + <property name="successUrl" value="/index" />
  41 + <property name="filters">
  42 + <util:map>
  43 + <entry key="forceLogout" value-ref="forceLogoutFilter"/>
  44 + </util:map>
  45 + </property>
  46 + <property name="filterChainDefinitions">
  47 + <value>
  48 + /login/tokens = anon
  49 + /** = user,forceLogout
  50 + <!--
  51 + /logout = logout
  52 + /captcha/* = anon
  53 + /upload/* = anon
  54 + /static/** = anon
  55 + /dubboService/** = anon
  56 + /authenticated = authc
  57 + /test/** = anon
  58 + -->
  59 + </value>
  60 + </property>
  61 + </bean>
  62 + <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
  63 +</beans>
parent/hospital.web/src/main/webapp/WEB-INF/web.xml View file @ bd4264e
... ... @@ -58,6 +58,20 @@
58 58 <url-pattern>/*</url-pattern>
59 59 </filter-mapping>
60 60 <filter>
  61 + <filter-name>shiroFilter</filter-name>
  62 + <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  63 + <async-supported>true</async-supported>
  64 + <init-param>
  65 + <param-name>targetFilterLifecycle</param-name>
  66 + <param-value>true</param-value>
  67 + </init-param>
  68 + </filter>
  69 + <filter-mapping>
  70 + <filter-name>shiroFilter</filter-name>
  71 + <url-pattern>/*</url-pattern>
  72 + <dispatcher>REQUEST</dispatcher>
  73 + </filter-mapping>
  74 + <filter>
61 75 <filter-name>springSessionRepositoryFilter</filter-name>
62 76 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
63 77 </filter>