사용자 정의 'AuthenticationProvider'를 구현 중입니다. 인증되지 않은 경우 아래에 표시된대로 '인증'기능 내에 예외가 발생합니다.AuthenticationProvider에서 캐칭 예외가 throw 됨
public class DelegatingLdapAuthenticationProvider implements AuthenticationProvider {
private ActiveDirectoryLdapAuthenticationProvider primaryProvider;
private List<ActiveDirectoryLdapAuthenticationProvider> secondaryProviders = new ArrayList<>();
public DelegatingLdapAuthenticationProvider() {
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Authentication result = null;
AuthenticationException exception = null;
try {
result = primaryProvider.authenticate(authentication);
} catch (AuthenticationException e) {
exception = e;
for (ActiveDirectoryLdapAuthenticationProvider secondaryProvider : secondaryProviders) {
try {
result = secondaryProvider.authenticate(authentication);
if (result.isAuthenticated()) {
break;
}
} catch (AuthenticationException e1) {
exception = e;
}
}
}
if (result == null || !result.isAuthenticated()) {
throw exception;
}
return result;
}
다음과 같이 전역 예외 처리기가 있습니다.
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler({NoPermissionException.class})
@ResponseBody
@ResponseStatus(value = HttpStatus.FORBIDDEN)
public Map<String, String> noPermission(NoPermissionException e) {
return createErrorResponse(e, "Don't have permissions");
}
@ExceptionHandler({Exception.class})
@ResponseBody
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public Map<String, String> exceptionInProcessing(Exception e) {
return createErrorResponse(e, "Unable to process. Unknown error occurred: " + e.getMessage());
}
private Map<String, String> createErrorResponse(Exception e, String errorMessage) {
Map<String, String> errorResponse = new HashMap<>();
errorResponse.put("message", errorMessage);
errorResponse.put("reason", e.toString());
return errorResponse;
}
}
'authenticate'함수 내에 예외가 발생하면 전역 예외 처리기가 호출되지 않습니다. 다른 모든 예외의 경우 호출됩니다. 전역 예외 처리기에서 예외를 catch하고 사용자 지정 오류 메시지를 반환하고 싶습니다. 어떻게해야합니까? 어떤 도움을 주셔서 감사합니다. 미리 감사드립니다. 당신은 AuthenticationEntryPoint
을 구현하고 commence
메소드를 오버라이드 (override) 할을 처리 할 필요가,
실제로 예외가 발생했는지 또는 제공자가 처음에 호출되고 있는지 확인 했습니까? – pvg