Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/server/SamlServlet.java @ 5953:24dc13ac8e6c
Add AuthenticationServlet, a common base class for the login servlets
LoginServlet and SamlServlet to reduce code duplication.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 08 May 2013 17:57:51 +0200 |
parents | 38d161edba77 |
children | ea9eef426962 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/SamlServlet.java Wed May 08 17:56:14 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/SamlServlet.java Wed May 08 17:57:51 2013 +0200 @@ -14,10 +14,8 @@ import javax.servlet.ServletException; import javax.servlet.ServletContext; -import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Base64InputStream; @@ -25,53 +23,15 @@ import org.dive4elements.river.client.server.auth.AuthenticationException; import org.dive4elements.river.client.server.auth.User; -import org.dive4elements.river.client.server.auth.UserClient; import org.dive4elements.river.client.server.auth.saml.TicketValidator; import org.dive4elements.river.client.server.auth.saml.Assertion; import org.dive4elements.river.client.server.features.Features; -public class SamlServlet extends HttpServlet { +public class SamlServlet extends AuthenticationServlet { private static Logger logger = Logger.getLogger(SamlServlet.class); - private static final String FLYS_PAGE = "FLYS.html"; - private static final String LOGIN_PAGE = "login.jsp"; - - private void redirectFailure(HttpServletResponse resp, String path) - throws IOException { - resp.sendRedirect(path + "/" + LOGIN_PAGE); - } - - private void redirectFailure(HttpServletResponse resp, String path, - Exception e) throws IOException { - this.redirectFailure(resp, path, e.getMessage()); - } - - private void redirectFailure(HttpServletResponse resp, String path, - String message) throws IOException { - resp.sendRedirect(path + "/" + LOGIN_PAGE + "?error=" + message); - } - - private void redirectSuccess(HttpServletResponse resp, String path, - String uri) throws IOException { - if (uri == null) { - String redirecturl = getServletContext().getInitParameter("redirect-url"); - if (redirecturl == null) { - redirecturl = FLYS_PAGE; - } - uri = "/" + redirecturl; - } - resp.sendRedirect(uri); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - logger.debug("Processing get request"); - this.redirectFailure(resp, req.getContextPath()); - } - @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException @@ -94,24 +54,7 @@ this.redirectFailure(resp, req.getContextPath()); return; } - - String url = getServletContext().getInitParameter("server-url"); - UserClient client = new UserClient(url); - if (!client.userExists(user)) { - logger.debug("Creating db user"); - if (!client.createUser(user)) { - this.redirectFailure(resp, req.getContextPath(), - "Could not create new user"); - return; - } - } - - HttpSession session = req.getSession(); - session.setAttribute("user", user); - - String uri = (String)session.getAttribute("requesturi"); - - this.redirectSuccess(resp, req.getContextPath(), uri); + this.performLogin(req, resp, user); } catch(AuthenticationException e) { logger.error(e, e);