annotate flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java @ 3692:d18e6811e924

Refactor UserServiceImpl getCurrentUser method Return the logged in user in getCurrentUser method. flys-client/trunk@5378 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 07 Sep 2012 11:58:11 +0000
parents 3a8884e06aaa
children 5e4d91304484
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
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
3 import javax.xml.xpath.XPathConstants;
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
4
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
5 import org.w3c.dom.Document;
3502
3a8884e06aaa Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 1425
diff changeset
6 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
7 import org.w3c.dom.NodeList;
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
8
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
9 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
10
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
11 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
12 import de.intevation.artifacts.common.utils.XMLUtils;
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
13
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
14 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
15
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
16 import de.intevation.flys.client.client.services.UserService;
3692
d18e6811e924 Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3502
diff changeset
17 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
18 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
19 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
20 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
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 /**
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 * @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
24 */
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 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
26 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
27 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
28 {
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
29 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
30
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
31
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
32 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
33
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
34 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
35 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
36 {
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
37 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
38
3692
d18e6811e924 Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3502
diff changeset
39 UserClient client = new UserClient(url);
d18e6811e924 Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3502
diff changeset
40 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
41
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
42 try {
3692
d18e6811e924 Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3502
diff changeset
43 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
44
3692
d18e6811e924 Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3502
diff changeset
45 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
46 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
47 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
48 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
49 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
50
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
51 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
52 }
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
53 }
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 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
55 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
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
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 229
diff changeset
58 logger.error("No users existing in the server.");
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
59 throw new AuthenticationException(ERROR_NO_SUCH_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
60 }
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
61 }
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
62 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org