annotate gwt-client/src/main/java/org/dive4elements/river/client/server/LoginServlet.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5953
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5953
diff changeset
6 * documentation coming with Dive4Elements River for details.
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 package org.dive4elements.river.client.server;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
11 import java.io.IOException;
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
12
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13 import javax.servlet.ServletException;
3485
71ba3cf3ec5e Refactor Authentication to allow to pass the Freatures to the user class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2984
diff changeset
14 import javax.servlet.ServletContext;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15 import javax.servlet.http.HttpServletRequest;
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
16 import javax.servlet.http.HttpServletResponse;
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
17
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
18 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
19 import org.apache.logging.log4j.LogManager;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
21 import org.dive4elements.river.client.server.auth.Authentication;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
22 import org.dive4elements.river.client.server.auth.AuthenticationException;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
23 import org.dive4elements.river.client.server.auth.AuthenticationFactory;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
24 import org.dive4elements.river.client.server.features.Features;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
25
5953
24dc13ac8e6c Add AuthenticationServlet, a common base class for the login servlets
Bernhard Herzog <bh@intevation.de>
parents: 5933
diff changeset
26 public class LoginServlet extends AuthenticationServlet {
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
28 private static Logger log = LogManager.getLogger(LoginServlet.class);
4451
e2d8f344491e Use static variable for login page name in LoginServlet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4450
diff changeset
29
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 @Override
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
31 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
3697
2e12518ff5b4 Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3696
diff changeset
32 throws ServletException, IOException
3696
a050cb5f303f Cosmetics
Christian Lins <christian.lins@intevation.de>
parents: 3503
diff changeset
33 {
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34 String encoding = req.getCharacterEncoding();
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 String username = req.getParameter("username");
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36 String password = req.getParameter("password");
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
38 log.debug("Processing post request");
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
40 if (username == null || password == null) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
41 log.debug("No username or password provided");
3851
a4c9296f6efa Use the Context PATH servlet variable when using URLs in the GGInAFilter
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3697
diff changeset
42 this.redirectFailure(resp, req.getContextPath());
3696
a050cb5f303f Cosmetics
Christian Lins <christian.lins@intevation.de>
parents: 3503
diff changeset
43 return;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44 }
3697
2e12518ff5b4 Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3696
diff changeset
45
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
46 try {
2956
d7f76f197d89 Refactor GGInA authentication
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2950
diff changeset
47 Authentication aresp = this.auth(username, password, encoding);
d7f76f197d89 Refactor GGInA authentication
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2950
diff changeset
48 if (aresp == null || !aresp.isSuccess()) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
49 log.debug("Authentication not successful");
3851
a4c9296f6efa Use the Context PATH servlet variable when using URLs in the GGInAFilter
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3697
diff changeset
50 this.redirectFailure(resp, req.getContextPath());
4489
fea3e4b6faba Return after sending a redirect
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4451
diff changeset
51 return;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
52 }
8399
c668520cc5fb Log successful/unsuccessful authentication without traceback.
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
53 log.info("Authentication successfull.");
5953
24dc13ac8e6c Add AuthenticationServlet, a common base class for the login servlets
Bernhard Herzog <bh@intevation.de>
parents: 5933
diff changeset
54 this.performLogin(req, resp, aresp.getUser());
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
55 }
2956
d7f76f197d89 Refactor GGInA authentication
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2950
diff changeset
56 catch(AuthenticationException e) {
8399
c668520cc5fb Log successful/unsuccessful authentication without traceback.
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
57 log.error(e.getMessage());
3851
a4c9296f6efa Use the Context PATH servlet variable when using URLs in the GGInAFilter
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3697
diff changeset
58 this.redirectFailure(resp, req.getContextPath(), e);
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
59 }
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
60 }
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
61
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
62 private Authentication auth(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
63 String username,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
64 String password,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
65 String encoding
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
66 )
3697
2e12518ff5b4 Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3696
diff changeset
67 throws AuthenticationException, IOException
3696
a050cb5f303f Cosmetics
Christian Lins <christian.lins@intevation.de>
parents: 3503
diff changeset
68 {
3485
71ba3cf3ec5e Refactor Authentication to allow to pass the Freatures to the user class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2984
diff changeset
69 ServletContext sc = this.getServletContext();
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
70 Features features = (Features)sc.getAttribute(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
71 Features.CONTEXT_ATTRIBUTE);
3485
71ba3cf3ec5e Refactor Authentication to allow to pass the Freatures to the user class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2984
diff changeset
72 String auth = sc.getInitParameter("authentication");
4451
e2d8f344491e Use static variable for login page name in LoginServlet
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4450
diff changeset
73 return AuthenticationFactory.getInstance(auth).auth(username, password,
5933
1b939742629e Pass LoginServlet's ServletContext to the Authenticators.
Bernhard Herzog <bh@intevation.de>
parents: 5861
diff changeset
74 encoding, features, sc);
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 }
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
76 }

http://dive4elements.wald.intevation.org