Source Code Cross Referenced for ServerInterceptor.java in  » Net » Coadunation_1.0.1 » com » rift » coad » lib » interceptor » 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 » Net » Coadunation_1.0.1 » com.rift.coad.lib.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CoadunationLib: The coaduntion implementation library.
003:         * Copyright (C) 2006  Rift IT Contracting
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * ServerInterceptor.java
020:         *
021:         * This object is responsible for authenticating the incoming thread using the
022:         * credential information supplied.
023:         */
024:
025:        // package path
026:        package com.rift.coad.lib.interceptor;
027:
028:        // java imports
029:        import java.lang.reflect.Constructor;
030:        import java.util.concurrent.ConcurrentHashMap;
031:        import java.util.concurrent.ConcurrentMap;
032:
033:        // logging import
034:        import org.apache.log4j.Logger;
035:
036:        // coadunation imports
037:        import com.rift.coad.lib.configuration.Configuration;
038:        import com.rift.coad.lib.configuration.ConfigurationFactory;
039:        import com.rift.coad.lib.interceptor.credentials.Credential;
040:        import com.rift.coad.lib.interceptor.credentials.Login;
041:        import com.rift.coad.lib.interceptor.credentials.Session;
042:        import com.rift.coad.lib.interceptor.authenticator.SessionAuthenticator;
043:        import com.rift.coad.lib.security.AuthorizationException;
044:        import com.rift.coad.lib.security.ThreadPermissionSession;
045:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
046:        import com.rift.coad.lib.security.UserSession;
047:        import com.rift.coad.lib.security.user.UserSessionManager;
048:        import com.rift.coad.lib.security.user.UserStoreManager;
049:
050:        /**
051:         * This object is responsible for authenticating the incoming thread using the
052:         * credential information supplied.
053:         *
054:         * @author Brett Chaldecott
055:         */
056:        public class ServerInterceptor {
057:
058:            // class constants
059:            public static String CREDENTIAL_AUTHENTICATOR = "credential_authenticator";
060:
061:            // the class log variable
062:            protected Logger log = Logger.getLogger(ServerInterceptor.class
063:                    .getName());
064:
065:            // the class private member variables
066:            private ConcurrentMap authenticators = new ConcurrentHashMap();
067:            private ThreadsPermissionContainer permissionContainer = null;
068:            private InterceptorPermissionStack permissionStack = null;
069:            private UserSessionManager userSessionManager = null;
070:            private UserStoreManager userStoreManger = null;
071:
072:            /**
073:             * Creates a new instance of ServerInterceptor
074:             *
075:             * @param threadPermissionContainer The container responsible for 
076:             *          controlling the threading permissions.
077:             */
078:            protected ServerInterceptor(
079:                    ThreadsPermissionContainer threadPermissionContainer,
080:                    UserSessionManager userSessionManager,
081:                    UserStoreManager userStoreManger) {
082:                permissionStack = new InterceptorPermissionStack(
083:                        threadPermissionContainer);
084:                this .permissionContainer = threadPermissionContainer;
085:                this .userSessionManager = userSessionManager;
086:                this .userStoreManger = userStoreManger;
087:            }
088:
089:            /**
090:             * This method overwrites the session attached to this thread.
091:             *
092:             * @return The user session of the authenticated user.
093:             * @param credential The credentials to create a new session for.
094:             * @exception AuthorizationException
095:             * @exception InterceptorException
096:             */
097:            public UserSession setSession(Credential credential)
098:                    throws AuthorizationException, InterceptorException {
099:                UserSession userSession = authenticate(credential);
100:                permissionContainer.putSession(Thread.currentThread().getId(),
101:                        new ThreadPermissionSession(new Long(Thread
102:                                .currentThread().getId()), userSession));
103:                return userSession;
104:            }
105:
106:            /**
107:             * This method creates a new session using the credentials passed in.
108:             *
109:             * @return The user session of the authenticated user.
110:             * @param credential The credentials to create a new session for.
111:             * @exception AuthorizationException
112:             * @exception InterceptorException
113:             */
114:            public UserSession createSession(Credential credential)
115:                    throws AuthorizationException, InterceptorException {
116:                UserSession userSession = authenticate(credential);
117:                permissionStack.push(userSession);
118:                return userSession;
119:            }
120:
121:            /**
122:             * This method releases this thread, removing all user information from it.
123:             *
124:             * @exception InterceptorException
125:             */
126:            public void release() throws InterceptorException {
127:                permissionStack.pop();
128:            }
129:
130:            /**
131:             * This method authenticates a thread using the credential object passed in.
132:             *
133:             * @return The reference to the user session object.
134:             * @param credentials The credential to authenticate this call.
135:             * @exception AuthorizationException
136:             * @exception InterceptorException
137:             */
138:            private UserSession authenticate(Credential credential)
139:                    throws AuthorizationException, InterceptorException {
140:                try {
141:                    InterceptorAuthenticator authenticator = null;
142:                    if (!authenticators.containsKey(credential.getClass())) {
143:                        Configuration config = ConfigurationFactory
144:                                .getInstance().getConfig(credential.getClass());
145:                        String className = config.getString(
146:                                CREDENTIAL_AUTHENTICATOR,
147:                                SessionAuthenticator.class.getName());
148:                        if (className.equals(SessionAuthenticator.class
149:                                .getName())) {
150:                            authenticator = new SessionAuthenticator(
151:                                    userSessionManager, userStoreManger);
152:                        } else {
153:                            authenticator = (InterceptorAuthenticator) Class
154:                                    .forName(className).newInstance();
155:                        }
156:                        authenticators
157:                                .put(credential.getClass(), authenticator);
158:                    } else {
159:                        authenticator = (InterceptorAuthenticator) authenticators
160:                                .get(credential.getClass());
161:                    }
162:
163:                    return authenticator.authenticate(credential);
164:                } catch (AuthorizationException ex) {
165:                    throw ex;
166:                } catch (InterceptorException ex) {
167:                    throw ex;
168:                } catch (Exception ex) {
169:                    log.error("Failed to authenticate :" + ex.getMessage(), ex);
170:                    throw new InterceptorException("Failed to authenticate : "
171:                            + ex.getMessage(), ex);
172:                }
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.