⚡ 优化 #1337 社交登录用户凭证已过期

This commit is contained in:
lengleng committed 2020-06-04 12:24:39 +08:00
1 parent d90a021659
commit a5437968b9
2 files changed
+14 -3

No files matched your search

+1 -1
View File
@@ -229,7 +229,7 @@ CREATE TABLE `sys_log` (
`type` char(1) DEFAULT '0',
`title` varchar(255) DEFAULT NULL,
`service_id` varchar(32) DEFAULT NULL,
`create_by` varchar(64) DEFAULT NULL,
`create_by` varchar(255) DEFAULT NULL,
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`remote_addr` varchar(255) DEFAULT NULL,
@@ -25,8 +25,10 @@ import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.CredentialsExpiredException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.SpringSecurityMessageSource;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
@@ -53,13 +55,22 @@ public class ResourceAuthExceptionEntryPoint implements AuthenticationEntryPoint
response.setCharacterEncoding(CommonConstants.UTF8);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
R<String> result = new R<>();
result.setMsg(authException.getMessage());
result.setData(authException.getMessage());
result.setCode(CommonConstants.FAIL);
if (authException != null) {
if (authException instanceof CredentialsExpiredException) {
String msg = SpringSecurityMessageSource.getAccessor().getMessage(
"AbstractUserDetailsAuthenticationProvider.credentialsExpired", authException.getMessage());
result.setMsg(msg);
result.setData(authException.getMessage());
}
if (authException instanceof UsernameNotFoundException) {
String msg = SpringSecurityMessageSource.getAccessor().getMessage(
"AbstractUserDetailsAuthenticationProvider.noopBindAccount", authException.getMessage());
result.setMsg(msg);
}
response.setStatus(HttpStatus.HTTP_UNAUTHORIZED);
PrintWriter printWriter = response.getWriter();
printWriter.append(objectMapper.writeValueAsString(result));