mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added CustomExceptionHandler
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package com.cfive.pinnacle.config;
|
package com.cfive.pinnacle.config;
|
||||||
|
|
||||||
import com.cfive.pinnacle.filter.JwtAuthenticationTokenFilter;
|
import com.cfive.pinnacle.filter.JwtAuthenticationTokenFilter;
|
||||||
import com.cfive.pinnacle.handler.AccessDeniedHandler;
|
import com.cfive.pinnacle.handler.CustomAccessDeniedHandler;
|
||||||
import com.cfive.pinnacle.handler.AuthenticationEntryPointHandler;
|
import com.cfive.pinnacle.handler.CustomAuthenticationEntryPointHandler;
|
||||||
import com.cfive.pinnacle.service.permission.impl.UserDetailsServiceImpl;
|
import com.cfive.pinnacle.service.permission.impl.UserDetailsServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -25,8 +25,8 @@ import java.util.List;
|
|||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
private UserDetailsServiceImpl userDetailsService;
|
private UserDetailsServiceImpl userDetailsService;
|
||||||
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
|
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
|
||||||
private AuthenticationEntryPointHandler authenticationEntryPointHandler;
|
private CustomAuthenticationEntryPointHandler authenticationEntryPointHandler;
|
||||||
private AccessDeniedHandler accessDeniedHandler;
|
private CustomAccessDeniedHandler accessDeniedHandler;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setUserDetailsService(UserDetailsServiceImpl userDetailsService) {
|
public void setUserDetailsService(UserDetailsServiceImpl userDetailsService) {
|
||||||
@@ -39,12 +39,12 @@ public class SecurityConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setAuthenticationEntryPointHandler(AuthenticationEntryPointHandler authenticationEntryPointHandler) {
|
public void setAuthenticationEntryPointHandler(CustomAuthenticationEntryPointHandler authenticationEntryPointHandler) {
|
||||||
this.authenticationEntryPointHandler = authenticationEntryPointHandler;
|
this.authenticationEntryPointHandler = authenticationEntryPointHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler) {
|
public void setAccessDeniedHandler(CustomAccessDeniedHandler accessDeniedHandler) {
|
||||||
this.accessDeniedHandler = accessDeniedHandler;
|
this.accessDeniedHandler = accessDeniedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AccessDeniedHandler implements org.springframework.security.web.access.AccessDeniedHandler {
|
public class CustomAccessDeniedHandler implements org.springframework.security.web.access.AccessDeniedHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
|
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
|
||||||
String objectResponse = WebUtil.objectResponse(ResponseCode.ACCESS_DENIED, "Access denied", null);
|
String objectResponse = WebUtil.objectResponse(ResponseCode.ACCESS_DENIED, "Access denied", null);
|
||||||
@@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AuthenticationEntryPointHandler implements AuthenticationEntryPoint {
|
public class CustomAuthenticationEntryPointHandler implements AuthenticationEntryPoint {
|
||||||
@Override
|
@Override
|
||||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
|
||||||
String objectResponse;
|
String objectResponse;
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user