Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01d29e6ec3 | ||
|
|
06b5258824 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.7</version>
|
<version>1.5.8</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>ZKH Framework</name>
|
<name>ZKH Framework</name>
|
||||||
<description>A Java framework for ZKH applications</description>
|
<description>A Java framework for ZKH applications</description>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.7</version>
|
<version>1.5.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-common</artifactId>
|
<artifactId>zkh-common</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.7</version>
|
<version>1.5.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-data</artifactId>
|
<artifactId>zkh-data</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.7</version>
|
<version>1.5.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-file</artifactId>
|
<artifactId>zkh-file</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.7</version>
|
<version>1.5.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-log</artifactId>
|
<artifactId>zkh-log</artifactId>
|
||||||
|
|||||||
+5
-1
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.7</version>
|
<version>1.5.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-web</artifactId>
|
<artifactId>zkh-web</artifactId>
|
||||||
@@ -23,6 +23,10 @@
|
|||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-log</artifactId>
|
<artifactId>zkh-log</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ public class GlobalExceptionHandler {
|
|||||||
* 处理 @RequestBody + @Valid 校验失败
|
* 处理 @RequestBody + @Valid 校验失败
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
||||||
public R<?> handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
|
public R<?> handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
|
||||||
log.error("接口入参校验失败", ex);
|
log.error("接口入参校验失败", ex);
|
||||||
BindingResult bindingResult = ex.getBindingResult();
|
BindingResult bindingResult = ex.getBindingResult();
|
||||||
@@ -82,7 +81,6 @@ public class GlobalExceptionHandler {
|
|||||||
* 处理 @RequestParam / @PathVariable 校验失败
|
* 处理 @RequestParam / @PathVariable 校验失败
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(ConstraintViolationException.class)
|
@ExceptionHandler(ConstraintViolationException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
||||||
public R<?> handleConstraintViolation(ConstraintViolationException ex) {
|
public R<?> handleConstraintViolation(ConstraintViolationException ex) {
|
||||||
log.error("接口入参校验失败", ex);
|
log.error("接口入参校验失败", ex);
|
||||||
String msg = ex.getConstraintViolations()
|
String msg = ex.getConstraintViolations()
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class WebSecurityConfig {
|
|||||||
config.requestMatchers(securityProps.getIgnoreUrls()).permitAll();
|
config.requestMatchers(securityProps.getIgnoreUrls()).permitAll();
|
||||||
config.anyRequest().authenticated();
|
config.anyRequest().authenticated();
|
||||||
});
|
});
|
||||||
CustomAuthenticationEntryPoint authenticationEntryPoint = new CustomAuthenticationEntryPoint(objectMapper, tokenRedisStorage);
|
CustomAuthenticationEntryPoint authenticationEntryPoint = new CustomAuthenticationEntryPoint(objectMapper, tokenRedisStorage, securityProps);
|
||||||
http.formLogin(config -> {
|
http.formLogin(config -> {
|
||||||
config.loginProcessingUrl("/login");
|
config.loginProcessingUrl("/login");
|
||||||
});
|
});
|
||||||
@@ -140,7 +140,8 @@ public class WebSecurityConfig {
|
|||||||
|
|
||||||
private record CustomAuthenticationEntryPoint(
|
private record CustomAuthenticationEntryPoint(
|
||||||
ObjectMapper objectMapper,
|
ObjectMapper objectMapper,
|
||||||
TokenRedisStorage tokenRedisStorage) implements AuthenticationEntryPoint, AuthenticationFailureHandler, AuthenticationSuccessHandler {
|
TokenRedisStorage tokenRedisStorage,
|
||||||
|
SecurityProps securityProps) implements AuthenticationEntryPoint, AuthenticationFailureHandler, AuthenticationSuccessHandler {
|
||||||
@Override
|
@Override
|
||||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
|
||||||
log.warn("访问 {} ,但是认证失败", request.getRequestURI(), authException);
|
log.warn("访问 {} ,但是认证失败", request.getRequestURI(), authException);
|
||||||
@@ -152,7 +153,7 @@ public class WebSecurityConfig {
|
|||||||
@Override
|
@Override
|
||||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
|
||||||
log.warn("登录失败", exception);
|
log.warn("登录失败", exception);
|
||||||
R<Object> data = new R<>(HttpServletResponse.SC_UNAUTHORIZED, "用户名或密码错误", false, null);
|
R<Object> data = new R<>(HttpServletResponse.SC_BAD_REQUEST, "用户名或密码错误", false, null);
|
||||||
response.setContentType("application/json;charset=UTF-8");
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
objectMapper.writeValue(response.getWriter(), data);
|
objectMapper.writeValue(response.getWriter(), data);
|
||||||
}
|
}
|
||||||
@@ -177,7 +178,7 @@ public class WebSecurityConfig {
|
|||||||
accessToken,
|
accessToken,
|
||||||
refreshToken,
|
refreshToken,
|
||||||
"Bearer",
|
"Bearer",
|
||||||
1800, // 30分钟,秒数
|
securityProps.getDuration().getSeconds(), // 30分钟,秒数
|
||||||
authentication.getName()
|
authentication.getName()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user