Class CryptoMapper

java.lang.Object
org.apache.wicket.core.request.mapper.CryptoMapper
All Implemented Interfaces:
IRequestMapper, IRequestMapperDelegate

public class CryptoMapper extends Object implements IRequestMapperDelegate

A request mapper that encrypts URLs generated by another mapper. This mapper encrypts the segments and query parameters of URLs starting with IMapperContext.getNamespace(), and just the PageComponentInfo parameter for mounted URLs.

Important: for better security it is recommended to use CryptoMapper(IRequestMapper, Supplier) constructor with ICrypt implementation that generates a separate key for each user. KeyInSessionSunJceCryptFactory provides such an implementation that stores the key in the HTTP session.

This mapper can be mounted before or after mounting other pages, but will only encrypt URLs for pages mounted before the CryptoMapper. If required, multiple CryptoMappers may be installed in an Application.

When encrypting URLs in the Wicket namespace (starting with IMapperContext.getNamespace()), the entire URL, including segments and parameters, is encrypted, with the encrypted form stored in the first segment of the encrypted URL.

To be able to handle relative URLs, like for image URLs in a CSS file, checksum segments are appended to the encrypted URL until the encrypted URL has the same number of segments as the original URL had. Each checksum segment has a precise 5 character value, calculated using a checksum. This helps in calculating the relative distance from the original URL. When a URL is returned by the browser, we iterate through these checksummed placeholder URL segments. If the segment matches the expected checksum, then the segment is deemed to be the corresponding segment in the original URL. If the segment does not match the expected checksum, then the segment is deemed a plain text sibling of the corresponding segment in the original URL, and all subsequent segments are considered plain text children of the current segment.

When encrypting mounted URLs, we look for the PageComponentInfo parameter, and encrypt only that parameter.

CryptoMapper can be configured to mark encrypted URLs as encrypted, and throw a PageExpiredException exception if a encrypted URL cannot be decrypted. This can occur when using KeyInSessionSunJceCryptFactory, and the session has expired.

Author:
igor.vaynberg, Jesse Long, svenmeier
See Also: