SeamLoginModule Error invoking login method
desingraj Jun 11, 2015 3:12 AMI am creating jsf 1.2 + Seam project.
I am able to get the war and show the login page.
While login, I am not able to success and get the following error. Can someone point me the mistake I did?
[SeamLoginModule] Error invoking login method
Caused by: java.lang.NullPointerException
at com.erp.jbs.authentication.UserAuthenticateActionImpl.authenticate(UserAuthenticateActionImpl.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
My classes are as follows:
@Name("authenticationAction")
@Stateless
@AutoCreate
public class UserAuthenticateActionImpl implements UserAuthenticateAction {
private static final long serialVersionUID = 1L;
@In
private StatusMessages statusMessages;
@In
private Identity identity;
@In
private Credentials credentials;
@In
private UserAuthentication userAuthentication;
@In
private LoginBean loginBean;
private Logger logger = Logger.getLogger(this.getClass());
@Override
public boolean authenticate() {
credentials.setPassword(loginBean.getPassword());
credentials.setUsername(loginBean.getUserName());
System.out.println("loginBean.getPassword()----"+loginBean.getPassword());
System.out.println("loginBean.getUserName()----"+loginBean.getUserName());
AuthenticationStatus status = userAuthentication.authenticate();
String retVal = Constants.SUCCESS_STR;
statusMessages.clear();
switch (status) {
case INVALID:
statusMessages.add(Severity.ERROR,
"#{messages['sourcevalue.invalid.credential']}");
logger.info("User #0 presented invalid credentials "
+ credentials.getUsername());
retVal = "failed";
break;
case RESET:
// TODO password needs to be reset.. take him to password reset page
statusMessages.add(Severity.ERROR,
"#{messages['sourcevalue.invalid.reset']}");
logger.info("User #0 needs to be reset in MCSource front end "
+ credentials.getUsername());
retVal = "resetPassword";
break;
case LOCKED:
statusMessages.add(Severity.ERROR,
"#{messages['sourcevalue.account.locked']}");
logger.info("User #0 is locked " + credentials.getUsername());
retVal = "failed";
break;
case SUCESS:
logger.info("User #0 presented valid credentials and was allowed logged in "
+ credentials.getUsername());
break;
default:
retVal = "failed";
}
// TODO change this to boolean and look into ways to take the user to
// change password screen if expired
return retVal.equals("success");
}
public void logout() {
// TODO Auto-generated method stub
identity.logout();
}
}
--
@Name("userAuthentication")
@Stateless
@AutoCreate
public class UserAuthenticationImpl implements UserAuthentication {
private static final long serialVersionUID = -1829464929417550824L;
@In
private UserLoginDAO userLoginDAO;
@In
private UserDAO userDAO;
@In
private LoginhistoryService LoginhistoryService;
@In
private UserLoginService userLoginService;
@In
private Credentials credentials;
@In
private Identity identity;
@Out(value = "authenticatedUser", scope = ScopeType.SESSION)
private CLRPUser authenticatedUser = null;
@Out(value = "authenticatedUserLogin", scope = ScopeType.SESSION, required = false)
private UserLogin authenticatedUserLogin = null;
@Out(value = "currentLoginhistory", scope = ScopeType.CONVERSATION)
@In(value = "currentLoginhistory", scope = ScopeType.CONVERSATION, required = false)
private Loginhistory currentLoginhistory;
public AuthenticationStatus authenticate() {
System.out.println("authenticate() method--------");
UserLoginEntity userLogin = userLoginDAO.findByUserName(credentials
.getUsername());
System.out.println("After DAO call******");
AuthenticationStatus status = AuthenticationStatus.SUCESS;
if (userLogin == null) {
status = AuthenticationStatus.INVALID;
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Invalid");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
} else if (!userLogin.isAccountNonLocked()) {
status = AuthenticationStatus.LOCKED;
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Lock");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
} else if (!userLogin.isCredentialsNonExpired()) {
status = AuthenticationStatus.RESET;
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Expired");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
} else if (!isValidCredentials(userLogin)) {
status = AuthenticationStatus.INVALID;
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Not Valid");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
} else if (userLogin.isDeleted()) {
status = AuthenticationStatus.INVALID;
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Deleted");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
}
if (status.equals(AuthenticationStatus.SUCESS)) {
Set<UserRoleEntity> userRoles = userLogin.getRoles();
for (UserRoleEntity userRoleEntity : userRoles) {
identity.addRole((RoleTypeEnum.get(userRoleEntity.getRoleId()))
.getRoleName().toLowerCase());
}
//
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
authenticatedUserLogin = UserLoginMapper.mapUserLogin(userLoginDAO
.findByUserId(userLogin.getUserID()));
System.out.print("UserLoginId"
+ authenticatedUserLogin.getUserLoginId());
System.out.print("Initial"
+ authenticatedUserLogin.isInitialLogin());
userLoginService.saveOrUpdate(authenticatedUserLogin);
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Success");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
}
return status;
}
public String sendout() {
UserLoginEntity userLogin = userLoginDAO.findByUserName(credentials
.getUsername());
authenticatedUser = UserMapper.mapUser(false,
userDAO.findById(userLogin.getUserID()), false, false);
currentLoginhistory = new Loginhistory();
currentLoginhistory.setRef(authenticatedUser.getUserId());
currentLoginhistory.setName(authenticatedUser.getProprietorName());
currentLoginhistory.setHistoryDate(new Date());
currentLoginhistory.setAction("Success");
Integer historyId = LoginhistoryService
.saveOrUpdate(this.currentLoginhistory);
identity.logout();
return "/login.xhtml";
}
// TODO do the encryption later
private boolean isValidCredentials(UserLoginEntity userLogin) {
if (userLogin.getUserName().equals(credentials.getUsername())
&& userLogin.getPassword().equals(credentials.getPassword())) {
return true;
}
return false;
}
/**
* @return the loggedInUser
*/
public CLRPUser getLoggedInUser() {
return authenticatedUser;
}
}