【发布时间】:2013-09-07 09:53:07
【问题描述】:
我正在开发一个使用 JBoss seam 开发的 Web 应用程序的前端。我在用户登录时遇到NullPointerException,但我不知道它是如何发生的。这是基于日志的摘要。
当用户尝试登录时,LoginBean 中的 authenticate 方法被执行
public class LoginBean{
//both from org.jboss.seam.security package
@In
private Credentials credentials
@In
private Identity identity
public boolean authenticate(){
...
//false
logger.info(identity.getCredential null? == " + identity.getCredential==null);
//this returns true
result = webAuthentication.login(credential.getUsername(), credential.getPassword());
return result;
}
}
我仍然可以在此代码中访问身份对象的凭据属性。执行身份验证后,日志显示执行了另一个类的方法。
public class LoginControllerBean{
@In
private Identity identity; //org.jboss.seam.security
@Observer("org.jboss.seam.security.loginSuccessful")
@Begin(join = true)
public void updateSessionUserStats(){
//i can still see this in the log
logger.info("Login successful. updating sessionUserInfo....");
//throws NullPointerException
logger.info("check identity.getCredential if null == " + identity.getCredential());
sessionUser = new SessionUser();
//if I remove the log above this call will throw NullPointerException
sessionUser.setUsername(identity.getCredentials().getUsername());
}
}
我认为登录是成功的,因为带有@Observer(...loginSuccessful)注解的方法是在认证后立即执行的。
第一类和第二类的标识对象都是@In annotation.注入的
为什么identity.getCredentials() throws nullPointerException 在第二个代码上,而在第一个代码上没问题? identity.getCredentials() throwing nullPointerException? 的原因可能是什么,抱歉,如果我不能提供有关问题的更多详细信息。我只能访问前端代码。谢谢。
【问题讨论】:
-
身份为空,所以你得到了 nullPointerException
标签: java authentication jboss seam code-injection