mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
feat:jwt续期实现
This commit is contained in:
parent
ff4ef4285b
commit
f163298472
@ -1,12 +1,9 @@
|
|||||||
package com.youlai.auth.exception;
|
package com.youlai.auth.exception;
|
||||||
|
|
||||||
import com.youlai.common.core.result.Result;
|
import com.youlai.common.core.result.Result;
|
||||||
import com.youlai.common.core.result.ResultCode;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
||||||
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
|
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
|
||||||
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
@ -14,18 +11,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class AuthExceptionHandler {
|
public class AuthExceptionHandler {
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端信息错误
|
|
||||||
*
|
|
||||||
* @param e
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(UsernameNotFoundException.class)
|
|
||||||
public Result handleUsernameNotFoundException(UsernameNotFoundException e) {
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名和密码异常
|
* 用户名和密码异常
|
||||||
*
|
*
|
||||||
@ -49,14 +34,4 @@ public class AuthExceptionHandler {
|
|||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ExceptionHandler(InvalidTokenException.class)
|
|
||||||
public Result handleInvalidTokenException(InvalidTokenException e) {
|
|
||||||
return Result.custom(ResultCode.TOKEN_INVALID_OR_EXPIRED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
|
||||||
public Result handleException(Exception e) {
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ public class ResourceServerConfig {
|
|||||||
return (exchange, e) -> {
|
return (exchange, e) -> {
|
||||||
Mono<Void> mono = Mono.defer(() -> Mono.just(exchange.getResponse()))
|
Mono<Void> mono = Mono.defer(() -> Mono.just(exchange.getResponse()))
|
||||||
.flatMap(response -> {
|
.flatMap(response -> {
|
||||||
response.setStatusCode(HttpStatus.UNAUTHORIZED);
|
response.setStatusCode(HttpStatus.OK);
|
||||||
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||||
response.getHeaders().set("Access-Control-Allow-Origin", "*");
|
response.getHeaders().set("Access-Control-Allow-Origin", "*");
|
||||||
response.getHeaders().set("Cache-Control", "no-cache");
|
response.getHeaders().set("Cache-Control", "no-cache");
|
||||||
|
Loading…
Reference in New Issue
Block a user