comparison gwt-client/src/main/java/org/dive4elements/river/client/server/LoginServlet.java @ 9497:d6d5ca6d4af0

Enabled logging of saml-group-name in log-ing logfile. Some cleanup/refaktoring.
author gernotbelger
date Thu, 27 Sep 2018 17:40:39 +0200
parents 5e38e2924c07
children ca19b7186294
comparison
equal deleted inserted replaced
9486:ce13a2f07290 9497:d6d5ca6d4af0
8 8
9 package org.dive4elements.river.client.server; 9 package org.dive4elements.river.client.server;
10 10
11 import java.io.IOException; 11 import java.io.IOException;
12 12
13 import javax.servlet.ServletContext;
13 import javax.servlet.ServletException; 14 import javax.servlet.ServletException;
14 import javax.servlet.ServletContext;
15 import javax.servlet.http.HttpServletRequest; 15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse; 16 import javax.servlet.http.HttpServletResponse;
17 17
18 import org.apache.log4j.Logger; 18 import org.apache.log4j.Logger;
19
20 import org.dive4elements.river.client.server.auth.Authentication; 19 import org.dive4elements.river.client.server.auth.Authentication;
21 import org.dive4elements.river.client.server.auth.AuthenticationException; 20 import org.dive4elements.river.client.server.auth.AuthenticationException;
22 import org.dive4elements.river.client.server.auth.AuthenticationFactory; 21 import org.dive4elements.river.client.server.auth.AuthenticationFactory;
22 import org.dive4elements.river.client.server.auth.User;
23 import org.dive4elements.river.client.server.features.Features; 23 import org.dive4elements.river.client.server.features.Features;
24 24
25 public class LoginServlet extends AuthenticationServlet { 25 public class LoginServlet extends AuthenticationServlet {
26 26
27 private static Logger log = Logger.getLogger(LoginServlet.class); 27 private static Logger log = Logger.getLogger(LoginServlet.class);
28 28
29 @Override 29 @Override
30 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 30 protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
31 throws ServletException, IOException 31 final String encoding = req.getCharacterEncoding();
32 { 32 final String username = req.getParameter("username");
33 String encoding = req.getCharacterEncoding(); 33 final String password = req.getParameter("password");
34 String username = req.getParameter("username");
35 String password = req.getParameter("password");
36 34
37 log.debug("Processing post request"); 35 log.debug("Processing post request");
38 36
39 if (username == null || password == null) { 37 if (username == null || password == null) {
40 log.debug("No username or password provided"); 38 log.debug("No username or password provided");
41 this.redirectFailure(resp, req.getContextPath()); 39 this.redirectFailure(resp, req.getContextPath());
42 return; 40 return;
43 } 41 }
44 42
45 try { 43 try {
46 Authentication aresp = this.auth(username, password, encoding); 44 final Authentication aresp = this.auth(username, password, encoding);
47 if (aresp == null || !aresp.isSuccess()) { 45 if (aresp == null || !aresp.isSuccess()) {
48 log.debug("Authentication not successful"); 46 log.debug("Authentication not successful");
49 this.redirectFailure(resp, req.getContextPath()); 47 this.redirectFailure(resp, req.getContextPath());
50 return; 48 return;
51 } 49 }
52 log.info("Authentication successfull."); 50
53 this.performLogin(req, resp, aresp.getUser()); 51 final User user = aresp.getUser();
52 final String userGroup = user.getUserGroup();
53
54 log.info(String.format("Authentication successfull: group = '%s'", userGroup));
55 this.performLogin(req, resp, user);
54 } 56 }
55 catch(AuthenticationException e) { 57 catch (final AuthenticationException e) {
56 log.error(e.getMessage()); 58 log.error(e.getMessage());
57 this.redirectFailure(resp, req.getContextPath(), e); 59 this.redirectFailure(resp, req.getContextPath(), e);
58 } 60 }
59 } 61 }
60 62
61 private Authentication auth( 63 private Authentication auth(final String username, final String password, final String encoding) throws AuthenticationException, IOException {
62 String username, 64 final ServletContext sc = this.getServletContext();
63 String password, 65 final Features features = (Features) sc.getAttribute(Features.CONTEXT_ATTRIBUTE);
64 String encoding 66 final String auth = sc.getInitParameter("authentication");
65 ) 67 return AuthenticationFactory.getInstance(auth).auth(username, password, encoding, features, sc);
66 throws AuthenticationException, IOException
67 {
68 ServletContext sc = this.getServletContext();
69 Features features = (Features)sc.getAttribute(
70 Features.CONTEXT_ATTRIBUTE);
71 String auth = sc.getInitParameter("authentication");
72 return AuthenticationFactory.getInstance(auth).auth(username, password,
73 encoding, features, sc);
74 } 68 }
75 } 69 }

http://dive4elements.wald.intevation.org