annotate flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java @ 4526:1f38fa929986

Cosmetics.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 15 Nov 2012 07:38:43 +0100
parents e39ac9767a69
children
rev   line source
2
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
4214
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
3 import javax.servlet.http.HttpSession;
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
4
3502
3a8884e06aaa Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 1425
diff changeset
5 import org.w3c.dom.Element;
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
6
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
7 import org.apache.log4j.Logger;
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
8
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
9 import de.intevation.artifacts.common.ArtifactNamespaceContext;
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
10
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
11 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
2
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.flys.client.client.services.UserService;
3548
fed914a42a10 Merged revisions 5373,5377-5378 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3502
diff changeset
14 import de.intevation.flys.client.server.auth.UserClient;
217
907b61e4d702 Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 49
diff changeset
15 import de.intevation.flys.client.shared.exceptions.AuthenticationException;
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
16 import de.intevation.flys.client.shared.model.DefaultUser;
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
17 import de.intevation.flys.client.shared.model.User;
2
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 /**
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 */
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 public class UserServiceImpl
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 extends RemoteServiceServlet
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 implements UserService
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 {
3860
b32e8353c30e Donate own error message when no users were found.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3698
diff changeset
26 /** Private logger. */
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
27 private static final Logger logger = Logger.getLogger(UserServiceImpl.class);
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
28
217
907b61e4d702 Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 49
diff changeset
29 public static final String ERROR_NO_SUCH_USER = "error_no_such_user";
907b61e4d702 Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 49
diff changeset
30
3860
b32e8353c30e Donate own error message when no users were found.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3698
diff changeset
31 public static final String ERROR_NO_USERS = "error_no_users";
b32e8353c30e Donate own error message when no users were found.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3698
diff changeset
32
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
33 public User getCurrentUser(String locale)
217
907b61e4d702 Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 49
diff changeset
34 throws AuthenticationException
907b61e4d702 Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 49
diff changeset
35 {
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
36 String url = getServletContext().getInitParameter("server-url");
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
37
3548
fed914a42a10 Merged revisions 5373,5377-5378 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3502
diff changeset
38 UserClient client = new UserClient(url);
fed914a42a10 Merged revisions 5373,5377-5378 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3502
diff changeset
39 de.intevation.flys.client.server.auth.User loginuser = getUser();
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
40
3695
5e4d91304484 Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3548
diff changeset
41 if (loginuser == null) {
5e4d91304484 Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3548
diff changeset
42 logger.debug("no session user");
5e4d91304484 Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3548
diff changeset
43 throw new AuthenticationException(ERROR_NO_SUCH_USER);
5e4d91304484 Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3548
diff changeset
44 }
5e4d91304484 Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3548
diff changeset
45
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
46 try {
3548
fed914a42a10 Merged revisions 5373,5377-5378 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3502
diff changeset
47 Element user = client.findUser(loginuser);
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
48
3548
fed914a42a10 Merged revisions 5373,5377-5378 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3502
diff changeset
49 if (user != null) {
3502
3a8884e06aaa Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 1425
diff changeset
50 String uuid = user.getAttributeNS(
3a8884e06aaa Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 1425
diff changeset
51 ArtifactNamespaceContext.NAMESPACE_URI, "uuid");
3a8884e06aaa Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 1425
diff changeset
52 String name = user.getAttributeNS(
3a8884e06aaa Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 1425
diff changeset
53 ArtifactNamespaceContext.NAMESPACE_URI, "name");
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
54
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
55 return new DefaultUser(uuid, name);
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
56 }
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
57 }
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
58 catch (ConnectionException ce) {
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
59 logger.error(ce, ce);
25
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
60 }
2da6be38d8b6 Added a User interface and a default implementation to handle users in this client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2
diff changeset
61
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
62 logger.error("No users existing in the server.");
3860
b32e8353c30e Donate own error message when no users were found.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3698
diff changeset
63 throw new AuthenticationException(ERROR_NO_USERS);
2
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 }
4214
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
65
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
66 public void logoutCurrentUser() {
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
67 HttpSession session = this.getThreadLocalRequest().getSession();
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
68 session.setAttribute("user", null);
e39ac9767a69 Implement UserService method to remove current user from session
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3860
diff changeset
69 }
2
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 }
bc5d4d2297b9 Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org