我有一个应用程序使用JBoss的custom login module。身份验证可能因多种原因而失败,我必须将这些显示给用户,而不是通常的Inavlid username/password
错误。JBoss JAAS自定义登录模块错误消息
有没有办法从登录消息中获取错误消息?我认为最好的是通过一个异常,因为authenticate返回一个布尔值,但是我不知道如何在认证后捕获它。任何指针都欢迎。
我有一个应用程序使用JBoss的custom login module。身份验证可能因多种原因而失败,我必须将这些显示给用户,而不是通常的Inavlid username/password
错误。JBoss JAAS自定义登录模块错误消息
有没有办法从登录消息中获取错误消息?我认为最好的是通过一个异常,因为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中a过滤器:
的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);
}
但是你应该知道,因为我知道这是一个不好的做法和安全漏洞。
呃..在我的情况下,客户赢了...