01: /**
02: *
03: */package clime.messadmin.providers.user;
04:
05: import javax.servlet.http.HttpSession;
06:
07: import clime.messadmin.providers.spi.UserNameProvider;
08:
09: /**
10: * Search "known locations" for user name
11: * @author Cédrik LIME
12: */
13: public class KnownLocations implements UserNameProvider {
14: /**
15: * The session attributes key under which the user
16: * name is stored, if any.
17: *
18: * Lower and upper-case strings will be dynamically generated. Put mid-capitalised strings here!
19: */
20: private static final String[] USER_TEST_ATTRIBUTES = new String[] {
21: "Login", "User", "userName", "UserName", "Utilisateur" };
22:
23: /**
24: *
25: */
26: public KnownLocations() {
27: super ();
28: }
29:
30: /**
31: * {@inheritDoc}
32: */
33: public int getPriority() {
34: return 10;
35: }
36:
37: /**
38: * {@inheritDoc}
39: */
40: public Object guessUserFromSession(HttpSession httpSession) {
41: Object user = null;
42:
43: for (int i = 0; i < USER_TEST_ATTRIBUTES.length; ++i) {
44: Object obj = httpSession
45: .getAttribute(USER_TEST_ATTRIBUTES[i]);
46: if (null != obj) {
47: user = obj;
48: break;
49: }
50: obj = httpSession.getAttribute(USER_TEST_ATTRIBUTES[i]
51: .toLowerCase());
52: if (null != obj) {
53: user = obj;
54: break;
55: }
56: obj = httpSession.getAttribute(USER_TEST_ATTRIBUTES[i]
57: .toUpperCase());
58: if (null != obj) {
59: user = obj;
60: break;
61: }
62: }
63:
64: return user;
65: }
66:
67: }
|