Package org.uberfire.ext.security.server
Class LoginRedirectServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.uberfire.ext.security.server.LoginRedirectServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class LoginRedirectServlet extends javax.servlet.http.HttpServletA workaround for the servlet form authentication process (j_security_check), which, at least on WildFly 8.1, uses the HTTP POST method when forwarding the request after successful login. This blows up after login, giving anHTTP 405 Method Not Allowedresponse when the desired resource is a static one, such as a GWT host page.This servlet works around the issue by sending an HTTP redirect only if the request comes from an authenticated user to a URL of your choice. The end result is that your user will see the real resource's URL in their browser's location bar after login. In addition, this servlet copies all request parameters that were submitted along with the login form (except j_username and j_password) to the redirect URL.
To set this servlet up, configure your web application as follows:
- Declare this servlet in web.xml with init-param
display-after-loginset to the context-relative URI of the page you want the user to land on after a successful login. (for example,/host_page.html) - Map this servlet to a url-pattern that makes sense for a sign-in page, such as
/login. - Mark this servlet's url-pattern with a security-constraint that only allows logged-in users to see it. (I know, this part is confusing! The login URL has to be a protected resource!)
- Configure web.xml for auth-method
FORM - Configure the form-login-page and form-error-page to any resource you like. It can even be JSP's under /WEB-INF,
since the login and error pages will never display under their "own" URLs. They always display in place of the "real"
resource that was being requested by an unauthorized user. In our case, that resource should always be whatever this
servlet is mapped to (eg.
/login). - (Optional) set welcome-page-uri to this servlet's uri-pattern, as an easy way to direct new visitors into this tangled web of deceit.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringDISPLAY_AFTER_LOGIN_INIT_PARAMstatic StringDISPLAY_WHEN_NOT_AUTH_INIT_PARAM
-
Constructor Summary
Constructors Constructor Description LoginRedirectServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)protected voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)voidinit(javax.servlet.ServletConfig config)-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
DISPLAY_AFTER_LOGIN_INIT_PARAM
public static final String DISPLAY_AFTER_LOGIN_INIT_PARAM
- See Also:
- Constant Field Values
-
DISPLAY_WHEN_NOT_AUTH_INIT_PARAM
public static final String DISPLAY_WHEN_NOT_AUTH_INIT_PARAM
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException- Overrides:
doPostin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
-