Example usage for org.apache.wicket Session error

List of usage examples for org.apache.wicket Session error

Introduction

In this page you can find the example usage for org.apache.wicket Session error.

Prototype

@Override
public final void error(final Serializable message) 

Source Link

Document

Registers an error feedback message for this session

Usage

From source file:fiftyfive.wicket.shiro.ShiroWicketPlugin.java

License:Apache License

/**
 * Invoked by {@code ShiroWicketPlugin} when the user has tried to access a page
 * but lacks the necessary role or permission. The default implementation places a
 * "sorry, you are not allowed to access that page" feedback message in the session.
 * To override or localize this message,
 * define {@code unauthorized} in your application properties. You can disable the
 * message entirely by defining {@code unauthorized} as an empty string.
 *///  ww  w .j  ava2s  .  c o m
public void onUnauthorized() {
    String message = getLocalizedMessage(UNAUTHORIZED_MESSAGE_KEY,
            "Sorry, you are not allowed to access that page.");

    if (message != null && !message.matches("^\\s*$")) {
        // We need a new session because otherwise our feedback message won't "stick".
        Session session = Session.get();
        session.bind();

        // Add localized "sorry, you are not allowed to access that page" message to session
        session.error(message);
    }
}