hlf 1 år sedan
förälder
incheckning
c7099d530d

+ 4 - 5
src/main/java/com/gyee/table/controller/ComponentInformationController.java

@@ -6,7 +6,6 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.gyee.table.entity.ComponentModificationRecord;
 import com.gyee.table.entity.Configurationinfo;
-import com.gyee.table.jwt.annotation.PassToken;
 import com.gyee.table.result.Result;
 import com.gyee.table.service.IComponentModificationRecordService;
 import com.gyee.table.service.IConfigurationinfoService;
@@ -42,7 +41,7 @@ public class ComponentInformationController {
      * @return
      */
     @PostMapping("/componentList")
-    @PassToken
+    //@PassToken
     public TableDataInfo componentList(@RequestBody Configurationinfo configurationinfo) {
         PageHelper.startPage(configurationinfo.getPageNumber(), configurationinfo.getPageSize(), true);
         List<Configurationinfo> list = configurationinfoService.selectConfigurationinfoList(configurationinfo);
@@ -56,7 +55,7 @@ public class ComponentInformationController {
      * @return
      */
     @PostMapping("/addComponent")
-    @PassToken
+    //@PassToken
     public JSONObject addComponent(@RequestBody Configurationinfo configurationinfo) {
         configurationinfo.setId(Long.toString(IdUtil.getSnowflake(1, 1).nextId()));
         configurationinfoService.save(configurationinfo);
@@ -70,7 +69,7 @@ public class ComponentInformationController {
      * @return
      */
     @PostMapping("/updateComponent")
-    @PassToken
+    //@PassToken
     public JSONObject updateComponent(@RequestBody Configurationinfo configurationinfo) {
         configurationinfoService.updateById(configurationinfo);
         ComponentModificationRecord componentModificationRecord = new ComponentModificationRecord();
@@ -88,7 +87,7 @@ public class ComponentInformationController {
      * @return
      */
     @DeleteMapping("/deleteComponent/{id}")
-    @PassToken
+    //@PassToken
     public JSONObject deleteComponent(@PathVariable String id) {
         configurationinfoService.removeById(id);
         return Result.success();

+ 3 - 2
src/main/java/com/gyee/table/controller/LoginController.java

@@ -8,6 +8,7 @@ import com.gyee.table.service.ISysUserService;
 import com.gyee.table.utils.StringUtil;
 import com.gyee.table.vo.AjaxResult;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -33,10 +34,10 @@ public class LoginController {
      * @param password 密码
      * @return
      */
-    @PostMapping("/toLogin")
+    @PostMapping("/toLogin/{username}/{password}")
     @ResponseBody
     @UserLoginToken
-    public AjaxResult jwtLogin(String username, String password) {
+    public AjaxResult jwtLogin(@PathVariable String username, @PathVariable String password) {
         if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
             return AjaxResult.error("账号和密码不能为空!");
         }

+ 4 - 7
src/main/java/com/gyee/table/controller/SysUserController.java

@@ -2,7 +2,6 @@ package com.gyee.table.controller;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.gyee.table.entity.SysUser;
-import com.gyee.table.jwt.annotation.PassToken;
 import com.gyee.table.result.Result;
 import com.gyee.table.result.ResultCode;
 import com.gyee.table.service.ISysUserService;
@@ -32,7 +31,7 @@ public class SysUserController {
      * @return
      */
     @GetMapping("/getUserList")
-    @PassToken
+    //@PassToken
     public JSONObject getUserList() {
         List<SysUser> list = userService.list();
         return Result.successData(ResultCode.SUCCESS, list);
@@ -46,11 +45,9 @@ public class SysUserController {
      * @param newPassword      新密码
      * @return
      */
-    @PostMapping("/changePassword")
-    @PassToken
-    public JSONObject changePassword(@RequestParam(value = "id") String id,
-                                     @RequestParam(value = "originalPassword") String originalPassword,
-                                     @RequestParam(value = "newPassword") String newPassword) {
+    @PostMapping("/changePassword/{id}/{originalPassword}/{newPassword}")
+    //@PassToken
+    public JSONObject changePassword(@PathVariable String id, @PathVariable String originalPassword, @PathVariable String newPassword) {
         SysUser user = userService.getById(id);
         if (!originalPassword.equals(user.getPassword())) {
             return Result.error();

+ 3 - 3
src/main/java/com/gyee/table/jwt/config/InterceptorConfig.java

@@ -1,6 +1,6 @@
 package com.gyee.table.jwt.config;
 
-import com.gyee.table.jwt.interceptor.AuthenticationInterceptor;
+import com.gyee.table.jwt.filter.JwtFilter;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
@@ -16,8 +16,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 public class InterceptorConfig implements WebMvcConfigurer {
 
     @Bean
-    public AuthenticationInterceptor authenticationInterceptor() {
-        return new AuthenticationInterceptor();
+    public JwtFilter authenticationInterceptor() {
+        return new JwtFilter();
     }
 
     // 这个方法用来注册拦截器,我们自己写好的拦截器需要通过这里添加注册才能生效

+ 6 - 5
src/main/java/com/gyee/table/jwt/interceptor/AuthenticationInterceptor.java

@@ -1,6 +1,7 @@
-package com.gyee.table.jwt.interceptor;
+package com.gyee.table.jwt.filter;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.auth0.jwt.exceptions.JWTDecodeException;
 import com.gyee.table.entity.SysUser;
 import com.gyee.table.jwt.annotation.PassToken;
@@ -19,9 +20,9 @@ import java.lang.reflect.Method;
 /**
  * @author hlf
  * @date 2023/4/1 16:26
- * 文件说明:拦截器
+ * 文件说明:jwt 自定义拦截器
  */
-public class AuthenticationInterceptor implements HandlerInterceptor {
+public class JwtFilter implements HandlerInterceptor {
 
     @Autowired
     private ISysUserService userService;
@@ -51,8 +52,8 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
             PassToken passToken = method.getDeclaredAnnotation(PassToken.class);
             if (passToken.required()) {
                 // 执行认证
-                if (token == null) {
-                    throw new RuntimeException("无token,请重新登录!");
+                if (StrUtil.isEmpty(token)) {
+                    throw new RuntimeException("消息头不正确,header需要携带token参数");
                 }
                 // 获取token中的username
                 String username;

+ 4 - 1
src/main/java/com/gyee/table/jwt/utils/JwtUtils.java

@@ -16,7 +16,10 @@ import java.util.Date;
  * @author hlf
  */
 public class JwtUtils {
-    private static final long EXPIRE_TIME = 3 * 120 * 60 * 1000;
+
+    //2小时
+    //private static final long EXPIRE_TIME = 120 * 60 * 1000;
+    private static final long EXPIRE_TIME = 3 * 100 * 1000;
 
     private static final String CLAIM_NAME = "username";
 

+ 1 - 21
src/main/resources/mappers/Configurationinfo.xml

@@ -2,27 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.gyee.table.mapper.ConfigurationinfoMapper">
 
-    <resultMap type="Configurationinfo" id="ConfigurationinfoResult">
-        <id     property="id"             column="id"                  />
-        <result property="name"           column="name"                />
-        <result property="needBg"         column="need_bg"             />
-        <result property="needColor"      column="need_color"          />
-        <result property="needLw"         column="need_lw"             />
-        <result property="needMap"        column="need_map"            />
-        <result property="needMapDone"    column="need_map_done"       />
-        <result property="otherDesc"      column="other_desc"          />
-        <result property="otherNeed"      column="other_need"          />
-        <result property="stateDesc"      column="state_desc"          />
-        <result property="svg"            column="svg"                 />
-        <result property="trSvg"          column="tr_svg"              />
-        <result property="type"           column="type"                />
-        <result property="uploadDate"     column="upload_date"         />
-        <result property="uploadUser"     column="upload_user"         />
-        <result property="updataDate"     column="updata_date"         />
-        <result property="changeUser"     column="change_user"         />
-    </resultMap>
-
-    <select id="selectConfigurationinfoList" parameterType="Configurationinfo" resultMap="ConfigurationinfoResult">
+    <select id="selectConfigurationinfoList" resultType="com.gyee.table.entity.Configurationinfo">
         select
         c.*,
         u1.user_name as "uploadUserStr",