浏览代码

bug fixes

PLF 5 年之前
父节点
当前提交
1eafb5a3d6

+ 2 - 1
src/main/java/com/caimei/modules/shiro/auth/AuthRealm.java

@@ -62,8 +62,9 @@ public class AuthRealm extends AuthorizingRealm {
         if (user == null) {
             throw new UnknownAccountException("用户不存在!");
         }
+        String infos = TokenEncryptUtils.encoded(tokens[0] + "#,#" + user.getId() + "#,#" + user.getPassword());
         //5. 根据用户的情况, 来构建 AuthenticationInfo 对象并返回. 通常使用的实现类为: SimpleAuthenticationInfo
-        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, accessToken, this.getName());
+        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, infos, this.getName());
         return info;
     }
 }

+ 3 - 2
src/main/java/com/caimei/modules/shiro/controller/ShiroController.java

@@ -4,6 +4,7 @@ package com.caimei.modules.shiro.controller;
 import com.caimei.modules.shiro.entity.CmMallAdminUser;
 import com.caimei.modules.shiro.service.ShiroService;
 import com.caimei.utils.JsonModel;
+import com.caimei.utils.MD5Util;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,12 +23,12 @@ public class ShiroController {
      * 登录
      */
     @GetMapping("/login")
-    public JsonModel login(String account, String password, Integer organizeID) {
+    public JsonModel login(String account, String password, Integer organizeID) throws Exception {
         JsonModel jsonModel = JsonModel.newInstance();
         //用户信息
         CmMallAdminUser user = shiroService.findByUsername(account, organizeID);
         //账号不存在、密码错误
-        if (user == null || !user.getPassword().equals(password)) {
+        if (user == null || !user.getPassword().equals(MD5Util.MD5(password))) {
             return jsonModel.error("账号或密码有误");
         } else {
             //生成token

+ 0 - 12
src/main/java/com/caimei/modules/shiro/dao/SysTokenRepository.java

@@ -1,12 +0,0 @@
-package com.caimei.modules.shiro.dao;
-
-
-import com.caimei.modules.shiro.entity.SysToken;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-public interface SysTokenRepository {
-    SysToken findByToken(String accessToken);
-
-    SysToken findByUserId(Integer userId);
-}

+ 0 - 2
src/main/java/com/caimei/modules/shiro/entity/Permission.java

@@ -1,8 +1,6 @@
 package com.caimei.modules.shiro.entity;
 
-
 public class Permission {
-
     private Integer permissionId;
     private String permissionName;
     private String permission;

+ 0 - 2
src/main/java/com/caimei/modules/shiro/entity/Role.java

@@ -1,10 +1,8 @@
 package com.caimei.modules.shiro.entity;
 
-
 import java.util.Set;
 
 public class Role {
-
     private Integer roleId;
     private String roleName;
     private Set<Permission> permissions;

+ 0 - 60
src/main/java/com/caimei/modules/shiro/entity/SysToken.java

@@ -1,60 +0,0 @@
-package com.caimei.modules.shiro.entity;
-
-import java.io.Serializable;
-import java.util.Date;
-
-
-public class SysToken implements Serializable {
-
-    /**
-     * 用户ID
-     */
-    private Integer userId;
-
-    /**
-     * token
-     */
-    private String token;
-
-    /**
-     * 过期时间
-     */
-    private Date expireTime;
-
-    /**
-     * 更新时间
-     */
-    private Date updateTime;
-
-    public Integer getUserId() {
-        return userId;
-    }
-
-    public void setUserId(Integer userId) {
-        this.userId = userId;
-    }
-
-    public String getToken() {
-        return token;
-    }
-
-    public void setToken(String token) {
-        this.token = token;
-    }
-
-    public Date getExpireTime() {
-        return expireTime;
-    }
-
-    public void setExpireTime(Date expireTime) {
-        this.expireTime = expireTime;
-    }
-
-    public Date getUpdateTime() {
-        return updateTime;
-    }
-
-    public void setUpdateTime(Date updateTime) {
-        this.updateTime = updateTime;
-    }
-}

+ 1 - 6
src/main/java/com/caimei/modules/shiro/service/impl/ShiroServiceImpl.java

@@ -1,7 +1,5 @@
 package com.caimei.modules.shiro.service.impl;
 
-
-import com.caimei.modules.shiro.dao.SysTokenRepository;
 import com.caimei.modules.shiro.dao.UserMapper;
 import com.caimei.modules.shiro.entity.CmMallAdminUser;
 import com.caimei.modules.shiro.service.ShiroService;
@@ -14,8 +12,6 @@ import org.springframework.stereotype.Service;
 public class ShiroServiceImpl implements ShiroService {
     @Autowired
     private UserMapper userMapper;
-    @Autowired
-    private SysTokenRepository sysTokenRepository;
 
     /**
      * 根据account查找用户
@@ -33,8 +29,7 @@ public class ShiroServiceImpl implements ShiroService {
     public String createToken(CmMallAdminUser user) throws Exception {
         // 获取当前时间戳(10位整数)
         int time = (int) (System.currentTimeMillis() / 1000 + 3600);
-        String password = MD5Util.MD5(user.getPassword());
-        String token = TokenEncryptUtils.encoded(time + "#,#" + user.getId() + "#,#" + password);
+        String token = TokenEncryptUtils.encoded(time + "#,#" + user.getId() + "#,#" + user.getPassword());
         return token;
     }