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)
精彩评论