修改方法
authorTang Cheng <cheng.tang@supwisdom.com>
Wed, 26 Jun 2019 07:40:21 +0000 (15:40 +0800)
committerTang Cheng <cheng.tang@supwisdom.com>
Wed, 26 Jun 2019 07:40:25 +0000 (15:40 +0800)
src/main/kotlin/com/supwisdom/dlpay/security.kt

index 3b7ce49..7762e9f 100644 (file)
@@ -1,6 +1,5 @@
 package com.supwisdom.dlpay
 
-import com.supwisdom.dlpay.api.bean.JsonResult
 import com.supwisdom.dlpay.framework.core.JwtConfig
 import com.supwisdom.dlpay.framework.core.JwtTokenUtil
 import com.supwisdom.dlpay.framework.core.PasswordBCryptConfig
@@ -35,7 +34,6 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority
 import org.springframework.security.core.context.SecurityContextHolder
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
 import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore
-import org.springframework.security.web.authentication.AuthenticationFailureHandler
 import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
 import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl
 import org.springframework.security.web.util.matcher.AntPathRequestMatcher
@@ -134,12 +132,12 @@ class ApiJwtAuthenticationFilter : OncePerRequestFilter() {
                     // jwt 过期后返回 401
                     apiJwtRepository.deleteById(e.jwtContext.jwtClaims.jwtId)
                 }
-                response.setStatus(HttpStatus.UNAUTHORIZED.value(), e.message)
+                response.sendError(HttpStatus.UNAUTHORIZED.value(), e.message)
                 return
             } catch (e: JoseException) {
                 SecurityContextHolder.clearContext()
                 // jwt 失效后返回 401
-                response.setStatus(HttpStatus.UNAUTHORIZED.value(), e.message)
+                response.sendError(HttpStatus.UNAUTHORIZED.value(), e.message)
                 response.contentType = "application/json;charset=UTF-8"
                 return
             }