Hello everyone,
I am trying to implement spring security check for authentication in login page.
public String doLogin() throws IOException, ServletException {
if(username == null ||username.equals("") ||
password==null || password.equals("") ){
CommonUtils.showMessage(FacesMessage.SEVERITY_INFO, "Required :", "Both fields are required");
}else{
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
}
return null;
}
Page is not getting redirected to index.jsf.It is showing error page.No active contexts....
public void init() {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse) context.getResponse();
HttpSession session = (HttpSession) context.getSession(false);
HttpServletRequest request = (HttpServletRequest) context.getRequest();
try {
if (session.getAttribute(HTTPSessionVariables.USERNAME) != null) {
response.sendRedirect(request.getContextPath() + "/pages/index.jsf");
}
} catch (Exception e) {
log.error("Error in LogoutBean " + e);
}
}