2016-04-18 19:10:32 +00:00
|
|
|
|
2019-01-21 16:15:22 +00:00
|
|
|
[[adapter_error_handling]]
|
2016-06-09 13:12:10 +00:00
|
|
|
==== Error Handling
|
2016-04-18 19:10:32 +00:00
|
|
|
|
2017-08-28 12:50:14 +00:00
|
|
|
{project_name} has some error handling facilities for servlet based client adapters.
|
|
|
|
When an error is encountered in authentication, {project_name} will call `HttpServletResponse.sendError()`.
|
2016-04-18 19:10:32 +00:00
|
|
|
You can set up an error-page within your `web.xml` file to handle the error however you want.
|
2017-08-28 12:50:14 +00:00
|
|
|
{project_name} can throw 400, 401, 403, and 500 errors.
|
2016-04-18 19:10:32 +00:00
|
|
|
|
2016-06-03 10:35:36 +00:00
|
|
|
[source,xml]
|
2016-04-18 19:10:32 +00:00
|
|
|
----
|
|
|
|
<error-page>
|
2017-03-24 16:47:12 +00:00
|
|
|
<error-code>403</error-code>
|
2016-04-18 19:10:32 +00:00
|
|
|
<location>/ErrorHandler</location>
|
|
|
|
</error-page>
|
|
|
|
----
|
|
|
|
|
2017-08-28 12:50:14 +00:00
|
|
|
{project_name} also sets a `HttpServletRequest` attribute that you can retrieve.
|
2016-06-09 12:16:55 +00:00
|
|
|
The attribute name is `org.keycloak.adapters.spi.AuthenticationError`, which should be casted to `org.keycloak.adapters.OIDCAuthenticationError`.
|
2016-04-18 19:10:32 +00:00
|
|
|
|
2016-06-03 10:35:36 +00:00
|
|
|
For example:
|
2016-04-18 19:10:32 +00:00
|
|
|
|
2016-06-03 10:35:36 +00:00
|
|
|
[source,java]
|
2016-04-18 19:10:32 +00:00
|
|
|
----
|
2016-06-03 10:35:36 +00:00
|
|
|
import org.keycloak.adapters.OIDCAuthenticationError;
|
|
|
|
import org.keycloak.adapters.OIDCAuthenticationError.Reason;
|
|
|
|
...
|
|
|
|
|
|
|
|
OIDCAuthenticationError error = (OIDCAuthenticationError) httpServletRequest
|
|
|
|
.getAttribute('org.keycloak.adapters.spi.AuthenticationError');
|
2016-04-18 19:10:32 +00:00
|
|
|
|
2016-06-03 10:35:36 +00:00
|
|
|
Reason reason = error.getReason();
|
|
|
|
System.out.println(reason.name());
|
2016-06-09 12:28:35 +00:00
|
|
|
----
|
2016-06-09 12:29:14 +00:00
|
|
|
|