tôi đã cùng một vấn đề ..., nhưng tôi không thích writting đang gắn với thùng vì những lý do rõ ràng .
Vì vậy, điều tôi đã làm là tự thêm ngoại lệ cho phiên đó.
Thứ nhất, xây dựng một người giữ ngoại lệ ThreadLocal để gửi ngoại lệ giữa LoginContext và ServletContext:
public final class SecurityThreadLocal {
private static final ThreadLocal<Exception> j_exception = new ThreadLocal<Exception>();
public static void setException(Exception e) {
j_exception.set(e);
}
public static Exception getException() {
return (Exception)j_exception.get();
}
public static void clear() {
j_exception.remove();
}
}
Thêm LoginException để SecurityThreadLocal:
catch (Exception e) { // or just catch LoginException
log.log(Level.SEVERE, e.getMessage(), e);
SecurityThreadLocal.setException(e);
}
Add Exception để HttpSession với Bộ lọc:
web.xml
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
SecurityFilter.java
if (uri.endsWith("<form-error-page>") && session != null){
Exception j_exception = SecurityThreadLocal.getException();
if(j_exception != null)
session.setAttribute("j_exception", j_exception);
}
Nhưng bạn nên biết như tôi biết điều này là một thói quen xấu và một vết nứt an ninh.
Vâng .., trong trường hợp của tôi, khách hàng đã giành được ...
Nguồn
2016-07-15 15:50:57