1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 06:51:23 +08:00

Added CustomExceptionHandler

This commit is contained in:
2023-05-12 20:57:09 +08:00
parent 8fdc026604
commit 00240706ad
4 changed files with 21 additions and 8 deletions

View File

@@ -1,8 +1,8 @@
package com.cfive.pinnacle.config;
import com.cfive.pinnacle.filter.JwtAuthenticationTokenFilter;
import com.cfive.pinnacle.handler.AccessDeniedHandler;
import com.cfive.pinnacle.handler.AuthenticationEntryPointHandler;
import com.cfive.pinnacle.handler.CustomAccessDeniedHandler;
import com.cfive.pinnacle.handler.CustomAuthenticationEntryPointHandler;
import com.cfive.pinnacle.service.permission.impl.UserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -25,8 +25,8 @@ import java.util.List;
public class SecurityConfig {
private UserDetailsServiceImpl userDetailsService;
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
private AuthenticationEntryPointHandler authenticationEntryPointHandler;
private AccessDeniedHandler accessDeniedHandler;
private CustomAuthenticationEntryPointHandler authenticationEntryPointHandler;
private CustomAccessDeniedHandler accessDeniedHandler;
@Autowired
public void setUserDetailsService(UserDetailsServiceImpl userDetailsService) {
@@ -39,12 +39,12 @@ public class SecurityConfig {
}
@Autowired
public void setAuthenticationEntryPointHandler(AuthenticationEntryPointHandler authenticationEntryPointHandler) {
public void setAuthenticationEntryPointHandler(CustomAuthenticationEntryPointHandler authenticationEntryPointHandler) {
this.authenticationEntryPointHandler = authenticationEntryPointHandler;
}
@Autowired
public void setAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler) {
public void setAccessDeniedHandler(CustomAccessDeniedHandler accessDeniedHandler) {
this.accessDeniedHandler = accessDeniedHandler;
}

View File

@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
@Component
public class AccessDeniedHandler implements org.springframework.security.web.access.AccessDeniedHandler {
public class CustomAccessDeniedHandler implements org.springframework.security.web.access.AccessDeniedHandler {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
String objectResponse = WebUtil.objectResponse(ResponseCode.ACCESS_DENIED, "Access denied", null);

View File

@@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
@Component
public class AuthenticationEntryPointHandler implements AuthenticationEntryPoint {
public class CustomAuthenticationEntryPointHandler implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
String objectResponse;

View File

@@ -0,0 +1,13 @@
package com.cfive.pinnacle.handler;
import com.cfive.pinnacle.entity.common.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class CustomExceptionHandler {
@ExceptionHandler(value = Exception.class)
public ResponseResult exceptionHandler(Exception e) {
return ResponseResult.fail(e.getClass().toString() + ": " + e.getMessage());
}
}