Source Code Cross Referenced for ServerInterceptorTest.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:         * ServerInterceptorTest.java
020:         *
021:         * JUnit based test
022:         */
023:
024:        package com.rift.coad.lib.interceptor;
025:
026:        import java.util.HashSet;
027:        import java.util.Iterator;
028:        import java.util.Set;
029:        import java.lang.reflect.Constructor;
030:        import java.util.concurrent.ConcurrentHashMap;
031:        import java.util.concurrent.ConcurrentMap;
032:
033:        // unit test
034:        import junit.framework.*;
035:
036:        // logging
037:        import org.apache.log4j.Logger;
038:
039:        // coadunation
040:        import com.rift.coad.lib.configuration.Configuration;
041:        import com.rift.coad.lib.configuration.ConfigurationFactory;
042:        import com.rift.coad.lib.interceptor.credentials.Credential;
043:        import com.rift.coad.lib.interceptor.credentials.Login;
044:        import com.rift.coad.lib.interceptor.credentials.Session;
045:        import com.rift.coad.lib.interceptor.authenticator.SessionAuthenticator;
046:        import com.rift.coad.lib.security.AuthorizationException;
047:        import com.rift.coad.lib.security.RoleManager;
048:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
049:        import com.rift.coad.lib.security.ThreadPermissionSession;
050:        import com.rift.coad.lib.security.UserSession;
051:        import com.rift.coad.lib.security.user.UserSessionManager;
052:        import com.rift.coad.lib.security.user.UserStoreManager;
053:        import com.rift.coad.lib.security.SessionManager;
054:        import com.rift.coad.lib.security.login.LoginManager;
055:        import com.rift.coad.lib.thread.CoadunationThreadGroup;
056:
057:        /**
058:         * This class test the server interceptor.
059:         *
060:         * @author Brett Chaldecott
061:         */
062:        public class ServerInterceptorTest extends TestCase {
063:
064:            /**
065:             * This class is responsible for supplying access to the Server
066:             * interceptor methods
067:             */
068:            public class TestInterceptor extends InterceptorWrapper {
069:
070:                // private member variables
071:                private ServerInterceptor interceptor = null;
072:
073:                /**
074:                 * The constructor of the test interceptor.
075:                 */
076:                public TestInterceptor() throws Exception {
077:                    interceptor = this .getServerInterceptor();
078:                }
079:
080:                /**
081:                 * This method overwrites the existing session using the credentials 
082:                 * passed in.
083:                 *
084:                 * @param credential The credentials overwrite the old session with.
085:                 * @exception Exception
086:                 */
087:                public void setSession(Credential credential) throws Exception {
088:                    interceptor.setSession(credential);
089:                }
090:
091:                /**
092:                 * This method creates a new session using the credentials passed in.
093:                 *
094:                 * @param credential The credentials to create a new session for.
095:                 * @exception Exception
096:                 */
097:                public void createSession(Credential credential)
098:                        throws Exception {
099:                    interceptor.createSession(credential);
100:                }
101:
102:                /**
103:                 * This method releases this thread, removing all user information from it.
104:                 *
105:                 * @exception InterceptorException
106:                 */
107:                public void release() throws InterceptorException {
108:                    interceptor.release();
109:                }
110:
111:            }
112:
113:            public ServerInterceptorTest(String testName) {
114:                super (testName);
115:            }
116:
117:            protected void setUp() throws Exception {
118:            }
119:
120:            protected void tearDown() throws Exception {
121:            }
122:
123:            public static Test suite() {
124:                TestSuite suite = new TestSuite(ServerInterceptorTest.class);
125:
126:                return suite;
127:            }
128:
129:            /**
130:             * Test of createSession method, of class com.rift.coad.lib.interceptor.ServerInterceptor.
131:             */
132:            public void testServerInterceptor() throws Exception {
133:                System.out.println("testServerInterceptor");
134:
135:                // init the session information
136:                ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
137:                SessionManager.init(permissions);
138:                UserStoreManager userStoreManager = new UserStoreManager();
139:                UserSessionManager sessionManager = new UserSessionManager(
140:                        permissions, userStoreManager);
141:                LoginManager.init(sessionManager, userStoreManager);
142:                // instanciate the thread manager
143:                CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
144:                        sessionManager, userStoreManager);
145:
146:                // add a user to the session for the current thread
147:                RoleManager.getInstance();
148:
149:                InterceptorFactory.init(permissions, sessionManager,
150:                        userStoreManager);
151:
152:                TestInterceptor testInterceptor = new TestInterceptor();
153:
154:                Set principals = new HashSet();
155:                principals.add("test");
156:                Session session = new Session("test", "xxxxxxxxxxxx",
157:                        principals);
158:
159:                if (null != permissions.getSession(Thread.currentThread()
160:                        .getId())) {
161:                    fail("There is an existing session for this user");
162:                }
163:
164:                testInterceptor.createSession(session);
165:
166:                ThreadPermissionSession threadSession = permissions
167:                        .getSession();
168:
169:                if (!threadSession.getUser().getName().equals("test")) {
170:                    fail("The user name is not test");
171:                }
172:                if (!threadSession.getUser().getSessionId().equals(
173:                        "xxxxxxxxxxxx")) {
174:                    fail("The session id [xxxxxxxxxxxx] was not found ["
175:                            + threadSession.getUser().getSessionId() + "]");
176:                }
177:                if (!threadSession.getPrincipals().contains("test")) {
178:                    fail("The principals are not setup correctly.");
179:                }
180:
181:                principals = new HashSet();
182:                principals.add("test");
183:                principals.add("test1");
184:                principals.add("test2");
185:                session = new Session("test1", "yyyyyyyyyyyyy", principals);
186:
187:                testInterceptor.createSession(session);
188:
189:                threadSession = permissions.getSession();
190:
191:                if (!threadSession.getUser().getName().equals("test1")) {
192:                    fail("The user name is test");
193:                }
194:                if (!threadSession.getUser().getSessionId().contains(
195:                        "yyyyyyyyyyyyy")) {
196:                    fail("The session id [yyyyyyyyyyyyy] was not found.");
197:                }
198:                if (!threadSession.getPrincipals().contains("test")
199:                        || !threadSession.getPrincipals().contains("test1")
200:                        || !threadSession.getPrincipals().contains("test2")) {
201:                    fail("The principals are not setup correctly.");
202:                }
203:
204:                testInterceptor.release();
205:
206:                threadSession = permissions.getSession();
207:
208:                if (!threadSession.getUser().getName().equals("test")) {
209:                    fail("The user name is test");
210:                }
211:                if (!threadSession.getUser().getSessionId().equals(
212:                        "xxxxxxxxxxxx")) {
213:                    fail("The session id [xxxxxxxxxxxx] was not found");
214:                }
215:                if (!threadSession.getPrincipals().contains("test")
216:                        || threadSession.getPrincipals().contains("test1")
217:                        || threadSession.getPrincipals().contains("test2")) {
218:                    String principalString = "";
219:                    for (Iterator iter = threadSession.getPrincipals()
220:                            .iterator(); iter.hasNext();) {
221:                        principalString += "," + (String) iter.next();
222:                    }
223:                    fail("The principals are not setup correctly ["
224:                            + principalString + "]");
225:                }
226:
227:                testInterceptor.release();
228:
229:                if (null != permissions.getSession(Thread.currentThread()
230:                        .getId())) {
231:                    fail("There is an existing session for this user");
232:                }
233:
234:                // test set session
235:                principals = new HashSet();
236:                principals.add("test");
237:                principals.add("test1");
238:                principals.add("test2");
239:                session = new Session("test1", "yyyyyyyyyyyyy", principals);
240:
241:                testInterceptor.setSession(session);
242:
243:                threadSession = permissions.getSession();
244:
245:                if (!threadSession.getUser().getName().equals("test1")) {
246:                    fail("The user name is test");
247:                }
248:                if (!threadSession.getUser().getSessionId().contains(
249:                        "yyyyyyyyyyyyy")) {
250:                    fail("The session id [yyyyyyyyyyyyy] was not found.");
251:                }
252:                if (!threadSession.getPrincipals().contains("test")
253:                        || !threadSession.getPrincipals().contains("test1")
254:                        || !threadSession.getPrincipals().contains("test2")) {
255:                    fail("The principals are not setup correctly.");
256:                }
257:
258:            }
259:
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.