فهرست منبع

增加单点登录功能

tianye 2 سال پیش
والد
کامیت
92e0ee9947

+ 33 - 14
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/controller/AlarmUserController.java

@@ -41,21 +41,40 @@ public class AlarmUserController {
             String obj = requestData.getData().toString();
             String jsonData = RSAService.translateByPublicKey(obj, requestData.getPublicKey());
             AlarmUser user = JSONObject.parseObject(jsonData, AlarmUser.class);
-
-            AlarmUser dataUser = alarmUserService.login(user);
-
-            if (dataUser != null) {
-                String token = "";
-                token = TokenUtil.createJwtToken(dataUser.getUserName());
-                AlarmUser data = new AlarmUser();
-                data.setChineseName(dataUser.getChineseName());
-                data.setUserName(dataUser.getUserName());
-                data.setId(dataUser.getId());
-                data.setIdentity(dataUser.getIdentity());
-                wrapper = ResponseWrapper.success("登陆成功", data);
-                wrapper.setToken(token);
+            if (StringUtil.isNotBlank(user.getMark())) {
+                AlarmUser dbUser = alarmUserService.singleLogin(user);      //单点登录
+                //单点登录
+                if (dbUser!=null) {
+                    String token = "";
+                    token = TokenUtil.createJwtToken(user.getUserName());
+                    AlarmUser data = new AlarmUser();
+                    data.setChineseName(dbUser.getChineseName());
+                    data.setUserName(dbUser.getUserName());
+                    data.setId(dbUser.getId());
+                    data.setIdentity(dbUser.getIdentity());
+
+                    wrapper = ResponseWrapper.success("登陆成功", data);
+                    wrapper.setToken(token);
+                } else {
+                    wrapper = ResponseWrapper.error("身份不合法");
+                }
             } else {
-                wrapper = ResponseWrapper.error("用户名或密码错误");
+
+                AlarmUser dataUser = alarmUserService.login(user);
+
+                if (dataUser != null) {
+                    String token = "";
+                    token = TokenUtil.createJwtToken(dataUser.getUserName());
+                    AlarmUser data = new AlarmUser();
+                    data.setChineseName(dataUser.getChineseName());
+                    data.setUserName(dataUser.getUserName());
+                    data.setId(dataUser.getId());
+                    data.setIdentity(dataUser.getIdentity());
+                    wrapper = ResponseWrapper.success("登陆成功", data);
+                    wrapper.setToken(token);
+                } else {
+                    wrapper = ResponseWrapper.error("用户名或密码错误");
+                }
             }
 
         } catch (Exception ex) {

+ 2 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/entity/AlarmUser.java

@@ -34,4 +34,6 @@ public class AlarmUser implements Serializable {
     private int enabled;
     @TableField("IDENTITY")
     private String identity;
+    @TableField(exist = false)
+    private  String mark;
 }

+ 23 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmUserService.java

@@ -58,6 +58,29 @@ public class AlarmUserService {
 
     }
 
+    //单点登录
+    public AlarmUser singleLogin(AlarmUser user) {
+
+        if (StringUtil.isBlank(user.getUserName()))
+            return null;
+        else {
+            String md5str = DigestUtils.md5Hex(user.getUserName() + "gyee_alarm");
+            if (md5str.equals(user.getMark())) {
+                String userName = user.getUserName();
+                List<AlarmUser> dbUserList = alarmUserMapper.getUserByUserName(userName);
+                if (dbUserList.size() > 0 ) {
+                    return dbUserList.get(0);
+                } else {
+                    return null;
+                }
+
+            } else {
+                return null;
+            }
+
+        }
+    }
+
     public AlarmUser login2(AlarmUser user) {