Source Code Cross Referenced for SessionLoginTest.java in  » Net » Coadunation_1.0.1 » com » rift » coad » lib » security » login » 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.security.login 
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:         * SessionLoginTest.java
020:         *
021:         * JUnit based test
022:         */
023:
024:        // package path
025:        package com.rift.coad.lib.security.login;
026:
027:        import junit.framework.*;
028:
029:        // java imports
030:        import org.apache.log4j.BasicConfigurator;
031:
032:        // coadunation imports
033:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
034:        import com.rift.coad.lib.security.ThreadsPermissionContainerAccessor;
035:        import com.rift.coad.lib.security.user.UserStoreManager;
036:        import com.rift.coad.lib.security.user.UserStoreManagerAccessor;
037:        import com.rift.coad.lib.security.user.UserSessionManager;
038:        import com.rift.coad.lib.security.user.UserSessionManagerAccessor;
039:        import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler;
040:        import com.rift.coad.lib.security.SessionManager;
041:        import com.rift.coad.lib.security.RoleManager;
042:        import com.rift.coad.lib.security.Validator;
043:        import com.rift.coad.lib.security.UserSession;
044:        import com.rift.coad.lib.thread.BasicThread;
045:        import com.rift.coad.lib.thread.CoadunationThreadGroup;
046:        import com.rift.coad.lib.security.sudo.Sudo;
047:        import com.rift.coad.lib.security.sudo.SudoCallbackHandler;
048:
049:        /**
050:         * The class that tests the session login
051:         *
052:         * @author Brett Chaldecott
053:         */
054:        public class SessionLoginTest extends TestCase implements 
055:                SudoCallbackHandler {
056:
057:            /**
058:             * This object will sudo by user
059:             */
060:            public class SudoBySessionIdTest extends BasicThread {
061:
062:                private String sessionId = null;
063:                private SudoCallbackHandler handler = null;
064:
065:                /**
066:                 * The constructor of the handler
067:                 */
068:                public SudoBySessionIdTest(String sessionId,
069:                        SudoCallbackHandler handler) throws Exception {
070:                    this .sessionId = sessionId;
071:                    this .handler = handler;
072:                }
073:
074:                /**
075:                 * This method will process the result
076:                 */
077:                public void process() {
078:                    try {
079:                        Sudo.sudoThreadBySessionId(sessionId, handler);
080:                    } catch (Exception ex) {
081:                        System.out.println("Failed to process : "
082:                                + ex.getMessage());
083:                        ex.printStackTrace(System.out);
084:                    }
085:                }
086:            }
087:
088:            // private member variables
089:            private boolean called = false;
090:
091:            public SessionLoginTest(String testName) {
092:                super (testName);
093:                BasicConfigurator.configure();
094:            }
095:
096:            protected void setUp() throws Exception {
097:            }
098:
099:            protected void tearDown() throws Exception {
100:            }
101:
102:            public static Test suite() {
103:                TestSuite suite = new TestSuite(SessionLoginTest.class);
104:
105:                return suite;
106:            }
107:
108:            /**
109:             * Test of login method, of class com.rift.coad.lib.security.login.SessionLogin.
110:             */
111:            public void testLogin() throws Exception {
112:                System.out.println("login");
113:
114:                ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
115:                ThreadsPermissionContainerAccessor.init(permissions);
116:                SessionManager.init(permissions);
117:                UserStoreManager userStoreManager = new UserStoreManager();
118:                UserStoreManagerAccessor.init(userStoreManager);
119:                UserSessionManager sessionManager = new UserSessionManager(
120:                        permissions, userStoreManager);
121:                UserSessionManagerAccessor.init(sessionManager);
122:                LoginManager.init(sessionManager, userStoreManager);
123:                // instanciate the thread manager
124:                CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
125:                        sessionManager, userStoreManager);
126:
127:                // add a user to the session for the current thread
128:                RoleManager.getInstance();
129:
130:                SessionLogin instance = new SessionLogin(
131:                        new PasswordInfoHandler("test1", "112233"));
132:
133:                instance.login();
134:
135:                // retrieve the user object
136:                UserSession user = instance.getUser();
137:                if (!user.getName().equals("test1")) {
138:                    fail("Login failed");
139:                }
140:
141:                // run as a user
142:                called = false;
143:                SudoBySessionIdTest sudoBySessionIdTest = new SudoBySessionIdTest(
144:                        user.getSessionId(), this );
145:                threadGroup.addThread(sudoBySessionIdTest, "test1");
146:                sudoBySessionIdTest.start();
147:                sudoBySessionIdTest.join();
148:                if (!called) {
149:                    fail("Failed to call");
150:                }
151:            }
152:
153:            /**
154:             * This method is called to process
155:             */
156:            public void process() {
157:                called = true;
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.