Package hirondelle.web4j.security

Examples of hirondelle.web4j.security.ApplicationFirewall

Example 2
A text input control named Age accepts any text as input. That text should correspond to an integer in the range 0..130. In this case, the validation is shared between hard validation and soft validation :

Hard validation - can only make a basic sanity check. For instance, a check that the parameter value is not an unreasonable size - under 5K, for instance. This is meant only to detect obvious hacks. It has nothing to do with business logic. That is, this size check does not correspond to the maximum number of characters expected (3), since failure of a hard validation produces a response which should not be seen by the typical user during normal operation of the program. In this case, the field declared in the {@link Action}is :

 public static final RequestParameter AGE = RequestParameter.withLengthCheck("Age"); 
(The actual maximum length is set in web.xml.)

Soft validation #1 - first, make sure the user input can be translated into an {@link Integer}. This is a very common task, and is implemented by {@link RequestParser}, using its various toXXX methods (and, at a higher lever, by {@link ModelFromRequest}). When user input cannot be parsed into an {@link Integer}, then an error message is displayed to the user. See {@link ConvertParamError}.

Soft validation #2 - make sure the {@link Integer} returned by the previous validation is in the range 0..150. This is an example of a typical business validation. These are usually implemented in the constructor of a Model Object. Again, if a problem is detected, then an error message is displayed to to the user.

{@link hirondelle.web4j.model.Check} and {@link hirondelle.web4j.model.Validator} are provided to help you implement soft validations.


    RequestParser requestParser = RequestParser.getInstance(aRequest, aResponse);
    try {
      LoginTasksHelper loginHelper = new LoginTasksHelper();
      loginHelper.reactToNewLogins(aRequest);
      Action action = requestParser.getWebAction();
      ApplicationFirewall appFirewall = BuildImpl.forApplicationFirewall();
      appFirewall.doHardValidation(action, requestParser);
      logAttributesForAllScopes(aRequest);
      ensureDatabasesOk();
      ResponsePage responsePage = checkOwnershipThenExecuteAction(action, requestParser);
      if ( responsePage.hasBinaryData() ) {
        fLogger.fine("Serving binary data. Controller not performing a forward or redirect.");
View Full Code Here

TOP

Related Classes of hirondelle.web4j.security.ApplicationFirewall

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.