annotate gwt-client/src/main/java/org/dive4elements/river/client/server/LoginServlet.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents 5e38e2924c07
children d6d5ca6d4af0 0a5239a1e46e
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
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18 import org.apache.log4j.Logger;
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
20 import org.dive4elements.river.client.server.auth.Authentication;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
21 import org.dive4elements.river.client.server.auth.AuthenticationException;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
22 import org.dive4elements.river.client.server.auth.AuthenticationFactory;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
23 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
24
5953
24dc13ac8e6c Add AuthenticationServlet, a common base class for the login servlets
Bernhard Herzog <bh@intevation.de>
parents: 5933
diff changeset
25 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
26
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
27 private static Logger log = Logger.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
28
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
29 @Override
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 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
31 throws ServletException, IOException
3696
a050cb5f303f Cosmetics
Christian Lins <christian.lins@intevation.de>
parents: 3503
diff changeset
32 {
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 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
34 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
35 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
36
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
37 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
38
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39 if (username == null || password == null) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
40 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
41 this.redirectFailure(resp, req.getContextPath());
3696
a050cb5f303f Cosmetics
Christian Lins <christian.lins@intevation.de>
parents: 3503
diff changeset
42 return;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
43 }
3697
2e12518ff5b4 Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3696
diff changeset
44
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
45 try {
2956
d7f76f197d89 Refactor GGInA authentication
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2950
diff changeset
46 Authentication aresp = this.auth(username, password, encoding);
d7f76f197d89 Refactor GGInA authentication
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2950
diff changeset
47 if (aresp == null || !aresp.isSuccess()) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
48 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
49 this.redirectFailure(resp, req.getContextPath());
4489
fea3e4b6faba Return after sending a redirect
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4451
diff changeset
50 return;
2950
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
51 }
8399
c668520cc5fb Log successful/unsuccessful authentication without traceback.
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
52 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
53 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
54 }
2956
d7f76f197d89 Refactor GGInA authentication
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2950
diff changeset
55 catch(AuthenticationException e) {
8399
c668520cc5fb Log successful/unsuccessful authentication without traceback.
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
56 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
57 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
58 }
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
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
61 private Authentication auth(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
62 String username,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
63 String password,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
64 String encoding
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
65 )
3697
2e12518ff5b4 Removed trailing whitespace. Reverted functional change in parsing plain user file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3696
diff changeset
66 throws AuthenticationException, IOException
3696
a050cb5f303f Cosmetics
Christian Lins <christian.lins@intevation.de>
parents: 3503
diff changeset
67 {
3485
71ba3cf3ec5e Refactor Authentication to allow to pass the Freatures to the user class
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2984
diff changeset
68 ServletContext sc = this.getServletContext();
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
69 Features features = (Features)sc.getAttribute(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8399
diff changeset
70 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
71 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
72 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
73 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
74 }
192eddbbd4cf Implement a login page to be able to authenticate a user
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 }

http://dive4elements.wald.intevation.org