Commit 434ce2ce authored by 向怀芳's avatar 向怀芳 🎱

1. 新增账号锁定功能

parent f8249b11
...@@ -15,6 +15,4 @@ spring: ...@@ -15,6 +15,4 @@ spring:
config: config:
namespace: be9383c3-e535-4e9c-81ab-a8c6b7ecdc82 namespace: be9383c3-e535-4e9c-81ab-a8c6b7ecdc82
file-extension: yml file-extension: yml
shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
shared-configs: \ No newline at end of file
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
...@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.SpringSecurityMessageSource; import org.springframework.security.core.SpringSecurityMessageSource;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.validation.FieldError; import org.springframework.validation.FieldError;
...@@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; ...@@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.security.auth.login.AccountLockedException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -77,6 +79,28 @@ public class GlobalExceptionHandlerResolver { ...@@ -77,6 +79,28 @@ public class GlobalExceptionHandlerResolver {
return objectR; return objectR;
} }
@ExceptionHandler({BadCredentialsException.class})
@ResponseStatus(HttpStatus.OK)
public R handleBadCredentialsException(BadCredentialsException exception) {
R<Object> objectR = R.builder()
.code(Constant.BYTE_NO)
.msg(exception.getMessage())
.build();
return objectR;
}
@ExceptionHandler({AccountLockedException.class})
@ResponseStatus(HttpStatus.OK)
public R handleBAccountLockedException(AccountLockedException exception) {
R<Object> objectR = R.builder()
.code(Constant.BYTE_NO)
.msg(exception.getMessage())
.build();
return objectR;
}
/** /**
* AccessDeniedException * AccessDeniedException
* *
......
package cn.sh.stc.sict.cloud.common.security.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
//security中文提示信息配置类
@Configuration
public class ReloadMessageConfig {
@Bean //加载中文认证提示信息
public ReloadableResourceBundleMessageSource messageSource(){
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
//加载org/springframework/security包下的中文提示信息 配置文件
messageSource.setBasename("classpath:security/messages_zh_CN");
return messageSource;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment