In my JSF backing bean the method login responding login process and the code is as following.
Code:
public void loginUser() throws IOException, ServletException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext context = facesContext.getExternalContext();
ServletRequest request = (ServletRequest) context.getRequest();
ServletResponse response = (ServletResponse) context.getResponse();
RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check?j_username=" + strUserName + "&j_password=" + strPassword);
dispatcher.forward(request, response);
facesContext.responseComplete();
System.out.println("User Name: [" + strUserName + "] Password: [" + strPassword + "]");
User user = controller.loginUser(strUserName.toLowerCase(), strPassword);
if (null == user) {
bSuccessLogin = false;
iUserId = -1;
strUserName = null;
strPassword = null;
strFirstName = null;
strLastName = null;
} else {
bSuccessLogin = true;
iUserId = user.getOid();
strUserName = user.getUsername();
strPassword = user.getPassword();
strFirstName = user.getFirstName();
strLastName = user.getLastName();
}
user = null;
}
I got error message is
Code:
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.aaa.bbb.sss.model.User
at $Proxy23.findUserByNamePasswd(Unknown Source)
at com.aaa.bbb.sss.controller.UserManagementService.loginUser(UserManagementService.java:33)
After I change the sequence of fetching user information and forward to request as following.
Code:
public void loginUser() throws IOException, ServletException {
System.out.println("User Name: [" + strUserName + "] Password: [" + strPassword + "]");
User user = controller.loginUser(strUserName.toLowerCase(), strPassword);
if (null == user) {
bSuccessLogin = false;
iUserId = -1;
strUserName = null;
strPassword = null;
strFirstName = null;
strLastName = null;
} else {
bSuccessLogin = true;
iUserId = user.getOid();
strUserName = user.getUsername();
strPassword = user.getPassword();
strFirstName = user.getFirstName();
strLastName = user.getLastName();
}
user = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext context = facesContext.getExternalContext();
ServletRequest request = (ServletRequest) context.getRequest();
ServletResponse response = (ServletResponse) context.getResponse();
RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check?j_username=" + strUserName + "&j_password=" + strPassword);
dispatcher.forward(request, response);
facesContext.responseComplete();
}
The error message becomes into below.
Code:
java.lang.ClassCastException: com.aaa.bbb.sss.model.User cannot be cast to java.util.List
at $Proxy23.findUserByName(Unknown Source)
at com.aaa.bbb.sss.auth.MyUserDetailsService.loadUsersByUsername(MyUserDetailsService.java:103)
It seems the firstly running method will be cached and will be re-used when the second method invoked.
Due to different return type, class cast issue occurs.
Does it mean I could NOT proxy some class in one request?
Or I should forward request in another way?