You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

How to obfuscate/encrypt a wicket url

From time to time users ask how to obfuscate wicket urls. Instead of myApp?component=1&version=0&interface=IRedirectListener they asked for myApp?sdf897sD879ddfD8... and myApp/sdf897sD879ddfD8 and I can think of many many more. And because of varying requirements like being Google and/or cluster compliant we decided to provide "hooks" build into the core to allow for virtually any obfuscating alogrithm to be implemented by wicket users. Hopefully users will contribute their implementations back to the project.

Classes involved in encrypting and decrypting URLs are WebResponse and WebRequest. The default implementations provided by Wicket don't encrypt the URL at all, but subclasses (currently provided by core as well) like WebResponseWithCryptedUrl and WebRequestWithCryptedUrl do. In order for your application to use them you must subclass WebApplication.newWebRequest() and WebApplication.newWebResponse() like in the snippet shown below.

public final class SignIn2Application extends WicketExampleApplication
{
....
	/**
	 * @see wicket.protocol.http.WebApplication#newWebRequest(javax.servlet.http.HttpServletRequest)
	 */
	protected WebRequest newWebRequest(HttpServletRequest servletRequest)
	{
		return new WebRequestWithCryptedUrl(servletRequest);
	}
	
	/**
	 * @see wicket.protocol.http.WebApplication#newWebResponse(javax.servlet.http.HttpServletResponse)
	 */
	protected WebResponse newWebResponse(HttpServletResponse servletResponse) throws IOException
	{
		return new WebResponseWithCryptedUrl(servletResponse);
	}
}

Since Wicket 1.2 use insatead:

public final class SignIn2Application extends WicketExampleApplication
{
....
{panel}
 protected IRequestCycleProcessor newRequestCycleProcessor()
 {
 	return new CompoundRequestCycleProcessor(new CryptedUrlWebRequestCodingStrategy(
 			new WebRequestCodingStrategy()), null, null, null, null);
 }
{panel}
}
  • No labels