Reply To: Appending query string in perform redirect

Splash Forums PrettyFaces Users Appending query string in perform redirect Reply To: Appending query string in perform redirect

#25306

Hey! Absolutely.

Here’s just a short example of how I’ve done something like this to capture the target URL for a user that is not logged in, but is trying to access restricted content:

.addRule()
.when(Path.matches("/account/{*}")
    .andNot(AuthenticationStatus.isLoggedIn(identity))
)
.perform(Redirect.temporary(context.getContextPath() + "/login?" +
    LoginController.RETURN_TO_PARAM + "={url}")
)
.where("url").bindsTo(requestedPath);

Where requestedPath is:

 ValueBinding requestedPath = new ValueBinding() {
      @Override
      public Object retrieve(Rewrite event, EvaluationContext context)
      {
         HttpServletRewrite rewrite = (HttpServletRewrite) event;
         String url = rewrite.getAddress().getPathAndQuery();
         if (url.startsWith(rewrite.getContextPath()))
            url = url.substring(rewrite.getContextPath().length());
         return url;
      }
   };

And ValueBinding is just a class I created to simplify the binding interface and make my configuration a bit smaller:

public abstract class ValueBinding implements Binding
{
   @Override
   public Object submit(Rewrite event, EvaluationContext context, Object value)
   {
      throw new UnsupportedOperationException(getClass().getName() + " does not support value submission.");
   }

   @Override
   public boolean supportsRetrieval()
   {
      return true;
   }

   @Override
   public boolean supportsSubmission()
   {
      return false;
   }
}