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,6 +2,6 @@ FROM redis:6.2 | ||
| 2 | MAINTAINER guzijian | 2 | MAINTAINER guzijian |
| 3 | EXPOSE 6379 | 3 | EXPOSE 6379 |
| 4 | # 设置Redis快照 | 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 | CMD ["redis-server", "/etc/redis/redis.conf"] | 7 | CMD ["redis-server", "/etc/redis/redis.conf"] |
| 8 | \ No newline at end of file | 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,6 +3,12 @@ package com.ruoyi.web.controller.system; | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | import java.util.stream.Collectors; | 4 | import java.util.stream.Collectors; |
| 5 | import javax.servlet.http.HttpServletResponse; | 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 | import org.apache.commons.lang3.ArrayUtils; | 12 | import org.apache.commons.lang3.ArrayUtils; |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.security.access.prepost.PreAuthorize; | 14 | import org.springframework.security.access.prepost.PreAuthorize; |
| @@ -39,12 +45,19 @@ import com.ruoyi.system.service.ISysUserService; | @@ -39,12 +45,19 @@ import com.ruoyi.system.service.ISysUserService; | ||
| 39 | */ | 45 | */ |
| 40 | @RestController | 46 | @RestController |
| 41 | @RequestMapping("/system/user") | 47 | @RequestMapping("/system/user") |
| 48 | +@Api(tags = "用户信息") | ||
| 42 | public class SysUserController extends BaseController | 49 | public class SysUserController extends BaseController |
| 43 | { | 50 | { |
| 44 | @Autowired | 51 | @Autowired |
| 45 | private ISysUserService userService; | 52 | private ISysUserService userService; |
| 46 | 53 | ||
| 47 | @Autowired | 54 | @Autowired |
| 55 | + private TokenService tokenService; | ||
| 56 | + | ||
| 57 | + @Autowired | ||
| 58 | + private SysPermissionService permissionService; | ||
| 59 | + | ||
| 60 | + @Autowired | ||
| 48 | private ISysRoleService roleService; | 61 | private ISysRoleService roleService; |
| 49 | 62 | ||
| 50 | @Autowired | 63 | @Autowired |
| @@ -122,6 +135,7 @@ public class SysUserController extends BaseController | @@ -122,6 +135,7 @@ public class SysUserController extends BaseController | ||
| 122 | @PreAuthorize("@ss.hasPermi('system:user:add')") | 135 | @PreAuthorize("@ss.hasPermi('system:user:add')") |
| 123 | @Log(title = "用户管理", businessType = BusinessType.INSERT) | 136 | @Log(title = "用户管理", businessType = BusinessType.INSERT) |
| 124 | @PostMapping | 137 | @PostMapping |
| 138 | + @ApiOperation("新增用户") | ||
| 125 | public AjaxResult add(@Validated @RequestBody SysUser user) | 139 | public AjaxResult add(@Validated @RequestBody SysUser user) |
| 126 | { | 140 | { |
| 127 | if (!userService.checkUserNameUnique(user)) | 141 | if (!userService.checkUserNameUnique(user)) |
| @@ -138,6 +152,9 @@ public class SysUserController extends BaseController | @@ -138,6 +152,9 @@ public class SysUserController extends BaseController | ||
| 138 | } | 152 | } |
| 139 | user.setCreateBy(getUsername()); | 153 | user.setCreateBy(getUsername()); |
| 140 | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); | 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 | return toAjax(userService.insertUser(user)); | 158 | return toAjax(userService.insertUser(user)); |
| 142 | } | 159 | } |
| 143 | 160 | ||
| @@ -173,6 +190,7 @@ public class SysUserController extends BaseController | @@ -173,6 +190,7 @@ public class SysUserController extends BaseController | ||
| 173 | @PreAuthorize("@ss.hasPermi('system:user:remove')") | 190 | @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| 174 | @Log(title = "用户管理", businessType = BusinessType.DELETE) | 191 | @Log(title = "用户管理", businessType = BusinessType.DELETE) |
| 175 | @DeleteMapping("/{userIds}") | 192 | @DeleteMapping("/{userIds}") |
| 193 | + @ApiOperation("删除用户") | ||
| 176 | public AjaxResult remove(@PathVariable Long[] userIds) | 194 | public AjaxResult remove(@PathVariable Long[] userIds) |
| 177 | { | 195 | { |
| 178 | if (ArrayUtils.contains(userIds, getUserId())) | 196 | if (ArrayUtils.contains(userIds, getUserId())) |
| @@ -188,6 +206,7 @@ public class SysUserController extends BaseController | @@ -188,6 +206,7 @@ public class SysUserController extends BaseController | ||
| 188 | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") | 206 | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| 189 | @Log(title = "用户管理", businessType = BusinessType.UPDATE) | 207 | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| 190 | @PutMapping("/resetPwd") | 208 | @PutMapping("/resetPwd") |
| 209 | + @ApiOperation("重置密码") | ||
| 191 | public AjaxResult resetPwd(@RequestBody SysUser user) | 210 | public AjaxResult resetPwd(@RequestBody SysUser user) |
| 192 | { | 211 | { |
| 193 | userService.checkUserAllowed(user); | 212 | userService.checkUserAllowed(user); |
| @@ -203,6 +222,7 @@ public class SysUserController extends BaseController | @@ -203,6 +222,7 @@ public class SysUserController extends BaseController | ||
| 203 | @PreAuthorize("@ss.hasPermi('system:user:edit')") | 222 | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| 204 | @Log(title = "用户管理", businessType = BusinessType.UPDATE) | 223 | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| 205 | @PutMapping("/changeStatus") | 224 | @PutMapping("/changeStatus") |
| 225 | + @ApiOperation("状态修改") | ||
| 206 | public AjaxResult changeStatus(@RequestBody SysUser user) | 226 | public AjaxResult changeStatus(@RequestBody SysUser user) |
| 207 | { | 227 | { |
| 208 | userService.checkUserAllowed(user); | 228 | userService.checkUserAllowed(user); |
| @@ -216,6 +236,7 @@ public class SysUserController extends BaseController | @@ -216,6 +236,7 @@ public class SysUserController extends BaseController | ||
| 216 | */ | 236 | */ |
| 217 | @PreAuthorize("@ss.hasPermi('system:user:query')") | 237 | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| 218 | @GetMapping("/authRole/{userId}") | 238 | @GetMapping("/authRole/{userId}") |
| 239 | + @ApiOperation("根据用户编号获取授权角色") | ||
| 219 | public AjaxResult authRole(@PathVariable("userId") Long userId) | 240 | public AjaxResult authRole(@PathVariable("userId") Long userId) |
| 220 | { | 241 | { |
| 221 | AjaxResult ajax = AjaxResult.success(); | 242 | AjaxResult ajax = AjaxResult.success(); |
| @@ -232,6 +253,7 @@ public class SysUserController extends BaseController | @@ -232,6 +253,7 @@ public class SysUserController extends BaseController | ||
| 232 | @PreAuthorize("@ss.hasPermi('system:user:edit')") | 253 | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| 233 | @Log(title = "用户管理", businessType = BusinessType.GRANT) | 254 | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| 234 | @PutMapping("/authRole") | 255 | @PutMapping("/authRole") |
| 256 | + @ApiOperation("用户授权角色") | ||
| 235 | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) | 257 | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) |
| 236 | { | 258 | { |
| 237 | userService.checkUserDataScope(userId); | 259 | userService.checkUserDataScope(userId); |
| @@ -244,6 +266,7 @@ public class SysUserController extends BaseController | @@ -244,6 +266,7 @@ public class SysUserController extends BaseController | ||
| 244 | */ | 266 | */ |
| 245 | @PreAuthorize("@ss.hasPermi('system:user:list')") | 267 | @PreAuthorize("@ss.hasPermi('system:user:list')") |
| 246 | @GetMapping("/deptTree") | 268 | @GetMapping("/deptTree") |
| 269 | + @ApiOperation("获取部门树列表") | ||
| 247 | public AjaxResult deptTree(SysDept dept) | 270 | public AjaxResult deptTree(SysDept dept) |
| 248 | { | 271 | { |
| 249 | return success(deptService.selectDeptTreeList(dept)); | 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,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 111 | // 过滤请求 | 111 | // 过滤请求 |
| 112 | .authorizeRequests() | 112 | .authorizeRequests() |
| 113 | // 对于登录login 注册register 验证码captchaImage 允许匿名访问 | 113 | // 对于登录login 注册register 验证码captchaImage 允许匿名访问 |
| 114 | - .antMatchers("/login", "/register", "/captchaImage").permitAll() | 114 | + .antMatchers("/ceshi/**","/login", "/register", "/captchaImage").permitAll() |
| 115 | // 静态资源,可匿名访问 | 115 | // 静态资源,可匿名访问 |
| 116 | .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() | 116 | .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() |
| 117 | .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() | 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,8 +96,13 @@ public class SysLoginService | ||
| 96 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); | 96 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| 97 | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); | 97 | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
| 98 | recordLoginInfo(loginUser.getUserId()); | 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 | /** |