优化代码

pull/47/head
smallbun 2023-09-10 20:55:58 +08:00
parent 5dbd4cbc8e
commit ff5f883a52
2 changed files with 4 additions and 14 deletions

View File

@ -36,6 +36,7 @@ import cn.topiam.employee.support.context.ApplicationContextHelp;
import cn.topiam.employee.support.security.userdetails.UserDetails;
import cn.topiam.employee.support.security.userdetails.UserType;
import static cn.topiam.employee.core.security.util.SecurityUtils.getFailureMessage;
import static cn.topiam.employee.support.security.util.SecurityUtils.getPrincipal;
/**
*
@ -59,13 +60,7 @@ public class ConsoleAuthenticationFailureEventListener implements
AuditEventPublish publish = ApplicationContextHelp.getBean(AuditEventPublish.class);
String content = getFailureMessage(event);
logger.error("认证失败 [{}]",content);
String principal = (String) event.getAuthentication().getPrincipal();
if (event.getAuthentication().getPrincipal() instanceof String){
principal = (String) event.getAuthentication().getPrincipal();
}
if (event.getAuthentication().getPrincipal() instanceof UserDetails || event.getAuthentication().getPrincipal() instanceof org.springframework.security.core.userdetails.UserDetails){
principal = ((UserDetails) event.getAuthentication().getPrincipal()).getUsername();
}
String principal = getPrincipal(event);
if (StringUtils.isNotBlank(principal)){
Optional<AdministratorEntity> optional = getAdministratorRepository().findByUsername(principal);
if (optional.isEmpty()) {

View File

@ -43,6 +43,7 @@ import cn.topiam.employee.support.util.PhoneNumberUtils;
import static cn.topiam.employee.core.help.SettingHelp.getLoginFailureDuration;
import static cn.topiam.employee.core.security.util.SecurityUtils.getFailureMessage;
import static cn.topiam.employee.support.security.userdetails.UserType.USER;
import static cn.topiam.employee.support.security.util.SecurityUtils.getPrincipal;
/**
*
@ -67,13 +68,7 @@ public class PortalAuthenticationFailureEventListener implements
AuditEventPublish publish = ApplicationContextHelp.getBean(AuditEventPublish.class);
String content = getFailureMessage(event);
logger.error("认证失败", event.getException());
String principal = null;
if (event.getAuthentication().getPrincipal() instanceof String) {
principal = (String) event.getAuthentication().getPrincipal();
}
if (event.getAuthentication().getPrincipal() instanceof UserDetails || event.getAuthentication().getPrincipal() instanceof org.springframework.security.core.userdetails.UserDetails) {
principal = ((UserDetails) event.getAuthentication().getPrincipal()).getUsername();
}
String principal = getPrincipal(event);
if (StringUtils.isNotBlank(principal)) {
UserEntity user = getUserRepository().findByUsername(principal);
if (ObjectUtils.isEmpty(user)) {