01: /**
02: *
03: */package clime.messadmin.providers.spi;
04:
05: import java.util.Iterator;
06:
07: import javax.servlet.http.HttpSession;
08:
09: import clime.messadmin.providers.ProviderUtils;
10:
11: /**
12: * @author Cédrik LIME
13: */
14: public interface UserNameProvider extends BaseProvider {
15: public static class Util {
16: /**
17: * Try to get user from the session, if possible.
18: * @param httpSession
19: * @return Object
20: */
21: public static Object guessUserFromSession(
22: final HttpSession httpSession, ClassLoader cl) {
23: if (null == httpSession) {
24: return null;
25: }
26: try {
27: Iterator ps = ProviderUtils.getProviders(
28: UserNameProvider.class, cl).iterator();
29: while (ps.hasNext()) {
30: UserNameProvider provider = (UserNameProvider) ps
31: .next();
32: Object user = provider
33: .guessUserFromSession(httpSession);
34: if (user != null)
35: return user;
36: }
37: return null;
38: } catch (IllegalStateException ise) {
39: //ignore: invalidated session
40: return null;
41: }
42: }
43: }
44:
45: /**
46: * @param httpSession
47: * @return user name for given HttpSession, or null if it can be determined
48: */
49: public Object guessUserFromSession(HttpSession httpSession);
50: }
|