com.pingidentity.pa.sdk.policy
com.pingidentity.pa.sdk.policy.AccessExceptionContext
The nested Builder class has been removed from AccessExceptionContext and instead AccessExceptionContext is a builder that can be initially created with the new AccessExceptionContext#create method.
The LocalizedMessage interface has been introduced to simplify the configuration of a localized message for use in an error template. A LocalizedMessage has three implementations provided in the SDK: FixedMessage, BasicLocalizedMessage and ParameterizedLocalizedMessage. See the following code examples for more information on using these new classes.
Constructing an AccessExceptionContext
- Before PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus, Throwable cause) { return AccessExceptionContext.builder() .cause(cause) .httpStatus(httpStatus) .exceptionMessage(httpStatus.getMessage()) .errorDescription(httpStatus.getLocalizationKey()) .errorDescriptionIsKey(true) .errorDescriptionSubstitutions(new String[0]) .build(); }
- After PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus, Throwable cause) { return AccessExceptionContext.create(httpStatus) .cause(cause) .exceptionMessage(httpStatus.getMessage()) .errorDescription(httpStatus.getLocalizedMessage()); }
- Before PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus, String localizationKey, String[] substitutions) { return AccessExceptionContext.builder() .httpStatus(httpStatus) .errorDescription(localizationKey) .errorDescriptionIsKey(true) .errorDescriptionSubstitutions(substitutions) .build(); }
- After PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus, String localizationKey, String[] substitutions) { LocalizedMessage localizedMessage = new ParameterizedLocalizedMessage(localizationKey, substitutions); return AccessExceptionContext.create(httpStatus) .errorDescription(localizedMessage); }
- Before PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus, String localizationKey) { return AccessExceptionContext.builder() .httpStatus(httpStatus) .errorDescription(localizationKey) .errorDescriptionIsKey(true) .build(); }
- After PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus, String localizationKey) { LocalizedMessage localizedMessage = new BasicLocalizedMessage(localizationKey); return AccessExceptionContext.create(httpStatus) .errorDescription(localizedMessage); }
- Before PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus) { return AccessExceptionContext.builder() .from(httpStatus) .httpStatusDescription(httpStatus.getLocalizationKey()) .httpStatusDescriptionIsKey(true) .templateFile("template.html") .contentType("text/html"); }
- After PingAccess 5.0
-
private AccessExceptionContext createAccessExceptionContext(HttpStatus httpStatus) { return AccessExceptionContext.create(httpStatus) .errorDescription(httpStatus.getLocalizedMessage()); }
This example demonstrates that it is no longer possible to set a template file and its associated content type on an AccessExceptionContext. To generate an error response from a template file, use the TemplateRenderer class. See the Javadocs for the TemplateRenderer class for more information.
com.pingidentity.pa.sdk.policy.AccessException
The changes to AccessExceptionContext apply to the creation of AccessException because the creation of an AccessException requires an AccessExceptionContext.
In addition to these changes, obtaining information from AccessException has also changed. See the code examples below for more information.
Finally, AccessException no longer derives from IOException and derives directly from Exception instead.
Constructing an AccessException
- Before PingAccess 5.0
-
private void throwAccessException(String errorDescription, Throwable throwable) throws AccessException { throw new AccessException(errorDescription, throwable); }
- After PingAccess 5.0
-
private void throwAccessException(String errorDescription, Throwable throwable) throws AccessException { LocalizedMessage templateMessaage = new FixedMessage(errorDescription); throw new AccessException(AccessExceptionContext.create(HttpStatus.INTERNAL_SERVER_ERROR) .exceptionMessage(errorDescription) .cause(throwable) .errorDescription(templateMessaage)); }
- Before PingAccess 5.0
-
private void throwAccessException(String errorDescription) throws AccessException { throw new AccessException(errorDescription); }
- After PingAccess 5.0
-
private void throwAccessException(String errorDescription) throws AccessException { LocalizedMessage templateMessage = new FixedMessage(errorDescription); throw new AccessException(AccessExceptionContext.create(HttpStatus.INTERNAL_SERVER_ERROR) .exceptionMessage(errorDescription) .errorDescription(templateMessage)); }
- Before PingAccess 5.0
-
private void createAccessException(int statusCode, String statusMessage, String errorDescription) throws AccessException { throw new AccessException(statusCode, statusMessage, errorDescription); }
- After PingAccess 5.0
-
private void createAccessException(int statusCode, String statusMessage, String errorDescription) throws AccessException { HttpStatus httpStatus = new HttpStatus(statusCode, statusMessage); LocalizedMessage templateMessage = new FixedMessage(errorDescription); throw new AccessException(AccessExceptionContext.create(httpStatus) .exceptionMessage(errorDescription) .errorDescription(templateMessage)); }
- Before PingAccess 5.0
-
private void throwAccessException(int statusCode, String statusMessage, String errorDescription, Throwable throwable) throws AccessException { throw new AccessException(statusCode, statusMessage, errorDescription, throwable); }
- After PingAccess 5.0
-
private void throwAccessException(int statusCode, String statusMessage, String errorDescription, Throwable throwable) throws AccessException { HttpStatus httpStatus = new HttpStatus(statusCode, statusMessage); LocalizedMessage templateMessage = new FixedMessage(errorDescription); throw new AccessException(AccessExceptionContext.create(httpStatus) .exceptionMessage(errorDescription) .errorDescription(templateMessage) .cause(throwable)); }
- Before PingAccess 5.0
-
private void throwAccessException() throws AccessException { throw new AccessException(AccessExceptionContext.builder() .httpStatusCode(403) .httpStatusMessage("Forbidden") .build()); }
- After PingAccess 5.0
-
private void throwAccessException() throws AccessException { throw new AccessException(AccessExceptionContext.create(HttpStatus.FORBIDDEN)); }
Using the AccessException#getExceptionContext method
- Before PingAccess 5.0
-
AccessExceptionContext context = accessException.getExceptionContext();
- After PingAccess 5.0
-
This functionality is no longer supported. The information that used to be provided by the AccessExceptionContext is now provided directly by an AccessException.
Using the AccessException#getHttpStatusCode method
- Before PingAccess 5.0
-
int statusCode = accessException.getHttpStatusCode();
- After PingAccess 5.0
-
int statusCode = accessException.getErrorStatus().getCode();
Using the AccessException#getHttpStatusMessage method
- Before PingAccess 5.0
-
String statusMessage = accessException.getHttpStatusMessage();
- After PingAccess 5.0
-
String statusMessage = accessException.getErrorStatus().getMessage();
com.pingidentity.pa.sdk.policy.RuleInterceptor
The handleRequest and handleResponse methods on a RuleInterceptor no longer throw an IOException. Instead, they throw an AccessException, which no longer derives from IOException.
Accounting for the RuleInterceptor#handleRequest method signature change
- Before PingAccess 5.0
-
@Override public Outcome handleRequest(Exchange exchange) throws IOException { Outcome outcome = applyPolicy(exchange); return outcome; }
- After PingAccess 5.0
-
@Override public Outcome handleRequest(Exchange exchange) throws AccessException { Outcome outcome = applyPolicy(exchange); return outcome; }
Account for the RuleInterceptor#handleResponse method signature change
- Before PingAccess 5.0
-
@Override public void handleResponse(Exchange exchange) throws IOException { applyPolicyToResponse(exchange.getResponse()); }
- After PingAccess 5.0
-
@Override public void handleResponse(Exchange exchange) throws AccessException { applyPolicyToResponse(exchange.getResponse()); }