01: package clime.messadmin.providers.user;
02:
03: import java.lang.reflect.Method;
04:
05: import javax.servlet.http.HttpSession;
06:
07: import clime.messadmin.providers.spi.UserNameProvider;
08:
09: /**
10: * Note: this provider implementation uses reflexion, to avoid linking against Seam libs.
11: *
12: * @author @author Cédrik LIME
13: * @since 4.1
14: */
15: public class ReflectionJBossSeamProvider implements UserNameProvider {
16: protected static final String SEAM_IDENTITY_KEY = "org.jboss.seam.security.identity";//$NON-NLS-1$
17:
18: public ReflectionJBossSeamProvider() {
19: super ();
20: }
21:
22: /**
23: * @see clime.messadmin.providers.spi.BaseProvider#getPriority()
24: */
25: public int getPriority() {
26: return 60;
27: }
28:
29: /**
30: * @see clime.messadmin.providers.spi.UserNameProvider#guessUserFromSession(javax.servlet.http.HttpSession)
31: */
32: public Object guessUserFromSession(HttpSession httpSession) {
33: Object identity = httpSession.getAttribute(SEAM_IDENTITY_KEY);
34: if (identity != null) {
35: try {
36: Method getUserNameMethod = identity.getClass()
37: .getMethod("getUsername", null);//$NON-NLS-1$
38: return getUserNameMethod.invoke(identity, null);
39: } catch (Exception e) {
40: // not a chance...
41: }
42: }
43: return null;
44: }
45:
46: }
|