增加token拦截日志输出
This commit is contained in:
@ -76,6 +76,9 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
private Authentication getAuthentication(final String token, final String currentRoleCode) {
|
||||
SecurityUser securityUser = client.getUserInfo();
|
||||
|
||||
log.info("TokenAuthenticationFilter: token [{}]", token);
|
||||
log.info("TokenAuthenticationFilter: userid [{}]", securityUser.getUserId());
|
||||
|
||||
// 根据当前角色设定权限列表
|
||||
List<RoleCodeAuthority> authorities = Optional.ofNullable(securityUser.getAuthorityList()).map(list -> {
|
||||
return list.stream().filter(auth -> StringUtils.equals(auth.getRoleCode(), currentRoleCode))
|
||||
|
@ -33,7 +33,7 @@ public class BaseCacheUserServiceImpl implements IBaseCacheUserService {
|
||||
BeanUtils.copyProperties(SecurityContextHolder.getContext().getAuthentication().getPrincipal(), buser);
|
||||
|
||||
// if (Objects.isNull(buser.getUserId())) {
|
||||
// throw new InvalidTokenException("用户验证失败,无效的token!");
|
||||
// throw new AuthFailureException("登陆已超期");
|
||||
// }
|
||||
log.debug("Current user principal: " + buser);
|
||||
} catch (Exception e) {
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.chinaunicom.mall.ebtp.common.exception.entity;
|
||||
|
||||
/**
|
||||
* 无效的token
|
||||
*
|
||||
* @author Ajaxfan
|
||||
*/
|
||||
public class AuthFailureException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 7870600175887301004L;
|
||||
|
||||
public AuthFailureException() {
|
||||
}
|
||||
|
||||
public AuthFailureException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public AuthFailureException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public AuthFailureException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.chinaunicom.mall.ebtp.common.exception.entity;
|
||||
|
||||
/**
|
||||
* 无效的token
|
||||
*
|
||||
* @author Ajaxfan
|
||||
*/
|
||||
public class InvalidTokenException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 7870600175887301004L;
|
||||
|
||||
public InvalidTokenException() {
|
||||
}
|
||||
|
||||
public InvalidTokenException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidTokenException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidTokenException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.entity.BusinessException;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.entity.InvalidTokenException;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.entity.AuthFailureException;
|
||||
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
@ -138,15 +138,15 @@ public class BusinessExceptionHandlerAdviceDefault {
|
||||
* @param exception InvalidTokenException异常对象
|
||||
* @return 响应
|
||||
*/
|
||||
@ExceptionHandler(InvalidTokenException.class)
|
||||
@ExceptionHandler(AuthFailureException.class)
|
||||
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
||||
public BaseResponse<String> handleInvalidTokenException(HttpServletRequest request,
|
||||
InvalidTokenException exception) {
|
||||
AuthFailureException exception) {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("errors", exception.getMessage());
|
||||
body.put("error", HttpStatus.UNAUTHORIZED.getReasonPhrase());
|
||||
// body.put("path", request.getRequestURI());
|
||||
return BaseResponse.fail(HttpStatus.UNAUTHORIZED.value(), "用户验证失败,无效的token!", Convert.toStr(body));
|
||||
return BaseResponse.fail(HttpStatus.UNAUTHORIZED.value(), "登陆已超期", Convert.toStr(body));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
|
||||
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.entity.BusinessException;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.entity.InvalidTokenException;
|
||||
import com.chinaunicom.mall.ebtp.common.exception.entity.AuthFailureException;
|
||||
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
@ -154,15 +154,15 @@ public class BusinessExceptionHandlerAdvicePro {
|
||||
* @param exception InvalidTokenException异常对象
|
||||
* @return 响应
|
||||
*/
|
||||
@ExceptionHandler(InvalidTokenException.class)
|
||||
@ExceptionHandler(AuthFailureException.class)
|
||||
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
||||
public BaseResponse<String> handleInvalidTokenException(HttpServletRequest request,
|
||||
InvalidTokenException exception) {
|
||||
AuthFailureException exception) {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("errors", exception.getMessage());
|
||||
body.put("error", HttpStatus.UNAUTHORIZED.getReasonPhrase());
|
||||
// body.put("path", request.getRequestURI());
|
||||
return BaseResponse.fail(HttpStatus.UNAUTHORIZED.value(), "用户验证失败,无效的token!", Convert.toStr(body));
|
||||
return BaseResponse.fail(HttpStatus.UNAUTHORIZED.value(), "登陆已超期", Convert.toStr(body));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user