Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java @ 4161:ff74ff82f2d4 flys-2.9.3
Add theme for gauge discharge curve artifact
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 16 Oct 2012 16:50:18 +0200 |
parents | b32e8353c30e |
children | e39ac9767a69 |
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 |
3502
3a8884e06aaa
Avoid using XPath queries for getting attributes of a node
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
1425
diff
changeset
|
3 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
|
4 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
5 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
|
6 |
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 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
|
8 |
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.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
|
10 |
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
|
11 import de.intevation.flys.client.client.services.UserService; |
3692
d18e6811e924
Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3502
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 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
|
16 |
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
|
17 /** |
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 * @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
|
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 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
|
21 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
|
22 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
|
23 { |
3860
b32e8353c30e
Donate own error message when no users were found.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3698
diff
changeset
|
24 /** 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
|
25 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
|
26 |
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
|
27 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
|
28 |
3860
b32e8353c30e
Donate own error message when no users were found.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3698
diff
changeset
|
29 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
|
30 |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
31 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
|
32 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
|
33 { |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
34 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
|
35 |
3692
d18e6811e924
Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3502
diff
changeset
|
36 UserClient client = new UserClient(url); |
d18e6811e924
Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3502
diff
changeset
|
37 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
|
38 |
3695
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3692
diff
changeset
|
39 if (loginuser == null) { |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3692
diff
changeset
|
40 logger.debug("no session user"); |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3692
diff
changeset
|
41 throw new AuthenticationException(ERROR_NO_SUCH_USER); |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3692
diff
changeset
|
42 } |
5e4d91304484
Be more defensive about fetchimg users from session.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3692
diff
changeset
|
43 |
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 try { |
3692
d18e6811e924
Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3502
diff
changeset
|
45 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
|
46 |
3692
d18e6811e924
Refactor UserServiceImpl getCurrentUser method
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
3502
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
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 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
|
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 } |
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 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
|
57 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
|
58 } |
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
|
59 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
60 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
|
61 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
|
62 } |
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
|
63 } |
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |