正在显示
4 个修改的文件
包含
84 行增加
和
7 行删除
1 | +package com.tianbo.warehouse.annotation; | ||
2 | + | ||
3 | + | ||
4 | +import java.lang.annotation.*; | ||
5 | + | ||
6 | +/** | ||
7 | + * 将前端注册、新增、编辑后提交的明文密码MD5加密 | ||
8 | + * 使用该注解不用再MD5转换了 | ||
9 | + * | ||
10 | + * @author adonis | ||
11 | + * | ||
12 | + */ | ||
13 | +@Target({ElementType.PARAMETER,ElementType.METHOD}) | ||
14 | +@Retention(RetentionPolicy.RUNTIME) | ||
15 | +@Documented | ||
16 | +@Inherited | ||
17 | +public @interface UserPasswordSM3 { | ||
18 | + String value() default "password"; | ||
19 | + | ||
20 | +} |
1 | +package com.tianbo.warehouse.annotation; | ||
2 | + | ||
3 | +import com.tianbo.warehouse.model.USERS; | ||
4 | +import com.tianbo.warehouse.security.login.SM3EncryptUtil; | ||
5 | +import org.apache.commons.lang.StringUtils; | ||
6 | +import org.aspectj.lang.JoinPoint; | ||
7 | +import org.aspectj.lang.ProceedingJoinPoint; | ||
8 | +import org.aspectj.lang.annotation.*; | ||
9 | +import org.aspectj.lang.reflect.MethodSignature; | ||
10 | +import org.springframework.stereotype.Component; | ||
11 | + | ||
12 | +import java.lang.reflect.Method; | ||
13 | + | ||
14 | +@Aspect | ||
15 | +@Component | ||
16 | +public class UserPasswordSM3AOP { | ||
17 | + | ||
18 | + @Pointcut("@annotation(com.tianbo.warehouse.annotation.UserPasswordMd5)") | ||
19 | + public void annotationPointCut(){ | ||
20 | + | ||
21 | + } | ||
22 | + | ||
23 | + @Before("annotationPointCut()") | ||
24 | + public void before(JoinPoint joinPoint){ | ||
25 | + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
26 | + Method method= signature.getMethod(); | ||
27 | + UserPasswordSM3 annotation = method.getAnnotation(UserPasswordSM3.class); | ||
28 | + System.out.print("打印:"+annotation.value()+" SM3加密开始前"); | ||
29 | + } | ||
30 | + | ||
31 | + @Around("annotationPointCut()") | ||
32 | + public Object advice(ProceedingJoinPoint joinPoint){ | ||
33 | + System.out.println("SM3加密执行中"); | ||
34 | + Object[] args = joinPoint.getArgs(); | ||
35 | + if (args != null && args.length > 0 && args[0].getClass() == USERS.class) { | ||
36 | + USERS user = (USERS)args[0]; | ||
37 | + if (StringUtils.isNotEmpty(user.getPassword())){ | ||
38 | + user.setPassword(SM3EncryptUtil.passwordSm3(user.getPassword())); | ||
39 | + args[0] = user; | ||
40 | + } | ||
41 | + } | ||
42 | + Object retmsg=null; | ||
43 | + try { | ||
44 | + retmsg=joinPoint.proceed(args); | ||
45 | + System.err.println("++++++++"+retmsg); | ||
46 | + } catch (Throwable e) { | ||
47 | + e.printStackTrace(); | ||
48 | + } | ||
49 | + System.out.println("SM3加密执行结束"); | ||
50 | + return retmsg; | ||
51 | + } | ||
52 | + | ||
53 | + @After("annotationPointCut()") | ||
54 | + public void after(){ | ||
55 | + System.out.println("after方法SM3加密执行后"); | ||
56 | + } | ||
57 | + | ||
58 | +} |
@@ -2,6 +2,7 @@ package com.tianbo.warehouse.controller; | @@ -2,6 +2,7 @@ package com.tianbo.warehouse.controller; | ||
2 | 2 | ||
3 | import com.tianbo.warehouse.annotation.LogAnnotation; | 3 | import com.tianbo.warehouse.annotation.LogAnnotation; |
4 | import com.tianbo.warehouse.annotation.UserPasswordMd5; | 4 | import com.tianbo.warehouse.annotation.UserPasswordMd5; |
5 | +import com.tianbo.warehouse.annotation.UserPasswordSM3; | ||
5 | import com.tianbo.warehouse.controller.response.ResultJson; | 6 | import com.tianbo.warehouse.controller.response.ResultJson; |
6 | import com.tianbo.warehouse.model.USERS; | 7 | import com.tianbo.warehouse.model.USERS; |
7 | import com.tianbo.warehouse.service.UserService; | 8 | import com.tianbo.warehouse.service.UserService; |
@@ -31,7 +32,7 @@ public class AdminController { | @@ -31,7 +32,7 @@ public class AdminController { | ||
31 | @ApiOperation(value = "修改用户密码", notes = "超级管理修改其他用户密码") | 32 | @ApiOperation(value = "修改用户密码", notes = "超级管理修改其他用户密码") |
32 | @LogAnnotation(moduleName = "admin管理",operate = "用户密码修改") | 33 | @LogAnnotation(moduleName = "admin管理",operate = "用户密码修改") |
33 | @ApiImplicitParams({@ApiImplicitParam(name = "USERS", value = "用户账号密码", required = true, dataType = "USERS")}) | 34 | @ApiImplicitParams({@ApiImplicitParam(name = "USERS", value = "用户账号密码", required = true, dataType = "USERS")}) |
34 | - @UserPasswordMd5 | 35 | + @UserPasswordSM3 |
35 | @PutMapping("/password") | 36 | @PutMapping("/password") |
36 | public ResultJson updateUserPassById(@RequestBody USERS user){ | 37 | public ResultJson updateUserPassById(@RequestBody USERS user){ |
37 | int i = userService.updateByPrimaryKeySelective(user); | 38 | int i = userService.updateByPrimaryKeySelective(user); |
@@ -4,12 +4,11 @@ import com.alibaba.fastjson.JSON; | @@ -4,12 +4,11 @@ import com.alibaba.fastjson.JSON; | ||
4 | import com.github.pagehelper.PageInfo; | 4 | import com.github.pagehelper.PageInfo; |
5 | import com.tianbo.warehouse.annotation.LogAnnotation; | 5 | import com.tianbo.warehouse.annotation.LogAnnotation; |
6 | import com.tianbo.warehouse.annotation.RequestRequire; | 6 | import com.tianbo.warehouse.annotation.RequestRequire; |
7 | -import com.tianbo.warehouse.annotation.UserPasswordMd5; | 7 | +import com.tianbo.warehouse.annotation.UserPasswordSM3; |
8 | import com.tianbo.warehouse.controller.response.ResultJson; | 8 | import com.tianbo.warehouse.controller.response.ResultJson; |
9 | import com.tianbo.warehouse.model.USERS; | 9 | import com.tianbo.warehouse.model.USERS; |
10 | import com.tianbo.warehouse.model.UserRole; | 10 | import com.tianbo.warehouse.model.UserRole; |
11 | import com.tianbo.warehouse.security.CustomUserDetailService; | 11 | import com.tianbo.warehouse.security.CustomUserDetailService; |
12 | -import com.tianbo.warehouse.security.filter.JwtTokenUtil; | ||
13 | import com.tianbo.warehouse.service.UserService; | 12 | import com.tianbo.warehouse.service.UserService; |
14 | import com.tianbo.warehouse.service.validated.InsertUser; | 13 | import com.tianbo.warehouse.service.validated.InsertUser; |
15 | import com.tianbo.warehouse.service.validated.UpdateUser; | 14 | import com.tianbo.warehouse.service.validated.UpdateUser; |
@@ -28,7 +27,6 @@ import org.springframework.web.bind.annotation.*; | @@ -28,7 +27,6 @@ import org.springframework.web.bind.annotation.*; | ||
28 | 27 | ||
29 | import javax.servlet.http.HttpServletRequest; | 28 | import javax.servlet.http.HttpServletRequest; |
30 | import javax.servlet.http.HttpServletResponse; | 29 | import javax.servlet.http.HttpServletResponse; |
31 | -import javax.validation.Valid; | ||
32 | import java.util.List; | 30 | import java.util.List; |
33 | import java.util.Map; | 31 | import java.util.Map; |
34 | 32 | ||
@@ -71,7 +69,7 @@ public class UserController { | @@ -71,7 +69,7 @@ public class UserController { | ||
71 | UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | 69 | UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
72 | return userDetails.getUsername(); | 70 | return userDetails.getUsername(); |
73 | } | 71 | } |
74 | - @ApiOperation(value = "更新用户信息", notes = "跟新用户信息除了用户密码") | 72 | + @ApiOperation(value = "更新用户信息", notes = "更新用户信息除了用户密码") |
75 | @LogAnnotation(moduleName = "用户管理",operate = "用户编辑") | 73 | @LogAnnotation(moduleName = "用户管理",operate = "用户编辑") |
76 | @PutMapping("/edit") | 74 | @PutMapping("/edit") |
77 | public ResultJson updateUserById(@Validated(UpdateUser.class) @RequestBody USERS user){ | 75 | public ResultJson updateUserById(@Validated(UpdateUser.class) @RequestBody USERS user){ |
@@ -83,14 +81,14 @@ public class UserController { | @@ -83,14 +81,14 @@ public class UserController { | ||
83 | } | 81 | } |
84 | 82 | ||
85 | @LogAnnotation(moduleName = "用户管理",operate = "用户密码修改") | 83 | @LogAnnotation(moduleName = "用户管理",operate = "用户密码修改") |
86 | - @UserPasswordMd5 | 84 | + @UserPasswordSM3 |
87 | @PutMapping("/password") | 85 | @PutMapping("/password") |
88 | public ResultJson updateUserPassById(@RequestBody USERS user){ | 86 | public ResultJson updateUserPassById(@RequestBody USERS user){ |
89 | int i = userService.updateByPrimaryKeySelective(user); | 87 | int i = userService.updateByPrimaryKeySelective(user); |
90 | return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild"); | 88 | return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild"); |
91 | } | 89 | } |
92 | 90 | ||
93 | - @UserPasswordMd5 | 91 | + @UserPasswordSM3 |
94 | @LogAnnotation(moduleName = "用户管理",operate = "用户添加") | 92 | @LogAnnotation(moduleName = "用户管理",operate = "用户添加") |
95 | @PostMapping("/add") | 93 | @PostMapping("/add") |
96 | public ResultJson addUser(@RequestBody @Validated(InsertUser.class) USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){ | 94 | public ResultJson addUser(@RequestBody @Validated(InsertUser.class) USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){ |
-
请 注册 或 登录 后发表评论