org.apache.wicket.protocol.https
Class HttpsMapper

java.lang.Object
  extended by org.apache.wicket.protocol.https.HttpsMapper
All Implemented Interfaces:
IRequestMapper

public class HttpsMapper
extends Object
implements IRequestMapper

A IRequestMapper that will issue a redirect to secured communication (over https) if the page resolved by delegate is annotated with @RequireHttps

To setup it:

 public class MyApplication extends WebApplication
 {
        public void init()
        {
                super.init();
 
                getRootRequestMapperAsCompound().add(new MountedMapper("secured", HttpsPage.class));
                mountPage(SomeOtherPage.class);
 
                // notice that in most cases this should be done as the
                // last mounting-related operation because it replaces the root mapper
                setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(80, 443)));
        }
 }
 
any request to http://hostname:httpPort/secured will be redirected to https://hostname:httpsPort/secured

Author:
igor

Nested Class Summary
static class HttpsMapper.RedirectHandler
          Handler that takes care of redirecting
 
Constructor Summary
HttpsMapper(IRequestMapper delegate, HttpsConfig config)
          Constructor
 
Method Summary
protected  IRequestHandler createRedirectHandler(String url)
          Creates the IRequestHandler that will be responsible for the redirect
protected  String createRedirectUrl(IRequestHandler handler, Request request, Scheme scheme)
          Construts a redirect url that should switch the user to the specified scheme
 int getCompatibilityScore(Request request)
          Returns the score representing how compatible this request mapper is to processing the given request.
 HttpsConfig getConfig()
           
protected  Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass)
          Determines which Scheme should be used to access the page
protected  Scheme getDesiredSchemeFor(IRequestHandler handler)
          Figures out which Scheme should be used to access the request handler
protected  Scheme getSchemeOf(Request request)
          Determines the Scheme of the request
 Url mapHandler(IRequestHandler handler)
          Returns the Url for given IRequestHandler or null if the request handler is not recognized.
 IRequestHandler mapRequest(Request request)
          Returns IRequestHandler for the request or null if the Url is not recognized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpsMapper

public HttpsMapper(IRequestMapper delegate,
                   HttpsConfig config)
Constructor

Parameters:
delegate -
config -
Method Detail

getCompatibilityScore

public final int getCompatibilityScore(Request request)
Description copied from interface: IRequestMapper
Returns the score representing how compatible this request mapper is to processing the given request. When a request comes in all mappers are scored and are tried in order from highest score to lowest.

A good criteria for calculating the score is the number of matched url segments. For example when there are two mappers for a mounted page, one mapped to /foo another to /foo/bar and the incoming request URL is /foo/bar/baz, the mapping to /foo/bar should probably handle the request first as it has matching segments count of 2 while the first one has only matching segments count of 1.

Note that the method can return value greater then zero even if the mapper does not recognize the request.

Specified by:
getCompatibilityScore in interface IRequestMapper
Returns:
the compatibility score, e.g. count of matching segments

mapRequest

public final IRequestHandler mapRequest(Request request)
Description copied from interface: IRequestMapper
Returns IRequestHandler for the request or null if the Url is not recognized.

Specified by:
mapRequest in interface IRequestMapper
Parameters:
request - provides access to request data (i.e. Url and Parameters)
Returns:
RequestHandler instance or null

mapHandler

public final Url mapHandler(IRequestHandler handler)
Description copied from interface: IRequestMapper
Returns the Url for given IRequestHandler or null if the request handler is not recognized.

Specified by:
mapHandler in interface IRequestMapper
Returns:
Url instance or null.

createRedirectHandler

protected IRequestHandler createRedirectHandler(String url)
Creates the IRequestHandler that will be responsible for the redirect

Parameters:
url -
Returns:
request handler

createRedirectUrl

protected String createRedirectUrl(IRequestHandler handler,
                                   Request request,
                                   Scheme scheme)
Construts a redirect url that should switch the user to the specified scheme

Parameters:
handler - request handler being accessed
request - current request
scheme - desired scheme for the redirect url
Returns:
url

getDesiredSchemeFor

protected Scheme getDesiredSchemeFor(IRequestHandler handler)
Figures out which Scheme should be used to access the request handler

Parameters:
handler - request handler
Returns:
Scheme

getSchemeOf

protected Scheme getSchemeOf(Request request)
Determines the Scheme of the request

Parameters:
request -
Returns:
Scheme.HTTPS or Scheme.HTTP

getDesiredSchemeFor

protected Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass)
Determines which Scheme should be used to access the page

Parameters:
pageClass - type of page
Returns:
Scheme

getConfig

public final HttpsConfig getConfig()
Returns:
config with which this mapper was created


Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.