Hi
I've read numerous posts about this issue, and tried all possible solutions I could find, but none is working for me. I'm writing a IceFaces 1.8.2-based webapp, and added Spring Security for authentication and authorization. I want to have a custom login page (also written in JSF/icefaces). So I declared the following:
Code:
...
<security:form-login login-page="/secured/login.faces" default-target-url="/entry/entry.faces" />
<security:logout logout-success-url="/secured/logout.faces" />
...
The login page is the following
Code:
<ice:form id="loginform">
<ice:panelGrid columns="2">
<ice:outputLabel value="User Name" for="j_username" />
<ice:inputText id="j_username" value="#{loginBean.userId}" size="40"
maxlength="80" />
<ice:outputLabel value="Password" for="j_password" />
<ice:inputSecret id="j_password" value="#{loginBean.password}"
size="40" maxlength="80" />
</ice:panelGrid>
<ice:commandButton action="#{loginBean.login}" value="Login" />
<ice:messages style="color: red;" />
</ice:form>
The action in the backing bean is:
Code:
ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
context.dispatch("/j_spring_security_check");
When trying to reach a protected resource, I can indeed see the login page, then I enter my credentials, but after submitting, I always get an exception:
Code:
javax.servlet.ServletException: java.io.IOException: Cannot dispatch on XMLHTTP request.
com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:158)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
...
I also tried the following code for the action:
Code:
ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
RequestDispatcher dispatcher = ((HttpServletRequest) context
.getRequest()).getRequestDispatcher("/j_spring_security_check");
try {
dispatcher.forward((HttpServletRequest) context.getRequest(),
(HttpServletResponse) context.getResponse());
} catch (ServletException e1) {
e1.printStackTrace();
}
FacesContext.getCurrentInstance().responseComplete();
// It's OK to return null here because Faces is just going to exit.
return null;
but in that case, I get the following exception:
Code:
java.lang.UnsupportedOperationException: Use navigation rules instead
com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.getRequestDispatcher(ServletEnvironmentRequest.java:340)
be.oxys.itimesheets.beans.LoginBean.login(LoginBean.java:86)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
I've read all following sources, but none of them work.
Of course, I could use a plain jsp, without any JSF and IceFaces, but I still hope there's a way to combine IceFaces and Spring Security
I'd be very grateful if someone could help me? In the meantime, I'll revert to the standard login form
Thanks a lot for your help
Jean-Noel