I am working on a project where I have to include some code from a JSP. This JSP has code as follows (related to Spring Security) ...
<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt' %>
<%@ page import="org.springframework.security.ui.AbstractProcessingFilter" %>
<%@ page import="org.springframework.security.ui.webapp.AuthenticationProcessingFilter" %>
<%@ page import="org.springframework.security.AuthenticationException" %>
....
<c:if test="${not empty param.login_error}">
<font color="red">
Your login attempt was not successful, try again.<br/><br/>
Reason: <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.
</font>
</c:if>
....
<c:if test="${not empty param.login_error}"><c:out value="${SPRING_SECURITY_LAST_USERNAME}"/></c:if>
...
This is what I tried to check in my servlet:
enumr = request.getAttributeNames();
while(enumr.hasMoreElements())
{
String element = enumr.nextElement()+"";
out.print("<h3>Read an element:");
out.print(element+" » ");
out.print(request.getAttribute(element));
out.print("</h3>");
}
and the corresponding output:
Read an element:__spring_security_session_fixation_filter_applied » true
Read an element:__spring_security开发者_StackOverflow社区_filterSecurityInterceptor_filterApplied » true
Read an element:hibernateFilter.FILTERED » true
Read an element:__spring_security_session_integration_filter_applied » true
Read an element:requestContextFilter.FILTERED » true
An educated guess is that I can conclude an error on reading, _spring_security_filterSecurityInterceptor_filterApplied, depicts that an error has occured.
How do I get to read the error message?
First of all: you aren't using Facelets. You are using JSP. Those two are both independent view technologies from Sun, wherein Facelets is less or more seen as JSP on steroids. So this topic is incorrectly tagged with Facelets.
Second of all: the HTML <font> tag is deprecated since HTML 4.01 in 1998. You should be using CSS.
Back to your problem: I don't do Spring, so I can't go depth in detail, but have you checked the session scoped attribtues? Quickly Googling the key "SPRING_SECURITY_LAST_EXCEPTION.message" learns me that it is stored in the session scope.
It works:
String keyToSearch = AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY;
Object value = request.getSession().getAttribute(keyToSearch);
thanks once again BalusC
精彩评论