Working with spring security 6 + opaque token I am receiving, always, 401 when some exception happens during authentication process. Even when authorisation/authentication server is down I am getting 401.
I would like to return 500 internal server error when I can not touch the authentication server, most likely it will be a timeout exception I suppose, since I have configured a timeout configured.
@PostConstruct
public void init() {
RestOperations restOperations = new RestTemplateBuilder()
.basicAuthentication(clientId, clientSecret)
.setConnectTimeout(Duration.ofSeconds(connectionTimeout))
.setReadTimeout(Duration.ofSeconds(readTimeout))
.build();
delegate = new NimbusOpaqueTokenIntrospector(introspectionUrl, restOperations);
}
Also, I realize that when 401 and 403 happens, there is no message. Would be nice to have it either. How to handle exception properly to at least return 500 when server authentication is down.
Thank's