开发者

Access SPRING_SECURITY_LAST_EXCEPTION from Wicket

I want to create a Wicket panel as a replacement for the default (and not so beautiful) Spring Security Lo开发者_如何转开发gin page. The form itself is not a big thing, because it's just HTML, but I also want to view Login errors.

I saw many JSP snippets containing ${SPRING_SECURITY_LAST_EXCEPTION} for viewing authentication errors, but how can I access this parameter from Wicket?


Accessing this exception from WicketPanel, for example:

import org.apache.wicket.markup.html.panel.Panel;

public class LogInMenuPanel extends Panel {

    @Override
    protected void onBeforeRender() {
        super.onBeforeRender();

        HttpSession session = ((ServletWebRequest)this.getRequest()).getHttpServletRequest().getSession();
        Throwable exception = (Throwable) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

        //do something with exception
    }

}


While I have never tried it, I think this should be the way:

EDIT: I fixed the bug now

    Request request = RequestCycle.get().getRequest();
    Object lastException = WebUtils.getSessionAttribute(
        ((ServletWebRequest) request).getHttpServletRequest(),
        WebAttributes.AUTHENTICATION_EXCEPTION
    );

See

  • WebAttributes (Spring, Javadoc)
  • WebUtils (Spring, JavaDoc)
  • Constant Field Values: AUTHENTICATION_EXCEPTION (Spring, JavaDoc)
  • RequestCycle (Wicket, JavaDoc)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜