As expected, the login page loads when a protected/secure resource is requested:
<login-config>
<auth-method>FORM</auth-method>
<realm-name>jdbc</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login.xhtml</form-error-page>
</form-login-config>
</login-config>
I understand j_security_check
will automatically forward to the protected/secure resource if authentication is successful:
<form method="post" action="j_security_check">
<input type="text" name="j_username">
<input type="password" name= "j_password">
</form>
However, I would like to allow users to register (or login) to continue so I've used JSF 2.0: <h:form...
, EL: #{loginBean.register()}...
, etc... and I'm authenticating programmatically with Servlet 3.0:
public void register() {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
try {
// Register...
request.login(this.username, this.password);
// Redirect to the protected/secure resource...
} catch (ServletException e) {
...
}
}
How do I find out what that originally requested resource was? Possibly:
Any advice would be very much appreciated!
The login page is under the covers opened by a forward and the original request URI is available as request attribute with the name javax.servlet.forward.request_uri
.
So:
String uri = request.getAttribute("javax.servlet.forward.request_uri");
or, more JSF-ish:
String uri = externalContext.getRequestMap().get("javax.servlet.forward.request_uri");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With