chore: 修改 pointcut 通过 securitycontextholder 取出用户
authorTang Cheng <cheng.tang@supwisdom.com>
Wed, 19 Jun 2019 07:06:22 +0000 (15:06 +0800)
committerTang Cheng <cheng.tang@supwisdom.com>
Wed, 19 Jun 2019 07:06:22 +0000 (15:06 +0800)
src/main/kotlin/com/supwisdom/dlpay/api/advices.kt

index 0f9f314..092fde8 100644 (file)
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.beans.factory.annotation.Value
 import org.springframework.http.ResponseEntity
 import org.springframework.security.core.Authentication
+import org.springframework.security.core.context.SecurityContextHolder
 import org.springframework.stereotype.Component
 import org.springframework.web.bind.annotation.ExceptionHandler
 import org.springframework.web.bind.annotation.RestControllerAdvice
@@ -63,13 +64,16 @@ class RestControllerAspect {
     fun postmapping() {
     }
 
-    @Around("restcontroller() && postmapping() && args(@RequestBody body, auth, ..)")
+    @Around("restcontroller() && postmapping() && args(@RequestBody body, ..)")
     @Throws(Throwable::class)
-    fun logPostMethods(joinPoint: ProceedingJoinPoint, body: Any, auth: Authentication): Any {
+    fun logPostMethods(joinPoint: ProceedingJoinPoint, body: Any): Any {
         return try {
             if (body is APIRequestParam) {
                 body.checkParam()
-                if (requestSignCheck && !body.checkSign(commonService.getSecretByAppid(auth.name))) {
+
+                if (requestSignCheck &&
+                        !body.checkSign(commonService.getSecretByAppid(
+                                SecurityContextHolder.getContext().authentication.name))) {
                     throw RequestParamCheckException(TradeErrorCode.REQUEST_SIGN_ERROR, "参数签名错误")
                 }
             } else {