Source Code Cross Referenced for AcegiUserName.java in  » Profiler » MessAdmin » clime » messadmin » providers » user » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Profiler » MessAdmin » clime.messadmin.providers.user 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         */package clime.messadmin.providers.user;
003:
004:        import java.lang.reflect.Method;
005:
006:        import javax.servlet.ServletContext;
007:        import javax.servlet.http.HttpServletRequest;
008:        import javax.servlet.http.HttpServletResponse;
009:
010:        import clime.messadmin.model.ISessionInfo;
011:        import clime.messadmin.model.Server;
012:        import clime.messadmin.model.Session;
013:        import clime.messadmin.model.SessionInfo;
014:        import clime.messadmin.providers.spi.RequestLifeCycleProvider;
015:
016:        /**
017:         * Fetch the current user name from Acegi, if available.
018:         * 
019:         * Implementation note: Acegi stores its data in a ThreadLocal object, so we need to sniff it at request time.
020:         * Copy (cache) the information as RemoteUser at request time. It will be picked by the HttpRequestRemoteUser plugin.
021:         * 
022:         * @author Cédrik LIME
023:         * @since 4.1
024:         */
025:        public class AcegiUserName implements  RequestLifeCycleProvider {
026:            private Class securityContextHolderClass;
027:            private Method securityContextHolder_getContext;
028:            private Class securityContextClass;
029:            private Method securityContext_getAuthentication;
030:            private Class authenticationClass;
031:            private Method authentication_getPrincipal;
032:            private Class userDetailsClass;
033:            private Method userDetails_getUsername;
034:            private boolean acegiAvailable = false;
035:
036:            /**
037:             */
038:            public AcegiUserName() {
039:                super ();
040:                try {
041:                    securityContextHolderClass = Class
042:                            .forName("org.acegisecurity.context.SecurityContextHolder");//$NON-NLS-1$
043:                    securityContextClass = Class
044:                            .forName("org.acegisecurity.context.SecurityContext");//$NON-NLS-1$
045:                    authenticationClass = Class
046:                            .forName("org.acegisecurity.Authentication");//$NON-NLS-1$
047:                    userDetailsClass = Class
048:                            .forName("org.acegisecurity.userdetails.UserDetails");//$NON-NLS-1$
049:
050:                    securityContextHolder_getContext = securityContextHolderClass
051:                            .getMethod("getContext", null);//$NON-NLS-1$
052:                    securityContext_getAuthentication = securityContextClass
053:                            .getMethod("getAuthentication", null);//$NON-NLS-1$
054:                    authentication_getPrincipal = authenticationClass
055:                            .getMethod("getPrincipal", null);//$NON-NLS-1$
056:                    userDetails_getUsername = userDetailsClass.getMethod(
057:                            "getUsername", null);//$NON-NLS-1$
058:
059:                    acegiAvailable = securityContextHolderClass != null
060:                            && securityContextClass != null
061:                            && authenticationClass != null
062:                            && userDetailsClass != null
063:                            && securityContextHolder_getContext != null
064:                            && securityContext_getAuthentication != null
065:                            && authentication_getPrincipal != null
066:                            && userDetails_getUsername != null;
067:                } catch (Exception e) {
068:                    // do nothing, Acegi not available
069:                    acegiAvailable = false;
070:                }
071:            }
072:
073:            /**
074:             * @see clime.messadmin.providers.spi.BaseProvider#getPriority()
075:             */
076:            public int getPriority() {
077:                return 50;
078:            }
079:
080:            /**
081:             * {@inheritDoc}
082:             */
083:            public void requestInitialized(HttpServletRequest request,
084:                    HttpServletResponse response, ServletContext servletContext) {
085:                /*
086:                Object obj = org.acegisecurity.context.SecurityContextHolder.getContext().getAuthentication().getPrincipal();
087:                if (obj instanceof org.acegisecurity.userdetails.UserDetails) {
088:                	String username = ((org.acegisecurity.userdetails.UserDetails) obj).getUsername();
089:                } else {
090:                	String username = obj.toString();
091:                }
092:                 */
093:                if (acegiAvailable) {
094:                    Session session = Server.getInstance().getSession(
095:                            request.getSession(false));
096:                    if (session != null) {
097:                        ISessionInfo sessionInfo = session.getSessionInfo();
098:                        if (sessionInfo != null
099:                                && sessionInfo.getRemoteUser() == null) {
100:                            try {
101:                                String userName = null;
102:                                Object securityContext = securityContextHolder_getContext
103:                                        .invoke(null, null);
104:                                Object authentication = securityContext_getAuthentication
105:                                        .invoke(securityContext, null);
106:                                Object obj = authentication_getPrincipal
107:                                        .invoke(authentication, null);
108:                                if (userDetailsClass.isInstance(obj)) { // obj instanceof UserDetails
109:                                    userName = (String) userDetails_getUsername
110:                                            .invoke(obj, null);
111:                                } else {
112:                                    userName = (obj == null) ? null : obj
113:                                            .toString();
114:                                }
115:                                if (userName != null) {
116:                                    ((SessionInfo) sessionInfo)
117:                                            .setRemoteUser(userName);
118:                                }
119:                            } catch (Exception e) {
120:                                // shouldn't happen; nothing we can do anyway...
121:                            }
122:                        }
123:                    }
124:                }
125:            }
126:
127:            /**
128:             * {@inheritDoc}
129:             */
130:            public void requestDestroyed(HttpServletRequest request,
131:                    HttpServletResponse response, ServletContext servletContext) {
132:                // do nothing
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.