[英]JBoss JAAS custom Login Module Error messages
我有一個應用程序,它使用了JBoss的自定義登錄模塊 。 身份驗證可能由於各種原因而失敗,我必須向用戶顯示這些,而不是通常的Inavlid username / password
錯誤。
有沒有辦法從登錄消息中獲取錯誤消息? 我認為最好的方法是通過異常,因為authenticate返回一個布爾值,但我無法確定如何在身份驗證后捕獲它。 任何指針都歡迎。
使用了閥門org.jboss.web.tomcat.security.ExtendedFormAuthenticator
並從會話中獲取了j_exception
。
參考:
您可以使用數據庫登錄模塊,然后使用
例外e =(例外)SecurityContextAssociation.getContextInfo(“org.jboss.security.exception”);
您可以在托管bean函數中使用此代碼來獲取ex錯誤消息。
public String getLoginFailureMsg(){
Exception e = (Exception) SecurityContextAssociation.
getContextInfo("org.jboss.security.exception");
if(e != null){
if(e.getMessage().contains("PB00019"))
return "invalid username";
else
return "invalid password";
}
return null;
}
使用Jboss 7設置JAAS看到這個打擊:
http://amatya.net/blog/implementing-security-with-jaas-in-jboss-as-7/
我有同樣的問題...,但我不喜歡寫代碼綁在容器上的原因顯而易見。
所以我所做的就是自己在會話中添加例外。
首先,構建一個ThreadLocal異常持有者,以在LoginContext和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();
}
}
將LoginException添加到SecurityThreadLocal:
catch (Exception e) { // or just catch LoginException
log.log(Level.SEVERE, e.getMessage(), e);
SecurityThreadLocal.setException(e);
}
使用過濾器向HttpSession添加異常:
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);
}
但你應該知道,因為我知道這是一個不好的做法和安全漏洞。
嗯......,就我而言,客戶贏了......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.