Commit af404a8bb6e1880b03dd822b9040c0616c508b9a
1 parent
01108aa1
fix: update token expire Time to never expire time
Showing
5 changed files
with
74 additions
and
4 deletions
redis-dockerfile
| ... | ... | @@ -2,6 +2,6 @@ FROM redis:6.2 |
| 2 | 2 | MAINTAINER guzijian |
| 3 | 3 | EXPOSE 6379 |
| 4 | 4 | # 设置Redis快照 |
| 5 | -RUN sed -i 's/^# save ""/save 900 1\nsave 300 10\nsave 60 10000/g' /etc/redis/redis.conf | |
| 5 | +# RUN sed -i 's/^# save ""/save 900 1\nsave 300 10\nsave 60 10000/g' /etc/redis/redis.conf | |
| 6 | 6 | # 确保启动时使用容器内的配置 |
| 7 | 7 | CMD ["redis-server", "/etc/redis/redis.conf"] |
| 8 | 8 | \ No newline at end of file | ... | ... |
ruoyi-admin/src/main/java/com/ruoyi/test/GetAdminTOken.java
0 → 100644
| 1 | +package com.ruoyi.test; | |
| 2 | + | |
| 3 | +import com.ruoyi.common.core.domain.entity.SysUser; | |
| 4 | +import com.ruoyi.common.core.domain.model.LoginUser; | |
| 5 | +import com.ruoyi.framework.web.service.SysPermissionService; | |
| 6 | +import com.ruoyi.framework.web.service.TokenService; | |
| 7 | +import com.ruoyi.system.mapper.SysUserMapper; | |
| 8 | +import com.ruoyi.system.service.ISysUserService; | |
| 9 | +import io.swagger.annotations.Api; | |
| 10 | +import io.swagger.annotations.ApiOperation; | |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | +import org.springframework.web.bind.annotation.RestController; | |
| 15 | + | |
| 16 | +@RestController | |
| 17 | +@RequestMapping("/ceshi") | |
| 18 | +@Api(tags = "测试接口") | |
| 19 | +public class GetAdminTOken { | |
| 20 | + | |
| 21 | + @Autowired | |
| 22 | + private ISysUserService userService; | |
| 23 | + | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + private TokenService tokenService; | |
| 27 | + | |
| 28 | + @Autowired | |
| 29 | + private SysPermissionService permissionService; | |
| 30 | + | |
| 31 | + | |
| 32 | + @GetMapping("/getToken") | |
| 33 | + @ApiOperation("创建永久token") | |
| 34 | + public String getToken(Long userId){ | |
| 35 | + SysUser user = userService.selectUserById(userId); | |
| 36 | + LoginUser loginUser = new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); | |
| 37 | + // 每个用户分配一个固定token | |
| 38 | + user.setRemark(tokenService.createToken(loginUser)); | |
| 39 | + userService.updateUser(user); | |
| 40 | + return user.getRemark(); | |
| 41 | + } | |
| 42 | +} | ... | ... |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
| ... | ... | @@ -3,6 +3,12 @@ package com.ruoyi.web.controller.system; |
| 3 | 3 | import java.util.List; |
| 4 | 4 | import java.util.stream.Collectors; |
| 5 | 5 | import javax.servlet.http.HttpServletResponse; |
| 6 | + | |
| 7 | +import com.ruoyi.common.core.domain.model.LoginUser; | |
| 8 | +import com.ruoyi.framework.web.service.SysPermissionService; | |
| 9 | +import com.ruoyi.framework.web.service.TokenService; | |
| 10 | +import io.swagger.annotations.Api; | |
| 11 | +import io.swagger.annotations.ApiOperation; | |
| 6 | 12 | import org.apache.commons.lang3.ArrayUtils; |
| 7 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | 14 | import org.springframework.security.access.prepost.PreAuthorize; |
| ... | ... | @@ -39,12 +45,19 @@ import com.ruoyi.system.service.ISysUserService; |
| 39 | 45 | */ |
| 40 | 46 | @RestController |
| 41 | 47 | @RequestMapping("/system/user") |
| 48 | +@Api(tags = "用户信息") | |
| 42 | 49 | public class SysUserController extends BaseController |
| 43 | 50 | { |
| 44 | 51 | @Autowired |
| 45 | 52 | private ISysUserService userService; |
| 46 | 53 | |
| 47 | 54 | @Autowired |
| 55 | + private TokenService tokenService; | |
| 56 | + | |
| 57 | + @Autowired | |
| 58 | + private SysPermissionService permissionService; | |
| 59 | + | |
| 60 | + @Autowired | |
| 48 | 61 | private ISysRoleService roleService; |
| 49 | 62 | |
| 50 | 63 | @Autowired |
| ... | ... | @@ -122,6 +135,7 @@ public class SysUserController extends BaseController |
| 122 | 135 | @PreAuthorize("@ss.hasPermi('system:user:add')") |
| 123 | 136 | @Log(title = "用户管理", businessType = BusinessType.INSERT) |
| 124 | 137 | @PostMapping |
| 138 | + @ApiOperation("新增用户") | |
| 125 | 139 | public AjaxResult add(@Validated @RequestBody SysUser user) |
| 126 | 140 | { |
| 127 | 141 | if (!userService.checkUserNameUnique(user)) |
| ... | ... | @@ -138,6 +152,9 @@ public class SysUserController extends BaseController |
| 138 | 152 | } |
| 139 | 153 | user.setCreateBy(getUsername()); |
| 140 | 154 | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| 155 | + LoginUser loginUser = new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); | |
| 156 | + // 每个用户分配一个固定token | |
| 157 | + user.setRemark(tokenService.createToken(loginUser)); | |
| 141 | 158 | return toAjax(userService.insertUser(user)); |
| 142 | 159 | } |
| 143 | 160 | |
| ... | ... | @@ -173,6 +190,7 @@ public class SysUserController extends BaseController |
| 173 | 190 | @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| 174 | 191 | @Log(title = "用户管理", businessType = BusinessType.DELETE) |
| 175 | 192 | @DeleteMapping("/{userIds}") |
| 193 | + @ApiOperation("删除用户") | |
| 176 | 194 | public AjaxResult remove(@PathVariable Long[] userIds) |
| 177 | 195 | { |
| 178 | 196 | if (ArrayUtils.contains(userIds, getUserId())) |
| ... | ... | @@ -188,6 +206,7 @@ public class SysUserController extends BaseController |
| 188 | 206 | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| 189 | 207 | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| 190 | 208 | @PutMapping("/resetPwd") |
| 209 | + @ApiOperation("重置密码") | |
| 191 | 210 | public AjaxResult resetPwd(@RequestBody SysUser user) |
| 192 | 211 | { |
| 193 | 212 | userService.checkUserAllowed(user); |
| ... | ... | @@ -203,6 +222,7 @@ public class SysUserController extends BaseController |
| 203 | 222 | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| 204 | 223 | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| 205 | 224 | @PutMapping("/changeStatus") |
| 225 | + @ApiOperation("状态修改") | |
| 206 | 226 | public AjaxResult changeStatus(@RequestBody SysUser user) |
| 207 | 227 | { |
| 208 | 228 | userService.checkUserAllowed(user); |
| ... | ... | @@ -216,6 +236,7 @@ public class SysUserController extends BaseController |
| 216 | 236 | */ |
| 217 | 237 | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| 218 | 238 | @GetMapping("/authRole/{userId}") |
| 239 | + @ApiOperation("根据用户编号获取授权角色") | |
| 219 | 240 | public AjaxResult authRole(@PathVariable("userId") Long userId) |
| 220 | 241 | { |
| 221 | 242 | AjaxResult ajax = AjaxResult.success(); |
| ... | ... | @@ -232,6 +253,7 @@ public class SysUserController extends BaseController |
| 232 | 253 | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| 233 | 254 | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| 234 | 255 | @PutMapping("/authRole") |
| 256 | + @ApiOperation("用户授权角色") | |
| 235 | 257 | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) |
| 236 | 258 | { |
| 237 | 259 | userService.checkUserDataScope(userId); |
| ... | ... | @@ -244,6 +266,7 @@ public class SysUserController extends BaseController |
| 244 | 266 | */ |
| 245 | 267 | @PreAuthorize("@ss.hasPermi('system:user:list')") |
| 246 | 268 | @GetMapping("/deptTree") |
| 269 | + @ApiOperation("获取部门树列表") | |
| 247 | 270 | public AjaxResult deptTree(SysDept dept) |
| 248 | 271 | { |
| 249 | 272 | return success(deptService.selectDeptTreeList(dept)); | ... | ... |
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
| ... | ... | @@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter |
| 111 | 111 | // 过滤请求 |
| 112 | 112 | .authorizeRequests() |
| 113 | 113 | // 对于登录login 注册register 验证码captchaImage 允许匿名访问 |
| 114 | - .antMatchers("/login", "/register", "/captchaImage").permitAll() | |
| 114 | + .antMatchers("/ceshi/**","/login", "/register", "/captchaImage").permitAll() | |
| 115 | 115 | // 静态资源,可匿名访问 |
| 116 | 116 | .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() |
| 117 | 117 | .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() | ... | ... |
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
| ... | ... | @@ -96,8 +96,13 @@ public class SysLoginService |
| 96 | 96 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| 97 | 97 | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
| 98 | 98 | recordLoginInfo(loginUser.getUserId()); |
| 99 | - // 生成token | |
| 100 | - return tokenService.createToken(loginUser); | |
| 99 | + // 返回数据库中token | |
| 100 | + return getUserToken(loginUser.getUserId()); | |
| 101 | + } | |
| 102 | + | |
| 103 | + private String getUserToken(Long userId) { | |
| 104 | + SysUser sysUser = userService.selectUserById(userId); | |
| 105 | + return sysUser.getRemark(); | |
| 101 | 106 | } |
| 102 | 107 | |
| 103 | 108 | /** | ... | ... |