


HTTPS is the standard technology adopted on Internet to create a secure communication channel between web applications and their users.

In Wicket we can easily protect our pages with HTTPS mounting a special request mapper called _HttpsMapper_ and using annotation _RequireHttps_ with those pages we want to serve over this protocol. Both these two entities are in package _org.apache.wicket.protocol.https_.

_HttpsMapper_ wraps an existing mapper and redirects incoming requests to HTTPS if the related response must render a page annotated with _RequireHttps_. Most of the times the wrapped mapper will be the root one, just like we saw before for _CryptoMapper_ in <<urls.adoc#_generating_structured_and_clear_urls,paragraph 10.6>>.

Another parameter needed to build a _HttpsMapper_ is an instance of class _HttpsConfig_. This class allows us to specify which ports must be used for HTTPS and HTTP. By default the port numbers used by these two protocols are respectively 443 and 80.

The following code is taken from project _HttpsProtocolExample_ and illustrates how to enable HTTPS in our applications:

[source,java]
----
//Application class code...
@Override
public void init(){   
   setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), 
                                       new HttpsConfig(8080, 8443)));
}
----

Now we can use annotation _RequireHttps_ to specify which pages must be served using HTTPS:

[source,java]
----
@RequireHttps
public class HomePage extends WebPage {
    public HomePage(final PageParameters parameters) {
    	super(parameters);	
    }
}
----

If we want to protect many pages with HTTPS without adding annotation _RequireHttps_ to each of them, we can annotate a marker interface or a base page class and implement/extend it in any page we want to make secure:

[source,java]
----
// Marker interface:
@RequireHttps
public interface IMarker {
}

// Base class:
@RequireHttps
public class BaseClass extends WebPage {
//Page code...
}

// Secure page inheriting from BaseClass:
public class HttpsPage extends BaseClass {
//Page code...
}

// Secure page implementing IMarker:
public class HttpsPage implements IMarker {
//Page code...
}
----

